Decompose Matrix
const deltaTransformPoint = (matrix, point) => {
return {
x: point.x * matrix.a + point.y * matrix.c,
y: point.x * matrix.b + point.y * matrix.d
}
}
const decomposeMatrix = matrix => {
let px = deltaTransformPoint(matrix, { x: 0, y: 1 })
let py = deltaTransformPoint(matrix, { x: 1, y: 0 })
let skewX = FROM_RADS * Math.atan2(px.y, px.x) - 90
let skewY = FROM_RADS * Math.atan2(py.y, py.x)
return {
tx: matrix.e,
ty: matrix.f,
scaleX: Math.sqrt(matrix.a * matrix.a + matrix.b * matrix.b),
scaleY: Math.sqrt(matrix.c * matrix.c + matrix.d * matrix.d),
skewX: skewX,
skewY: skewY,
rotation: skewX
}
}
Get the scale, translation, rotationa and skew values from a matrix.
Great stackoverflow answer from user dave
Bad JavaScript Poem
with (self) with (Math){ typeof self
with (window) with (sin) if (true) self }
This could be dangerous. Bad js poetry:
With self
With Math
Type of self
With window
With sin
If true self
:/
Very Bad JavaScript Poem
if (window . i) {
if (window . you) {
if (window . we) {
with (window . blue) {
for ( window . what in window . how ) {
for ( window . how in window . who ) {
do {} while (true)
}
}
}
}
}
}
Bad js poem:
if window i
if window you
if window we
with window blue
for window what in window how
for window how in window who
do while true
Iterative Square Root
//------------------------------------------------------------------
float function_IterativeSquareRoot (float x) {
// http://en.wikipedia.org/wiki/Methods_of_computing_square_roots
// Ancient Babylonian technology
functionName = "Iterative (Heron's) Square Root";
float y = 0.5;
int n = 6;
for (int i=0; i<n; i++) {
y = (y + x/y)/2.0;
}
return y;
}
Was browsing some code by Golan Levin and stumbled on this…
There are some real gems in the repo – might port some stuff from there in the future…