transform
transform
¶
2D affine transform.
It's stored as the six significant components of a 3x3 affine matrix. The mapping works out to x' = ax + cy + e y' = bx + dy + f
nim2d bakes transforms into vertices on the CPU, since the renderer's only GPU uniform is the orthographic projection, so this is what shape and image drawing use to place geometry. The drawing transform stack (push, pop, translate, rotate, scale) builds on these same operations.
Transform
¶
type Transform = object
A 2D affine transform as the six significant components of a 3x3 matrix.
Fields
-
afloat -
bfloat -
cfloat -
dfloat -
efloat -
ffloat
identity ¶
func identity(): Transform
* ¶
func *(p, q: Transform): Transform
Compose two transforms (apply q first, then p): result = p * q.
Parameters
-
p(Transform) -
q(Transform)
Returns
Transform
translate ¶
func translate(t: Transform; tx, ty: float): Transform
The transform followed by a translation.
Parameters
-
t(Transform) -
tx(float) -
ty(float)
Returns
Transform
rotate ¶
func rotate(t: Transform; radians: float): Transform
The transform followed by a rotation.
Parameters
-
t(Transform) -
radians(float)
Returns
Transform
scale ¶
func scale(t: Transform; sx, sy: float): Transform
The transform followed by a scale.
Parameters
-
t(Transform) -
sx(float) -
sy(float)
Returns
Transform
shear ¶
func shear(t: Transform; kx, ky: float): Transform
The transform followed by a shear.
Parameters
-
t(Transform) -
kx(float) -
ky(float)
Returns
Transform
apply ¶
func apply(t: Transform; x, y: float): (float, float)
Map a local point through the transform.
Parameters
-
t(Transform) -
x(float) -
y(float)
Returns
(float, float)