Class CssRotateTransform
rotate(angle), or SVG's rotate(angle cx cy) about a center.
public sealed record CssRotateTransform : CssTransformFunction, IEquatable<CssTransformFunction>, IEquatable<CssRotateTransform>
- Inheritance
-
CssRotateTransform
- Implements
- Inherited Members
Examples
// A CSS transform list, its matrix, and the functions it holds.
bool isTransform = CssTransformList.TryParse("translate(10px, 50%) rotate(45deg) scale(2)", out CssTransformList? css);
Matrix3x2 matrix = css!.ToMatrix((length, isX) => length.Unit == CssUnit.Percent ? length.Value * (isX ? 2 : 1) : length.Value);
foreach (CssTransformFunction function in css.Functions)
{
string kind = function switch
{
CssTranslateTransform t => $"translate {t.X} {t.Y}",
CssRotateTransform r => $"rotate {r.Degrees} about ({r.CenterX}, {r.CenterY})",
CssScaleTransform s => $"scale {s.X} {s.Y}",
CssSkewTransform k => $"skew {k.XDegrees} {k.YDegrees}",
CssMatrixTransform m => $"matrix {m.A} {m.B} {m.C} {m.D} {m.E} {m.F}",
CssUnsupportedTransform u => $"{u.Name} (3D, ignored)",
_ => "",
};
}
bool isOrigin = CssTransformOrigin.TryParse("left bottom", out CssTransformOrigin origin); // (0%, 100%, 0)
Constructors
CssRotateTransform(double, double?, double?)
rotate(angle), or SVG's rotate(angle cx cy) about a center.
public CssRotateTransform(double Degrees, double? CenterX = null, double? CenterY = null)
Parameters
DegreesdoubleThe angle in degrees, clockwise in a y-down coordinate system.
CenterXdouble?The x of the center (SVG), or null for the origin.
CenterYdouble?The y of the center (SVG), or null for the origin.
Examples
// A CSS transform list, its matrix, and the functions it holds.
bool isTransform = CssTransformList.TryParse("translate(10px, 50%) rotate(45deg) scale(2)", out CssTransformList? css);
Matrix3x2 matrix = css!.ToMatrix((length, isX) => length.Unit == CssUnit.Percent ? length.Value * (isX ? 2 : 1) : length.Value);
foreach (CssTransformFunction function in css.Functions)
{
string kind = function switch
{
CssTranslateTransform t => $"translate {t.X} {t.Y}",
CssRotateTransform r => $"rotate {r.Degrees} about ({r.CenterX}, {r.CenterY})",
CssScaleTransform s => $"scale {s.X} {s.Y}",
CssSkewTransform k => $"skew {k.XDegrees} {k.YDegrees}",
CssMatrixTransform m => $"matrix {m.A} {m.B} {m.C} {m.D} {m.E} {m.F}",
CssUnsupportedTransform u => $"{u.Name} (3D, ignored)",
_ => "",
};
}
bool isOrigin = CssTransformOrigin.TryParse("left bottom", out CssTransformOrigin origin); // (0%, 100%, 0)
Properties
CenterX
The x of the center (SVG), or null for the origin.
public double? CenterX { get; init; }
Property Value
CenterY
The y of the center (SVG), or null for the origin.
public double? CenterY { get; init; }
Property Value
Degrees
The angle in degrees, clockwise in a y-down coordinate system.
public double Degrees { get; init; }
Property Value
Methods
ToMatrix(Func<CssLength, bool, double>)
Gets the function as a matrix.
public override Matrix3x2 ToMatrix(Func<CssLength, bool, double> resolve)
Parameters
resolveFunc<CssLength, bool, double>Converts a length (possibly a percentage) to pixels; the flag is true for the x axis.
Returns
- Matrix3x2
The matrix (identity for an unsupported function).