Function translate
Append a translation transform inferred from arguments to the matrix m. This is equivalent to the expression
translation(...) * mbut actually save computation by knowing where the ones and zeros are in a pure translation matrix.
M translate(M, X, Y)
(
in M m,
in X x,
in Y y
)
if (isMat!(3, 3, M) && allSatisfy!(isNumeric, X, Y));
M translate(M, X, Y)
(
in M m,
in X x,
in Y y
)
if (isMat!(2, 3, M) && allSatisfy!(isNumeric, X, Y));
M translate(M, V)
(
in M m,
in V v
)
if ((isMat!(2, 3, M) || isMat!(3, 3, M)) && isVec!(2, V));
M translate(M, X, Y, Z)
(
in M m,
in X x,
in Y y,
in Z z
)
if (isMat!(4, 4, M) && allSatisfy!(isNumeric, X, Y, Z));
M translate(M, X, Y, Z)
(
in M m,
in X x,
in Y y,
in Z z
)
if (isMat!(3, 4, M) && allSatisfy!(isNumeric, X, Y, Z));
M translate(M, V)
(
in M m,
in V v
)
if ((isMat!(3, 4, M) || isMat!(4, 4, M)) && isVec!(3, V));
Example
import gfx .math .approx : approxUlp;
immutable m = DMat3( 1, 2, 3, 4, 5, 6, 7, 8, 9 );
immutable expected = translation(7, 12) * m; // full multiplication
immutable result = translate(m, 7, 12); // simplified multiplication
assert (approxUlp(expected, result));
Example
import gfx .math .approx : approxUlp;
immutable m = DMat4( 1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16 );
immutable expected = translation(7, 12, 18) * m; // full multiplication
immutable result = translate(m, 7, 12, 18); // simplified multiplication
assert (approxUlp(expected, result));