Struct Transform2D
- Namespace
- Icy.Rendering
- Assembly
- IcyUI.dll
Represents a wrapper for the 2D transform matrix for the UI elements.
public struct Transform2D
- Inherited Members
- Extension Methods
Properties
Identity
Gets the identity transform that does nothing.
public static Transform2D Identity { get; }
Property Value
Matrix
Gets the matrix used to form this transform.
public readonly Matrix3x2 Matrix { get; }
Property Value
Origin
Gets or sets the origin of the rotation.
public Vector2 Origin { readonly get; set; }
Property Value
Position
Gets or sets the position to translate points to.
public Vector2 Position { readonly get; set; }
Property Value
Rotation
Gets or sets the rotation in radians to apply for the points.
public float Rotation { readonly get; set; }
Property Value
Scale
Gets or sets the scale factor to apply.
public Vector2 Scale { readonly get; set; }
Property Value
Methods
AddTransform(in Transform2D)
Adds another Transform2D to the current instance.
public void AddTransform(in Transform2D other)
Parameters
otherTransform2DOther transform to add.
Apply(Point)
Applies the transform to the specified Point.
public readonly Point Apply(Point source)
Parameters
sourcePointSource point to apply transform to.
Returns
- Point
New point with transformed coordinates.
Apply(Rectangle)
Applies the transform to the specified rectangle, returning the axis-aligned bounding box of its transformed area.
public readonly Rectangle Apply(Rectangle source)
Parameters
sourceRectangleSource rectangle to apply transform to.
Returns
- Rectangle
The axis-aligned bounding box containing all four of
source's corners after being transformed. For a rotation-free, uniform-position-only transform this is exactly the same rectangle, just translated; for a rotated and/or scaled transform, this is the true bounding box of the resulting (generally non-axis-aligned) shape - not that shape itself, which a Rectangle can't represent.
Remarks
This used to transform only source's top-left corner and scale the width/height by
(matrix.M11, matrix.M22) directly - correct only when the matrix has no rotation, since those
components mix rotation and scale together for any rotated matrix (e.g. M11 = scale.X * cos(θ)).
A 45° rotation multiplied both dimensions by cos(45°) ≈ 0.707 instead of computing the actual
(larger) rotated bounding box, collapsing the result down to a small sliver overlapping just the
transformed top-left corner - visible as a rotated element getting clipped down to almost nothing by
ClipToBounds scissoring, or a rotated/scaled glyph's measured bounds being
wrong.
Apply(Vector2)
Applies the transform to the specified Vector2.
public readonly Vector2 Apply(Vector2 source)
Parameters
sourceVector2Source vector to apply transform to.
Returns
- Vector2
New vector with transformed coordinates.
Create(Matrix3x2)
Creates a transform based on specified 2D transform matrix.
public static Transform2D Create(Matrix3x2 matrix)
Parameters
matrixMatrix3x2Matrix to get values from.
Returns
- Transform2D
New instance of the Transform2D struct with Matrix set to param values.
Create(Vector2, float, Vector2, Vector2)
Creates an instance of the Transform2D struct
with specified position, rotation around origin, and scale.
public static Transform2D Create(Vector2 position, float rotation, Vector2 origin, Vector2 scale)
Parameters
positionVector2Position to translate.
rotationfloatRotation in radians to apply.
originVector2Origin of the rotation.
scaleVector2Scale to apply.
Returns
- Transform2D
New instance of the Transform2D struct with specified parameters.
ToString()
Returns the fully qualified type name of this instance.
public override readonly string ToString()
Returns
- string
The fully qualified type name.