Skip to content

Commit

Permalink
refactor(matrices): update mat23to44, mat33to44
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Jul 19, 2019
1 parent db08cb8 commit 7dac1e6
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 23 deletions.
40 changes: 27 additions & 13 deletions packages/matrices/src/m23-m44.ts
Original file line number Diff line number Diff line change
@@ -1,20 +1,34 @@
import { setC } from "@thi.ng/vectors";
import { MatOpM } from "./api";

/**
* Converts M23 to M44 and writes result to `out`.
* Converts 2x3 to 4x4 matrix and writes result to `out`. Creates new
* matrix if `out` is `null`.
*
* @param out
* @param m23
*/
export const mat23to44: MatOpM = (out, m23) => (
!out && (out = []),
(out[0] = m23[0]),
(out[1] = m23[1]),
(out[4] = m23[2]),
(out[5] = m23[3]),
(out[12] = m23[4]),
(out[13] = m23[5]),
(out[10] = out[15] = 1),
(out[2] = out[3] = out[6] = out[7] = out[8] = out[9] = out[11] = out[14] = 0),
out
);
export const mat23to44: MatOpM = (out, m23) =>
setC(
out || [],
// x
m23[0],
m23[1],
0,
0,
// y
m23[2],
m23[3],
0,
0,
// z
0,
0,
1,
0,
// w
m23[4],
m23[5],
0,
1
);
37 changes: 27 additions & 10 deletions packages/matrices/src/m33-m44.ts
Original file line number Diff line number Diff line change
@@ -1,17 +1,34 @@
import { setS3, setS4, ZERO4 } from "@thi.ng/vectors";
import { setC } from "@thi.ng/vectors";
import { MatOpM } from "./api";

/**
* Converts M33 to M44 and writes result to `out`.
* Converts 3x3 to 4x4 matrix and writes result to `out`. Creates new
* matrix if `out` is `null`.
*
* @param out
* @param m33
*/
export const mat33to44: MatOpM = (out, m33) => (
!out && (out = []),
setS3(out, m33, 0, 0),
setS3(out, m33, 4, 3),
setS3(out, m33, 8, 6),
setS3(out, ZERO4, 12),
setS4(out, [0, 0, 0, 1], 3, 0, 4)
);
export const mat33to44: MatOpM = (out, m33) =>
setC(
out || [],
// x
m33[0],
m33[1],
m33[2],
0,
// y
m33[3],
m33[4],
m33[5],
0,
// z
m33[6],
m33[7],
m33[8],
0,
// w
0,
0,
0,
1
);

0 comments on commit 7dac1e6

Please sign in to comment.