// Copyright (c) Six Labors.
// Licensed under the Six Labors Split License.
using System.Numerics;
namespace SixLabors.Fonts.Rendering {
///
/// A single path command with all coordinates already transformed into final render space (y-down).
/// For arc commands, radii and flags must be pre-adjusted by the interpreter.
///
internal readonly struct PathCommand
{
///
/// Initializes a new instance of the struct.
///
/// The command verb.
/// The end point for the command.
/// The first control point, if used by the verb.
/// The second control point, if used by the verb.
/// The x-radius for .
/// The y-radius for .
/// The x-axis rotation in degrees for .
/// The large-arc flag for .
/// The sweep flag for .
public PathCommand(
PathVerb verb,
Vector2 endPoint,
Vector2 controlPoint1,
Vector2 controlPoint2,
float radiusX,
float radiusY,
float rotationDegrees,
bool largeArc,
bool sweep)
{
this.Verb = verb;
this.EndPoint = endPoint;
this.ControlPoint1 = controlPoint1;
this.ControlPoint2 = controlPoint2;
this.RadiusX = radiusX;
this.RadiusY = radiusY;
this.RotationDegrees = rotationDegrees;
this.LargeArc = largeArc;
this.Sweep = sweep;
}
///
/// Gets the command verb.
///
public PathVerb Verb { get; }
///
/// Gets the end point for the command.
/// For and this is the target point.
/// For curves and arcs it is the end point of the segment.
///
public Vector2 EndPoint { get; }
///
/// Gets the first control point (quadratic control or cubic control 1).
/// Not used for , , or .
///
public Vector2 ControlPoint1 { get; }
///
/// Gets the second control point (cubic control 2).
/// Only used for .
///
public Vector2 ControlPoint2 { get; }
///
/// Gets the x-radius for .
///
public float RadiusX { get; }
///
/// Gets the y-radius for .
///
public float RadiusY { get; }
///
/// Gets the rotation of the arc's x-axis in degrees for .
///
public float RotationDegrees { get; }
///
/// Gets a value indicating whether the large-arc flag is set for .
///
public bool LargeArc { get; }
///
/// Gets a value indicating whether the sweep flag is set for .
///
public bool Sweep { get; }
///
/// Creates a command.
///
/// The destination point.
/// The command.
public static PathCommand MoveTo(Vector2 point)
=> new(PathVerb.MoveTo, point, Vector2.Zero, Vector2.Zero, 0f, 0f, 0f, false, false);
///
/// Creates a command.
///
/// The destination point.
/// The command.
public static PathCommand LineTo(Vector2 point)
=> new(PathVerb.LineTo, point, Vector2.Zero, Vector2.Zero, 0f, 0f, 0f, false, false);
///
/// Creates a command.
///
/// The control point.
/// The end point.
/// The command.
public static PathCommand QuadraticTo(Vector2 control, Vector2 end)
=> new(PathVerb.QuadraticTo, end, control, Vector2.Zero, 0f, 0f, 0f, false, false);
///
/// Creates a command.
///
/// The first control point.
/// The second control point.
/// The end point.
/// The command.
public static PathCommand CubicTo(Vector2 control1, Vector2 control2, Vector2 end)
=> new(PathVerb.CubicTo, end, control1, control2, 0f, 0f, 0f, false, false);
///
/// Creates an command.
///
/// The x-radius of the ellipse.
/// The y-radius of the ellipse.
/// The rotation of the ellipse's x-axis in degrees.
/// The large-arc flag.
/// The sweep flag.
/// The end point.
/// The command.
public static PathCommand ArcTo(float radiusX, float radiusY, float rotationDegrees, bool largeArc, bool sweep, Vector2 end)
=> new(PathVerb.ArcTo, end, Vector2.Zero, Vector2.Zero, radiusX, radiusY, rotationDegrees, largeArc, sweep);
///
/// Creates a command.
///
/// The command.
public static PathCommand Close()
=> new(PathVerb.ClosePath, Vector2.Zero, Vector2.Zero, Vector2.Zero, 0f, 0f, 0f, false, false);
}
}