Function transform

Transform a vector by a matrix in homogenous coordinates.

auto transform(V, M) (
  in V v,
  in M m
)
if (isVec!(2, V) && isMat!(3, 3, M));

auto transform(V, M) (
  in V v,
  in M m
)
if (isVec!(2, V) && isMat!(2, 3, M));

auto transform(V, M) (
  in V v,
  in M m
)
if (isVec!(3, V) && isMat!(4, 4, M));

auto transform(V, M) (
  in V v,
  in M m
)
if (isVec!(3, V) && isMat!(3, 4, M));

auto transform(V, M) (
  in V v,
  in M m
)
if (isVec!(4, V) && isMat!(4, 4, M));

Example

import gfx.math.approx : approxUlp, approxUlpAndAbs;
import std.math : PI;

immutable v = dvec(2, 0);
auto m = DMat2x3.identity;

m = m.rotate(PI/2);
assert ( approxUlpAndAbs(transform(v, m), dvec(0, 2)) );

m = m.translate(2, 2);
assert ( approxUlp(transform(v, m), dvec(2, 4)) );

m = m.scale(2, 2);
assert ( approxUlp(transform(v, m), dvec(4, 8)) );

Example

import gfx.math.approx : approxUlp;

auto st = scale!float(2, 2).translate(3, 1);
assert( approxUlp(transform(fvec(0, 0), st), fvec(3, 1)) );
assert( approxUlp(transform(fvec(1, 1), st), fvec(5, 3)) );

auto ts = translation!float(3, 1).scale(2, 2);
assert( approxUlp(transform(fvec(0, 0), ts), fvec(6, 2)) );
assert( approxUlp(transform(fvec(1, 1), ts), fvec(8, 4)) );