AffineTransform


abstract class AffineTransform

Known direct subclasses
ImmutableAffineTransform

An affine transformation in the plane.

MutableAffineTransform

An affine transformation in the plane.


An affine transformation in the plane. The transformation can be thought of as a 3x3 matrix:

⎡m00  m10  m20⎤
⎢m01 m11 m21⎥
⎣ 0 0 1 ⎦

Applying the transformation can be thought of as a matrix multiplication, with the to-be-transformed point represented as a column vector with an extra 1:

⎡m00  m10  m20⎤   ⎡x⎤   ⎡m00*x + m10*y + m20⎤
⎢m01 m11 m21⎥ * ⎢y⎥ = ⎢m01*x + m11*y + m21⎥
⎣ 0 0 1 ⎦ ⎣1⎦ ⎣ 1 ⎦

Transformations are composed via multiplication. Multiplication is not commutative (i.e. AB != BA), and the left-hand transformation is composed "after" the right hand transformation. E.g., if you have:

val rotate = ImmutableAffineTransform.rotate(Angle.degreesToRadians(45))
val translate = ImmutableAffineTransform.translate(Vec(10, 0))

then rotate * translate first translates 10 units in the positive x-direction, then rotates 45° about the origin.

ImmutableAffineTransform and MutableAffineTransform are the two concrete implementations of this.

Summary

Public companion properties

ImmutableAffineTransform

Constant representing an identity transformation, which maps a point to itself, i.e. it leaves it unchanged.

Public functions

MutableParallelogram
applyTransform(box: Box, outParallelogram: MutableParallelogram)

Apply the AffineTransform to the Box and store the result in the MutableParallelogram.

MutableParallelogram
applyTransform(
    parallelogram: Parallelogram,
    outParallelogram: MutableParallelogram
)

Apply the AffineTransform to the Parallelogram and store the result in the MutableParallelogram.

MutableSegment
applyTransform(segment: Segment, outSegment: MutableSegment)

Apply the AffineTransform to the Segment and store the result in the MutableSegment.

MutableTriangle
applyTransform(triangle: Triangle, outTriangle: MutableTriangle)

Apply the AffineTransform to the Triangle and store the result in the MutableTriangle.

MutableVec
applyTransform(vec: Vec, outVec: MutableVec)

Apply the AffineTransform to the Vec and store the result in the MutableVec.

MutableAffineTransform

Populates outAffineTransform with the inverse of this AffineTransform.

@Size(min = 6) FloatArray
getValues(outArray: @Size(min = 6) FloatArray)

Populates the first 6 elements of outArray with the values of this transform, starting with the top left corner of the matrix and proceeding in row-major order.

Public companion properties

IDENTITY

val IDENTITYImmutableAffineTransform

Constant representing an identity transformation, which maps a point to itself, i.e. it leaves it unchanged.

Public functions

applyTransform

Added in 1.0.0-alpha01
fun applyTransform(box: Box, outParallelogram: MutableParallelogram): MutableParallelogram

Apply the AffineTransform to the Box and store the result in the MutableParallelogram. This is the only Apply function where the input cannot also be the output, as applying an Affine Transform to a Box makes a Parallelogram.

applyTransform

Added in 1.0.0-alpha01
fun applyTransform(
    parallelogram: Parallelogram,
    outParallelogram: MutableParallelogram
): MutableParallelogram

Apply the AffineTransform to the Parallelogram and store the result in the MutableParallelogram. The same MutableParallelogram can be used as both the input and output to avoid additional allocations.

applyTransform

Added in 1.0.0-alpha01
fun applyTransform(segment: Segment, outSegment: MutableSegment): MutableSegment

Apply the AffineTransform to the Segment and store the result in the MutableSegment. The same MutableSegment can be used as both the input and output to avoid additional allocations. Returns outSegment.

applyTransform

Added in 1.0.0-alpha01
fun applyTransform(triangle: Triangle, outTriangle: MutableTriangle): MutableTriangle

Apply the AffineTransform to the Triangle and store the result in the MutableTriangle. The same MutableTriangle can be used as both the input and output to avoid additional allocations. Returns outTriangle.

applyTransform

Added in 1.0.0-alpha01
fun applyTransform(vec: Vec, outVec: MutableVec): MutableVec

Apply the AffineTransform to the Vec and store the result in the MutableVec. The same MutableVec can be used as both the input and output to avoid additional allocations. Returns outVec.

computeInverse

Added in 1.0.0-alpha01
fun computeInverse(outAffineTransform: MutableAffineTransform): MutableAffineTransform

Populates outAffineTransform with the inverse of this AffineTransform. The same MutableAffineTransform instance can be used as the output to avoid additional allocations. Returns outAffineTransform.

getValues

Added in 1.0.0-alpha01
fun getValues(outArray: @Size(min = 6) FloatArray = FloatArray(6)): @Size(min = 6) FloatArray

Populates the first 6 elements of outArray with the values of this transform, starting with the top left corner of the matrix and proceeding in row-major order.

In performance-sensitive code, prefer to pass in an array that has already been allocated and is being reused, rather than relying on the default behavior of allocating a new instance for each call.

Prefer to apply this transform to an object, such as with applyTransform, rather than accessing the actual numeric values of this transform. This function is useful for when the values are needed in bulk but not to apply a transform, for example for serialization.

To set these values on a transform in the same order that they are retrieved here, use the ImmutableAffineTransform constructor or use MutableAffineTransform.setValues.