Class: Toybox.Graphics.AffineTransform

Overview

A 2D affine transformation matrix

This is a 2D transform, typically used for converting coordinates from one 2D coordinate system to another. These transformations can represent a sequence of rotations, scales, shears, and translations.

   | m00  m01  m02 |
   | m10  m11  m12 |
   |   0    0    1 |

Since:

API Level 4.2.0

Instance Method Summary collapse

Instance Method Details

concatenate(xform as Graphics.AffineTransform) as Void

Apply the given transform

Assign self to the result of the following cross product:

   | m00  m01  m02 |   | x00  x01  x02 |
   | m10  m11  m12 | x | x10  x11  x12 |
   |   0    0    1 |   |   0    0    1 |

Parameters:

Since:

API Level 4.2.0

getDeterminant() as Lang.Float

Get the transform determinant

Since:

API Level 4.2.0

getMatrix() as Lang.Array<Lang.Float>

Get the transform values

Get the underlying values of this transform as an Array

   | m00  m01  m02 |
   | m10  m11  m12 | => [ m00, m01, m02, m10, m11, m12 ]
   |   0    0    1 |

Since:

API Level 4.2.0

initialize()

initialize self to the identity transform

   |   1    0    0 |
   |   0    1    0 |
   |   0    0    1 |

Since:

API Level 4.2.0

invert() as Void

Invert self

Since:

API Level 4.2.0

Throws:

  • ValueOutOfBoundsException if self cannot be inverted.

preConcatenate(xform as Graphics.AffineTransform) as Void

Apply the given transform

Assign self to the result of the following cross product:

   | x00  x01  x02 |   | m00  m01  m02 |
   | x10  x11  x12 | x | m10  m11  m12 |
   |   0    0    1 |   |   0    0    1 |

Parameters:

Since:

API Level 4.2.0

rotate(theta as Lang.Float) as Void

Apply a rotation

Assign self to the result of the following cross product:

   | m00  m01  m02 |   | cos -sin    0 |
   | m10  m11  m12 | x | sin  cos    0 |
   |   0    0    1 |   |   0    0    1 |

Equivalent to

     var xform = new AffineTransform();
     xform.setToRotation(theta);
     self.concatenate(xform);

Parameters:

Since:

API Level 4.2.0

scale(sx as Lang.Float, sy as Lang.Float) as Void

Apply a scale

Assign self to the result of the following cross product:

   | m00  m01  m02 |   |  sx    0    0 |
   | m10  m11  m12 | x |   0   sy    0 |
   |   0    0    1 |   |   0    0    1 |

Equivalent to

     var xform = new AffineTransform();
     xform.setToScale(sx, sy);
     self.concatenate(xform);

Parameters:

Since:

API Level 4.2.0

setMatrix(m as Lang.Array<Lang.Float>) as Void

Set the transform values

                                       | m00  m01  m02 |
m00, m01, m02, m10, m11, m12
  • => | m10 m11 m12 |

                                           |   0    0    1 |
    
  • Since:

    API Level 4.2.0

    Throws:

    • UnexpectedTypeException if parameter is not an Array

    • InvalidValueException if parameter does not have exactly 6 elements

    setToRotation(theta as Lang.Float) as Void

    Set self to a rotation transform

       | cos -sin    0 |
       | sin  cos    0 |
       |   0    0    1 |
    

    Parameters:

    Since:

    API Level 4.2.0

    setToScale(sx as Lang.Float, sy as Lang.Float) as Void

    Set self to a scale transform

       |  sx    0    0 |
       |   0   sy    0 |
       |   0    0    1 |
    

    Parameters:

    Since:

    API Level 4.2.0

    setToShear(shx as Lang.Float, shy as Lang.Float) as Void

    Set self to a shear transform

       |   1  shx    0 |
       | shy    1    0 |
       |   0    0    1 |
    

    Parameters:

    Since:

    API Level 4.2.0

    setToTranslation(tx as Lang.Float, ty as Lang.Float) as Void

    Set self to a translation transform

       |   1    0   tx |
       |   0    1   ty |
       |   0    0    1 |
    

    Parameters:

    Since:

    API Level 4.2.0

    shear(shx as Lang.Float, shy as Lang.Float) as Void

    Apply a shear

    Assign self to the result of the following cross product:

       | m00  m01  m02 |   |   1  shx    0 |
       | m10  m11  m12 | x | shy    1    0 |
       |   0    0    1 |   |   0    0    1 |
    
    

    Equivalent to

         var xform = new AffineTransform();
         xform.setToShear(shx, shy);
         self.concatenate(xform);
    

    Parameters:

    Since:

    API Level 4.2.0

    transformPoint(pt as Graphics.Point2D) as Graphics.Point2D

    Apply transform to a 2D coordinate

    Transform a single point as if by generating the following cross product:

       | m00  m01  m02 |   | ptx |
       | m10  m11  m12 | x | pty |
       |   0    0    1 |   |   1 |
    

    Parameters:

    Returns:

    Since:

    API Level 4.2.0

    transformPoints(pts as Lang.Array<Graphics.Point2D>) as Lang.Array<Graphics.Point2D>

    Apply transform to an Array of 2D points

    Transform an array of points

    Parameters:

    Returns:

    Since:

    API Level 4.2.0

    translate(tx as Lang.Float, ty as Lang.Float) as Void

    Apply translation

    Assign self to the result of the following cross product:

       | m00  m01  m02 |   |   1    0   tx |
       | m10  m11  m12 | x |   0    1   ty |
       |   0    0    1 |   |   0    0    1 |
    
    

    Equivalent to

         var xform = new AffineTransform();
         xform.setToTranslation(tx, ty);
         self.concatenate(xform);
    

    Parameters:

    Since:

    API Level 4.2.0


    Generated Sep 25, 2023 12:31:45 PM