MutableAffineTransform



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 ImmutableAffineTransform for an immutable alternative to this class.

Summary

Public constructors

Constructs an identity MutableAffineTransform:

android

Public functions

open operator Boolean
equals(other: Any?)

Component-wise equality operator for MutableAffineTransform.

android
open Int
android
MutableAffineTransform

Fills this MutableAffineTransform with the same values contained in input.

android
MutableAffineTransform

Fills this MutableAffineTransform with an identity transformation, which maps a point to itself, i.e. it leaves it unchanged.

android
MutableAffineTransform

Fills this MutableAffineTransform with a transformation that rotates by the given angle, centered about the origin.

android
MutableAffineTransform
populateFromScale(scaleFactor: Float)

Fills this MutableAffineTransform with a transformation that scales in both the x and y direction by the given scaleFactor, centered about the origin.

android
MutableAffineTransform
populateFromScale(xScaleFactor: Float, yScaleFactor: Float)

Fills this MutableAffineTransform with 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.

android
MutableAffineTransform
populateFromScaleX(scaleFactor: Float)

Fills this MutableAffineTransform with a transformation that scales in the x-direction by the given factor, centered about the origin.

android
MutableAffineTransform
populateFromScaleY(scaleFactor: Float)

Fills this MutableAffineTransform with a transformation that scales in the y-direction by the given factor, centered about the origin.

android
MutableAffineTransform
populateFromShearX(shearFactor: Float)

Fills this MutableAffineTransform with a transformation that shears in the x-direction by the given factor.

android
MutableAffineTransform
populateFromShearY(shearFactor: Float)

Fills this MutableAffineTransform with a transformation that shears in the y-direction by the given factor.

android
MutableAffineTransform

Fills this MutableAffineTransform with a transformation that translates by the given offset vector.

android
Unit
setValues(values: @Size(min = 6) FloatArray)

Like setValues, but accepts a FloatArray instead of individual float values.

android
Unit
setValues(m00: Float, m10: Float, m20: Float, m01: Float, m11: Float, m21: Float)

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

android
open String
android

Extension functions

MutableAffineTransform

Fills this MutableAffineTransform with the values from matrix.

android
MutableAffineTransform

Fills this MutableAffineTransform with the values from matrix.

android

Inherited functions

From androidx.ink.geometry.AffineTransform
ImmutableParallelogram

Returns an ImmutableParallelogram containing the result of applying the AffineTransform to box.

android
ImmutableParallelogram
applyTransform(parallelogram: Parallelogram)

Returns an ImmutableParallelogram containing the result of applying the AffineTransform to parallelogram.

android
ImmutableVec

Returns an ImmutableVec containing the result of applying the AffineTransform to point.

android
ImmutableSegment

Returns an ImmutableSegment containing the result of applying the AffineTransform to segment.

android
ImmutableTriangle

Returns an ImmutableTriangle containing the result of applying the AffineTransform to triangle.

android
MutableParallelogram
applyTransform(box: Box, outParallelogram: MutableParallelogram)

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

android
MutableParallelogram
applyTransform(
    parallelogram: Parallelogram,
    outParallelogram: MutableParallelogram
)

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

android
MutableVec
applyTransform(point: Vec, outVec: MutableVec)

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

android
MutableSegment
applyTransform(segment: Segment, outSegment: MutableSegment)

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

android
MutableTriangle
applyTransform(triangle: Triangle, outTriangle: MutableTriangle)

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

android
ImmutableAffineTransform

Returns the inverse of the AffineTransform.

android
MutableAffineTransform

Populates outAffineTransform with the inverse of this AffineTransform.

android
@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.

android
Boolean
isAlmostEqual(
    other: AffineTransform,
    tolerance: @FloatRange(from = 0.0) Float
)

Compares this AffineTransform with other, and returns true if each component of the transform matrix is within tolerance of the corresponding component of other.

android

Public constructors

MutableAffineTransform

MutableAffineTransform()

Constructs an identity MutableAffineTransform:

1  0  0
0 1 0
0 0 1

This is useful when pre-allocating a scratch instance to be filled later.

Public functions

equals

open operator fun equals(other: Any?): Boolean

Component-wise equality operator for MutableAffineTransform.

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

