ImmutableAffineTransform


public final class ImmutableAffineTransform extends AffineTransform


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.

See MutableAffineTransform for mutable alternative to this class.

Summary

Public constructors

ImmutableAffineTransform(@Size(min = 6) @NonNull float[] values)

Like the primary constructor, but accepts a FloatArray instead of individual Float values.

ImmutableAffineTransform(
    float m00,
    float m10,
    float m20,
    float m01,
    float m11,
    float m21
)

Constructs this transform with 6 float values, starting with the top left corner of the matrix and proceeding in row-major order.

Public methods

boolean
equals(Object other)

Component-wise equality operator for ImmutableAffineTransform.

int
static final @NonNull ImmutableAffineTransform
scale(float scaleFactor)

Returns a transformation that scales in both the x- and y-direction by the given scaleFactor, centered about the origin.

static final @NonNull ImmutableAffineTransform
scale(float xScaleFactor, float yScaleFactor)

Returns a transformation that scales in both the x- and y-direction by the given pair of factors; xScaleFactor and yScaleFactor respectively, centered about the origin.

static final @NonNull ImmutableAffineTransform
scaleX(float scaleFactor)

Returns a transformation that scales in the x-direction by the given factor, centered about the origin.

static final @NonNull ImmutableAffineTransform
scaleY(float scaleFactor)

Returns a transformation that scales in the y-direction by the given factor, centered about the origin.

@NonNull String
static final @NonNull ImmutableAffineTransform

Returns a transformation that translates by the given offset vector.

Inherited methods

From androidx.ink.geometry.AffineTransform
final @NonNull MutableParallelogram
applyTransform(
    @NonNull Box box,
    @NonNull MutableParallelogram outParallelogram
)

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

final @NonNull MutableParallelogram
applyTransform(
    @NonNull Parallelogram parallelogram,
    @NonNull MutableParallelogram outParallelogram
)

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

final @NonNull MutableVec

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

final @NonNull MutableSegment
applyTransform(
    @NonNull Segment segment,
    @NonNull MutableSegment outSegment
)

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

final @NonNull MutableTriangle
applyTransform(
    @NonNull Triangle triangle,
    @NonNull MutableTriangle outTriangle
)

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

final @NonNull MutableAffineTransform

Populates outAffineTransform with the inverse of this AffineTransform.

final @Size(min = 6) @NonNull float[]
getValues(@Size(min = 6) @NonNull float[] outArray)

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 constructors

ImmutableAffineTransform

Added in 1.0.0-alpha02
public ImmutableAffineTransform(@Size(min = 6) @NonNull float[] values)

Like the primary constructor, but accepts a FloatArray instead of individual Float values.

ImmutableAffineTransform

Added in 1.0.0-alpha02
public ImmutableAffineTransform(
    float m00,
    float m10,
    float m20,
    float m01,
    float m11,
    float m21
)

Constructs this transform with 6 float values, starting with the top left corner of the matrix and proceeding in row-major order. Prefer to create this object with functions that apply specific transform operations, such as scale or translate, rather than directly passing in the actual numeric values of this transform. This constructor is useful for when the values are needed to be provided all at once, for example for serialization. To access these values in the same order as they are passed in here, use AffineTransform.getValues. To construct this object using an array as input, there is another public constructor for that.

Public methods

equals

public boolean equals(Object other)

Component-wise equality operator for ImmutableAffineTransform.

Due to the propagation floating point precision errors, operations that may be equivalent over the real numbers are not always equivalent for floats, and might return false for equals in some cases.

hashCode

public int hashCode()

scale

Added in 1.0.0-alpha02
public static final @NonNull ImmutableAffineTransform scale(float scaleFactor)

Returns a transformation that scales in both the x- and y-direction by the given scaleFactor, centered about the origin.

scale

Added in 1.0.0-alpha02
public static final @NonNull ImmutableAffineTransform scale(float xScaleFactor, float yScaleFactor)

Returns a transformation that scales in both the x- and y-direction by the given pair of factors; xScaleFactor and yScaleFactor respectively, centered about the origin.

scaleX

Added in 1.0.0-alpha02
public static final @NonNull ImmutableAffineTransform scaleX(float scaleFactor)

Returns a transformation that scales in the x-direction by the given factor, centered about the origin.

scaleY

Added in 1.0.0-alpha02
public static final @NonNull ImmutableAffineTransform scaleY(float scaleFactor)

Returns a transformation that scales in the y-direction by the given factor, centered about the origin.

toString

public @NonNull String toString()

translate

Added in 1.0.0-alpha02
public static final @NonNull ImmutableAffineTransform translate(@NonNull Vec offset)

Returns a transformation that translates by the given offset vector.