open fun hashCode(): Int

populateFrom

fun populateFrom(input: AffineTransform): MutableAffineTransform

Fills this MutableAffineTransform with the same values contained in input.

Returns the modified instance to allow chaining calls.

Returns
MutableAffineTransform

this

populateFromIdentity

fun populateFromIdentity(): MutableAffineTransform

Fills this MutableAffineTransform with an identity transformation, which maps a point to itself, i.e. it leaves it unchanged.

Returns the modified instance to allow chaining calls.

Returns
MutableAffineTransform

this

populateFromRotation

fun populateFromRotation(angleOfRotation: @AngleRadiansFloat Float): MutableAffineTransform

Fills this MutableAffineTransform with a transformation that rotates by the given angle, centered about the origin.

Returns the modified instance to allow chaining calls.

Returns
MutableAffineTransform

this

populateFromScale

fun populateFromScale(scaleFactor: Float): MutableAffineTransform

Fills this MutableAffineTransform with a transformation that scales in both the x and y direction by the given scaleFactor, centered about the origin.

Returns the modified instance to allow chaining calls.

Returns
MutableAffineTransform

this

populateFromScale

fun populateFromScale(xScaleFactor: Float, yScaleFactor: Float): MutableAffineTransform

Fills this MutableAffineTransform with 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.

Returns the modified instance to allow chaining calls.

Returns
MutableAffineTransform

this

populateFromScaleX

fun populateFromScaleX(scaleFactor: Float): MutableAffineTransform

Fills this MutableAffineTransform with a transformation that scales in the x-direction by the given factor, centered about the origin.

Returns the modified instance to allow chaining calls.

Returns
MutableAffineTransform

this

populateFromScaleY

fun populateFromScaleY(scaleFactor: Float): MutableAffineTransform

Fills this MutableAffineTransform with a transformation that scales in the y-direction by the given factor, centered about the origin.

Returns the modified instance to allow chaining calls.

Returns
MutableAffineTransform

this

populateFromShearX

fun populateFromShearX(shearFactor: Float): MutableAffineTransform

Fills this MutableAffineTransform with a transformation that shears in the x-direction by the given factor.

Returns the modified instance to allow chaining calls.

Returns
MutableAffineTransform

this

populateFromShearY

fun populateFromShearY(shearFactor: Float): MutableAffineTransform

Fills this MutableAffineTransform with a transformation that shears in the y-direction by the given factor.

Returns the modified instance to allow chaining calls.

Returns
MutableAffineTransform

this

populateFromTranslate

fun populateFromTranslate(offset: Vec): MutableAffineTransform

Fills this MutableAffineTransform with a transformation that translates by the given offset vector.

Returns the modified instance to allow chaining calls.

Returns
MutableAffineTransform

this

setValues

fun setValues(values: @Size(min = 6) FloatArray): Unit

Like setValues, but accepts a FloatArray instead of individual float values.

setValues

fun setValues(m00: Float, m10: Float, m20: Float, m01: Float, m11: Float, m21: Float): Unit

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

Prefer to modify this object with functions that apply specific transform operations, such as populateFromScale or populateFromRotate, rather than directly setting the actual numeric values of this transform. This function is useful for when the values are needed to be provided in bulk, for example for serialization.

To access these values in the same order as they are set here, use AffineTransform.getValues.

toString

open fun toString(): String

Extension functions

populateFrom

fun MutableAffineTransform.populateFrom(matrix: Matrix): MutableAffineTransform

Fills this MutableAffineTransform with the values from matrix.

If matrix is not an affine transform, throws IllegalArgumentException instead.

Leaves matrix unchanged. Returns this modified instance to allow chaining calls.

Returns
MutableAffineTransform

this

Throws
kotlin.IllegalArgumentException

if matrix is not an affine transform.

populateFrom

fun MutableAffineTransform.populateFrom(matrix: Matrix): MutableAffineTransform

Fills this MutableAffineTransform with the values from matrix.

If matrix is not an affine transform, throws IllegalArgumentException instead.

Leaves the input matrix unchanged. Returns the modified instance to allow chaining calls.

Returns
MutableAffineTransform

this

Throws
kotlin.IllegalArgumentException

if matrix is not a 2D affine transform.