// Generated API outline. Implementation bodies omitted.
#nullable enable
using System.Collections.Generic;
using System.ComponentModel;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Net.Http;
using System.Threading.Tasks;
using System.Threading;
using System;
using nfloat = System.Runtime.InteropServices.NFloat;
using static Xui.Core.Math2D.Constants;
namespace Xui.Core.Curves2D
{
using Xui.Core.Canvas;
using Xui.Core.Math2D;
///
/// Represents a circular or elliptical arc defined by a center point, radii, rotation, and sweep angles.
///
///
/// Arcs are useful for describing elliptical curves in vector graphics, layout paths, and stroke outlines.
/// They interpolate smoothly from to , optionally applying
/// rotation and winding direction.
///
public readonly struct Arc : ICurve
{
/// The center point of the arc's ellipse.
public readonly Point Center;
/// The horizontal radius of the arc.
public readonly nfloat RadiusX;
/// The vertical radius of the arc.
public readonly nfloat RadiusY;
/// The clockwise rotation (in radians) applied to the arc relative to the X axis.
public readonly nfloat Rotation;
/// The angle (in radians) at which the arc starts, before rotation is applied.
public readonly nfloat StartAngle;
/// The angle (in radians) at which the arc ends, before rotation is applied.
public readonly nfloat EndAngle;
/// Specifies whether the arc is drawn clockwise or counter-clockwise.
public readonly Winding Winding;
///
/// Initializes a new with the given center, radii, rotation, angles, and winding direction.
///
/// The center point of the arc's ellipse.
/// The horizontal radius.
/// The vertical radius.
/// The clockwise rotation in radians applied to the ellipse.
/// The start angle of the arc in radians (before rotation).
/// The end angle of the arc in radians (before rotation).
/// Whether the arc is drawn clockwise or counter-clockwise.
public Arc(Point center, nfloat rx, nfloat ry, nfloat rotation, nfloat startAngle, nfloat endAngle, Winding winding = Winding.ClockWise);
///
/// Gets the interpolated point on the arc at the specified parameter .
///
/// A normalized value from 0 to 1 representing the progression along the arc.
public Point this[nfloat t] { get; }
///
/// Computes the interpolated point on the arc at a given parameter .
///
/// A normalized value in the range [0, 1].
public Point Lerp(nfloat t);
///
/// Evaluates the arc at a normalized parameter , returning the corresponding point.
///
/// A normalized value in the range [0, 1].
/// The corresponding point on the rotated ellipse arc.
public Point Evaluate(nfloat t);
///
/// Computes the tangent vector at parameter on the arc.
///
/// A normalized value in the range [0, 1].
/// The normalized tangent vector at the evaluated point on the arc.
public Vector Tangent(nfloat t);
///
/// Approximates the arc length using uniform sampling with 16 segments.
///
/// The approximate total arc length.
public nfloat Length();
///
/// Approximates the arc length using recursive adaptive subdivision.
///
/// The maximum allowed error per segment for arc approximation.
/// The computed arc length within the specified flatness tolerance.
public nfloat Length(nfloat flatness);
///
/// Gets the signed sweep angle of the arc, in radians.
/// Adjusts automatically for the specified .
///
public nfloat SweepAngle { get; }
///
/// Converts this arc to an endpoint-parameterized representation.
///
///
/// This method generates a single arc segment between the start and end points of the original arc,
/// preserving the sweep direction and determining whether the arc is the larger of the two possible segments.
/// If the arc forms a complete circle (i.e., the start and end points match and the sweep covers 360°),
/// the endpoint position is nudged slightly to avoid rendering ambiguities in formats that do not support full-circle arcs directly.
///
///
/// An structure that approximates this arc using endpoint-based parametrization.
///
public ArcEndpoint ToEndpointArc();
///
/// Converts this arc to one or two endpoint-parameterized arcs, depending on the arc's sweep angle.
///
///
/// If the arc forms a complete or nearly complete circle (i.e., the sweep angle approaches ±360° and the start and end points match),
/// the arc is split into two half-circle segments to avoid rendering issues in formats that do not support full-circle arcs directly.
/// Otherwise, a single is returned with appropriate flags set for direction and size.
///
///
/// A tuple of one or two instances that collectively represent the same elliptical arc:
/// - Item1 – The first arc segment (always non-null).
///
- Item2 – The second arc segment if the arc is split, or null if the arc fits in a single segment.
///
public (ArcEndpoint, ArcEndpoint? ) ToEndpointArcs();
///
/// Evaluates the position on the ellipse at a given angle (in radians),
/// relative to the unrotated ellipse center.
///
///
/// The angle in radians, measured from the X axis of the unrotated ellipse.
/// This is not a normalized parameter like t, but an absolute angle used in parametric arc equations.
///
///
/// The corresponding on the arc's ellipse at the given angle,
/// after applying the arc's rotation and translating from its center.
///
///
/// The point is computed using the parametric equation of an axis-aligned ellipse:
/// (x, y) = (rx * cos(θ), ry * sin(θ)), then rotated by and translated to .
/// This method is useful when working directly with angle-based metrics like vertical extrema (e.g., θ = π/2 or 3π/2).
///
public Point EvaluateAtAngle(nfloat θ);
///
/// Splits this arc into a series of segments,
/// each spanning ≤ 90° and aligned so that one edge is axis-aligned.
///
///
/// A span to receive the output segments. Must have space for up to 4 entries.
///
///
/// The number of segments written to .
///
///
/// This method ensures consistent arc tessellation by aligning segment edges with
/// X or Y axes and bounding each by ≤ 90°, suitable for round rects or shader-compatible curves.
///
public void ToArc3Segments(Span buffer, out int count);
}
///
/// Represents a circular arc defined by three points: start, mid (on-curve), and end.
///
///
/// The arc is guaranteed to pass through all three control points , , and .
/// The arc lies on the unique circle that intersects these points and is useful for geometric primitives,
/// shader-based SDF rendering, and polygonal arc approximation.
///
public readonly struct Arc3Point : ICurve
{
/// The starting point of the arc.
public readonly Point P0;
/// A point on the arc between and .
public readonly Point P1;
/// The ending point of the arc.
public readonly Point P2;
///
/// Initializes a new defined by three on-curve points.
///
public Arc3Point(Point p0, Point p1, Point p2);
///
/// Converts this three-point arc into a center-based if the arc is valid.
///
///
/// A valid if the input points define a circular segment; otherwise null.
/// If the result is null, consider falling back to a straight from to .
///
public Arc? ToCenterArc();
///
/// Converts this arc to an endpoint-based format, if valid.
///
public ArcEndpoint? ToEndpointArc();
///
/// Evaluates the curve at the given normalized parameter t in [0, 1].
///
public Point Lerp(nfloat t);
///
/// Computes the tangent vector at the specified t.
///
public Vector Tangent(nfloat t);
///
/// Provides indexer access as an alias for .
///
public Point this[nfloat t] { get; }
///
/// Computes an approximate arc length using 16 steps.
///
public nfloat Length();
///
/// Computes a refined approximation of arc length with a specified precision.
///
public nfloat Length(nfloat precision);
///
/// Implicitly converts a tuple of 3 points to an .
///
public static implicit operator Arc3Point((Point p0, Point p1, Point p2) value);
///
/// Splits the arc into one or two Y-monotonic segments.
///
///
/// This method finds the angle θ where the Y value of the arc reaches an extremum.
/// If this point lies within the arc, the arc is split at that angle into two Y-monotonic sub-arcs.
/// If no vertical extremum is found within the arc range, the arc is already monotonic.
///
public MonotonicArc3Point SplitIntoYMonotonicCurves();
}
///
/// Represents a circular or elliptical arc defined by radii, rotation, and endpoint parameters.
///
///
/// This arc representation uses start and end points along with size and sweep flags.
/// It is commonly used in vector graphics where the arc shape is inferred from geometry and direction flags.
///
public readonly struct ArcEndpoint : ICurve
{
/// The start point of the arc.
public readonly Point Start;
/// The end point of the arc.
public readonly Point End;
/// The horizontal radius of the arc.
public readonly nfloat RadiusX;
/// The vertical radius of the arc.
public readonly nfloat RadiusY;
/// The clockwise rotation (in radians) applied to the arc's ellipse relative to the X axis.
public readonly nfloat Rotation;
/// If true, the arc is the longer (greater than 180°) of the two possible arcs between points.
public readonly bool LargeArc;
/// The direction in which the arc is drawn (clockwise or counter-clockwise).
public readonly Winding Winding;
///
/// Initializes a new with the given geometry and flags.
///
/// The start point of the arc.
/// The end point of the arc.
/// The horizontal radius.
/// The vertical radius.
/// The clockwise rotation in radians applied to the ellipse.
/// Whether the arc should be the larger of the two possible arcs.
/// The sweep direction (clockwise or counter-clockwise).
public ArcEndpoint(Point start, Point end, nfloat rx, nfloat ry, nfloat rotation, bool largeArc, Winding winding);
///
/// Gets the interpolated point on the arc at the specified parameter .
///
/// A normalized value from 0 to 1 representing the progression along the arc.
public Point this[nfloat t] { get; }
///
/// Computes the interpolated point on the arc at a given parameter .
///
/// A normalized value in the range [0, 1].
public Point Lerp(nfloat t);
///
/// Evaluates the arc at a normalized parameter , returning the corresponding point.
///
/// A normalized value in the range [0, 1].
/// The corresponding point on the arc.
public Point Evaluate(nfloat t);
///
/// Computes the tangent vector at parameter on the arc.
///
/// A normalized value in the range [0, 1].
/// The normalized tangent vector at the evaluated point on the arc.
public Vector Tangent(nfloat t);
///
/// Approximates the arc length using uniform sampling with 16 segments.
///
/// The approximate total arc length.
public nfloat Length();
///
/// Approximates the arc length using recursive adaptive subdivision.
///
/// The maximum allowed error per segment for arc approximation.
/// The computed arc length within the specified flatness tolerance.
public nfloat Length(nfloat flatness);
///
/// Converts this endpoint-parameterized arc to a center-based .
///
/// A new representing the same shape.
public Arc ToCenterArc();
///
/// Splits this arc into a series of segments,
/// each spanning ≤ 90° and aligned so that one edge is axis-aligned.
///
///
/// A span to receive the output segments. Must have space for up to 4 entries.
///
///
/// The number of segments written to .
///
///
/// This method converts the arc into a center-based representation,
/// then delegates to its method. Each resulting
/// segment spans ≤ 90° and is safe for monotonic tessellation.
///
public void ToArc3Segments(Span buffer, out int count);
}
}
namespace Xui.Core.Curves2D
{
using Xui.Core.Math2D;
///
/// Static helper methods for constructing Bézier curves.
///
public static class Bezier
{
///
/// Creates a linear Bézier curve from two points.
///
public static LinearBezier Linear(Point p0, Point p1);
///
/// Creates a quadratic Bézier curve from three control points.
///
public static QuadraticBezier Quadratic(Point p0, Point p1, Point p2);
///
/// Creates a cubic Bézier curve from four control points.
///
public static CubicBezier Cubic(Point p0, Point p1, Point p2, Point p3);
}
///
/// Represents a cubic Bézier curve defined by four control points.
///
///
/// A cubic Bézier curve provides smooth interpolation between and ,
/// influenced by the control points and . This is commonly used in vector graphics,
/// animation timing, and layout paths.
///
public readonly struct CubicBezier : ICurve
{
/// The starting point of the curve.
public readonly Point P0;
/// The first control point, influencing the curve near .
public readonly Point P1;
/// The second control point, influencing the curve near .
public readonly Point P2;
/// The ending point of the curve.
public readonly Point P3;
///
/// Initializes a new cubic Bézier curve with the specified control points.
///
public CubicBezier(Point p0, Point p1, Point p2, Point p3);
///
/// Computes the interpolated point on the curve at parameter using De Casteljau’s algorithm.
///
/// A normalized parameter in the range [0, 1].
public Point Lerp(nfloat t);
///
/// Returns a quadratic Bézier that approximates this cubic by averaging the endpoint tangents.
/// Suitable as a fast approximation when subdivision is not required.
///
public QuadraticBezier QuadraticApproximation { get; }
///
/// Computes the tangent vector of the curve at parameter .
///
/// A normalized parameter in the range [0, 1].
public Vector Tangent(nfloat t);
///
/// Approximates the arc length of the curve using uniform sampling with 16 segments.
///
public nfloat Length();
///
/// Approximates the arc length of the curve using recursive adaptive subdivision.
///
///
/// The tolerance value used to determine when a segment is flat enough to stop subdividing.
/// Smaller values result in more accurate results but require more computation.
///
public nfloat Length(nfloat precision);
///
/// Gets the interpolated point on the curve at the specified parameter.
///
/// A normalized parameter in the range [0, 1].
public Point this[nfloat t] { get; }
///
/// Implicitly converts a tuple of four points into a .
///
/// A tuple representing the start point, two control points, and end point.
public static implicit operator CubicBezier((Point p0, Point p1, Point p2, Point p3) value);
///
/// Implicitly converts a to a
/// using interpolation for smooth parameterization.
///
///
/// This conversion evaluates the quadratic Bézier at fixed steps (1⁄3 and 2⁄3) to generate
/// the internal control points of the cubic, resulting in a visually smooth upgrade path.
///
public static implicit operator CubicBezier(QuadraticBezier quadratic);
///
/// Implicitly converts this cubic Catmull–Rom spline to a .
///
///
/// Uses the canonical Catmull–Rom to Bézier mapping, interpolating between P1 and P2.
///
public static implicit operator CubicBezier(CubicSpline spline);
///
/// Returns a new curve where the control points P1 and P2
/// are adjusted based on a drag gesture at a given parametric position .
///
///
/// A normalized value (between 0 and 1) representing the position on the curve where the drag occurs.
///
///
/// The drag vector representing how far the user dragged the point at .
///
///
/// A new with P0 and P3 unchanged,
/// and P1 and P2 adjusted proportionally to the drag direction and distance.
///
///
/// The influence of the drag on P1 and P2 is weighted quadratically based on their
/// distance from along the curve:
/// P1 is influenced by (1 - t)² and P2 by t².
/// This preserves the endpoints while allowing intuitive manipulation of the curve shape.
///
public CubicBezier Drag(nfloat t, Vector delta);
///
/// Returns a new cubic Bézier curve with adjusted control points so the point on the curve
/// nearest to is moved by .
///
public CubicBezier DragAt(Point origin, Vector delta);
///
/// Returns a new cubic Bézier curve with adjusted control points so the point on the curve
/// nearest to is moved by .
/// Uses recursive refinement based on the specified .
///
public CubicBezier DragAt(Point origin, Vector delta, nfloat precision);
///
/// Returns the parameter t ∈ [0, 1] at which the curve is closest to the specified point.
/// This version uses uniform sampling with 16 segments and is fast enough for interactive use.
///
/// The point to compare against the curve.
/// The approximate t value where the curve is closest to .
public nfloat ClosestT(Point target);
///
/// Returns the parameter t ∈ [0, 1] at which the curve is closest to the specified point,
/// using recursive ternary subdivision until the difference in t range is less than .
///
/// The point to compare against the curve.
/// The minimum resolution for t convergence. Smaller values yield more accurate results.
/// The t value where the curve is closest to within the specified .
public nfloat ClosestT(Point target, nfloat precision);
///
/// Splits this curve at the Y-derivative roots, returning up to three Y-monotonic segments
/// packed into a .
///
public MonotonicCubicBezier SplitIntoYMonotonicCurves();
///
/// Subdivides this cubic Bézier curve at parameter t, returning two curves.
///
public (CubicBezier, CubicBezier) Subdivide(nfloat t);
///
/// Converts this cubic Bézier curve into a sequence of Y-monotonic quadratic Bézier segments,
/// each approximating a portion of the original curve within the specified flatness precision.
///
///
/// A span to receive the quadratic segments. Must be large enough to hold the result.
/// A typical size is between 4 and 32. Must be at least 3 to accommodate the initial monotonic split.
///
///
/// The maximum allowed distance between the original cubic curve and its quadratic approximation.
/// Lower values yield more accurate approximations but may require more output segments.
///
///
/// The number of segments written to .
///
///
/// This method uses an adaptive, flatness-aware subdivision strategy. It begins by splitting the
/// cubic curve into up to 3 Y-monotonic segments. Each is then approximated with a quadratic Bézier,
/// and the segments with the highest deviation are recursively subdivided until the total number of
/// segments fits within and all segments meet the precision requirement.
///
/// The output segments are returned in order, forming a continuous piecewise-curve that follows the
/// original cubic. Suitable for SDF tessellation or scanline-based rasterization.
///
///
/// Thrown if has fewer than 3 elements.
///
public void ToQuadratics(Span buffer, nfloat precision, out int count);
///
/// A node in the adaptive subdivision linked list used by .
/// Each node holds a cubic segment, its quadratic approximation, and a flatness error measure.
///
public struct SubcurveNode
{
/// The cubic Bézier segment represented by this node.
public CubicBezier Segment;
/// The quadratic Bézier approximation of .
public QuadraticBezier QuadraticBezierApproximation;
/// The maximum perpendicular deviation of the approximation from the original cubic.
public nfloat Precision;
/// Index of the next node in the linked chain; 0 indicates this is the last node.
public ushort NextIndex;
///
/// Initializes a new node representing a quadratic approximation of a cubic Bézier segment in a linked list.
///
/// The original cubic Bézier segment.
/// Index of the next node in the chain. Use 0 if this is the last node.
public SubcurveNode(CubicBezier segment, ushort nextIndex = 0);
}
}
///
/// Represents a 4-point spline segment using Catmull–Rom interpolation.
/// The curve interpolates smoothly between and .
///
///
/// Catmull–Rom splines are useful for generating smooth curves through a sequence of points
/// with minimal configuration. This implementation produces a C¹-continuous cubic curve,
/// influenced by neighboring control points and .
/// The segment can also be converted into a for drawing or compatibility.
///
public readonly struct CubicSpline : ICurve
{
/// The control point before the start of the curve.
public readonly Point P0;
/// The starting point of the interpolated segment.
public readonly Point P1;
/// The ending point of the interpolated segment.
public readonly Point P2;
/// The control point after the end of the curve.
public readonly Point P3;
///
/// Initializes a new Catmull–Rom spline segment from four control points.
///
public CubicSpline(Point p0, Point p1, Point p2, Point p3);
///
/// Evaluates the point on the spline at the given parameter using the Catmull–Rom formula.
///
/// A normalized parameter in the range [0, 1].
public Point Lerp(nfloat t);
///
/// Computes the tangent vector at parameter by differentiating the spline.
///
/// A normalized parameter in the range [0, 1].
public Vector Tangent(nfloat t);
///
/// Approximates the arc length of the curve using uniform sampling with 16 segments.
///
public nfloat Length();
///
/// Approximates the arc length using recursive adaptive subdivision.
///
/// The tolerance used to decide subdivision depth.
public nfloat Length(nfloat precision);
///
/// Indexer-style access to evaluate the curve at a given parameter.
///
public Point this[nfloat t] { get; }
///
/// Converts this Catmull–Rom spline segment to an equivalent .
/// The resulting curve interpolates between and .
///
public static implicit operator CubicBezier(CubicSpline s);
}
///
/// Represents a common interface for evaluable 2D curves.
///
public interface ICurve
{
///
/// Evaluates the curve at the given normalized parameter t in [0, 1].
///
Point Lerp(nfloat t);
///
/// Computes the tangent vector at the specified t.
///
Vector Tangent(nfloat t);
///
/// Provides indexer access as an alias for .
///
Point this[nfloat t] { get; }
///
/// Computes an approximate arc length using 16 steps.
///
nfloat Length();
///
/// Computes a refined approximation of arc length with a specified precision.
///
nfloat Length(nfloat precision);
}
///
/// Represents a linear Bézier curve, equivalent to a straight line between two points.
///
///
/// This is the simplest form of Bézier curve, defined by two points and .
/// It is often used for edges of polygonal paths or degenerate forms of higher-order Béziers.
///
public readonly struct LinearBezier : ICurve
{
/// The start point of the curve.
public readonly Point P0;
/// The end point of the curve.
public readonly Point P1;
///
/// Initializes a new curve with the given start and end points.
///
/// The starting point.
/// The ending point.
public LinearBezier(Point p0, Point p1);
///
/// Computes the point on the line at parameter using linear interpolation.
///
/// A normalized parameter in the range [0, 1].
public Point Lerp(nfloat t);
///
/// Returns the constant tangent vector of the line segment.
///
/// The curve parameter (ignored since the tangent is constant).
public Vector Tangent(nfloat t);
///
/// Returns the exact length of the line segment.
///
public nfloat Length();
///
/// Returns the length of the line segment. This overload ignores the parameter.
///
public nfloat Length(nfloat precision);
///
/// Indexer-style access to the interpolated point at parameter .
///
public Point this[nfloat t] { get; }
///
/// Implicitly converts a tuple of two points into a .
///
public static implicit operator LinearBezier((Point p0, Point p1) value);
///
/// Implicitly converts this to a curve.
/// The intermediate point is set to the midpoint for visual smoothness.
///
public static implicit operator QuadraticBezier(LinearBezier linear);
///
/// Implicitly converts this to a curve.
/// Intermediate control points are interpolated at 1/3 and 2/3 for smooth spacing.
///
public static implicit operator CubicBezier(LinearBezier linear);
///
/// Implicitly converts a to a .
///
public static implicit operator LinearBezier(LinearSpline spline);
}
///
/// Represents a linear spline segment between two points.
///
///
/// A linear spline defines a straight-line interpolation between and .
/// It is the simplest form of spline, useful for polyline paths, control handles, and degenerate Bézier cases.
///
public readonly struct LinearSpline : ICurve
{
///
/// The starting point of the line segment.
///
public readonly Point P0;
///
/// The ending point of the line segment.
///
public readonly Point P1;
///
/// Initializes a new segment between two points.
///
/// The starting point of the spline.
/// The ending point of the spline.
public LinearSpline(Point p0, Point p1);
///
/// Interpolates a point on the segment at the specified parameter.
///
/// A normalized parameter in the range [0, 1].
/// The interpolated point on the line.
public Point Lerp(nfloat t);
///
/// Gets the constant tangent vector of the line segment.
///
/// A normalized parameter (unused, since the tangent is constant).
public Vector Tangent(nfloat t);
///
/// Evaluates the point on the spline at the specified parameter.
///
public Point this[nfloat t] { get; }
///
/// Returns the length of the segment.
///
public nfloat Length();
///
/// Returns the length of the segment. Precision is ignored for linear splines.
///
public nfloat Length(nfloat precision);
///
/// Converts this linear spline to a .
///
public static implicit operator LinearBezier(LinearSpline s);
}
///
/// Represents a quadratic Bézier curve defined by three control points.
///
///
/// A quadratic Bézier curve smoothly interpolates between and .
/// The curve is influenced by a single control point .
/// Quadratic Béziers are widely used in vector graphics, font rendering, and easing functions.
///
public readonly struct QuadraticBezier : ICurve
{
/// The starting point of the curve.
public readonly Point P0;
/// The control point that influences the curvature of the segment.
public readonly Point P1;
/// The ending point of the curve.
public readonly Point P2;
///
/// Initializes a new quadratic Bézier curve with the specified control points.
///
public QuadraticBezier(Point p0, Point p1, Point p2);
///
/// Evaluates the curve at parameter using De Casteljau’s algorithm.
///
/// A normalized parameter in the range [0, 1].
/// The interpolated point on the curve.
public Point Lerp(nfloat t);
///
/// Computes the tangent vector at parameter .
///
/// A normalized parameter in the range [0, 1].
/// The tangent vector at the specified point.
public Vector Tangent(nfloat t);
///
/// Approximates the arc length using uniform sampling over 16 segments.
///
/// The approximate total length of the curve.
public nfloat Length();
///
/// Approximates the arc length using recursive adaptive subdivision.
///
/// The maximum allowed error for curve flatness.
public nfloat Length(nfloat precision);
///
/// Evaluates the point on the curve at the specified parameter.
///
public Point this[nfloat t] { get; }
///
/// Converts a tuple of 3 points to a .
///
public static implicit operator QuadraticBezier((Point p0, Point p1, Point p2) value);
///
/// Converts a to a .
///
public static implicit operator QuadraticBezier(QuadraticSpline spline);
///
/// Adjusts the control point to drag the curve at by the given delta.
/// Keeps and fixed.
///
public QuadraticBezier Drag(nfloat t, Vector delta);
///
/// Adjusts the control point so that the curve is moved near by .
/// Uses coarse sampling to find the closest point.
///
public QuadraticBezier DragAt(Point origin, Vector delta);
///
/// Adjusts the control point so that the curve is moved near by .
/// Uses adaptive precision to locate the closest point.
///
public QuadraticBezier DragAt(Point origin, Vector delta, nfloat precision);
///
/// Finds the t value where the curve is closest to .
/// Uses uniform sampling across 16 points.
///
public nfloat ClosestT(Point target);
///
/// Finds the t value where the curve is closest to .
/// Uses recursive ternary subdivision with the specified .
///
public nfloat ClosestT(Point target, nfloat precision);
///
/// Splits the current quadratic Bézier curve into two segments if it is not monotonic in the Y direction.
///
///
/// A instance containing one or two sub-curves, each guaranteed to be monotonic in Y.
/// If the curve is already Y-monotonic (i.e., has no vertical extrema within (0,1)), a single-segment result is returned.
///
///
/// This method analyzes the derivative of the Y component of the curve to determine if a vertical extremum occurs
/// within the curve's parameter domain. If a critical point is found in (0,1), the curve is split at that point to ensure
/// each resulting segment is Y-monotonic. This is useful for scanline rasterization, tessellation, or other geometry processing
/// that requires monotonic segments.
///
public MonotonicQuadraticBezier SplitIntoYMonotonicCurves();
///
/// Subdivides this quadratic Bézier curve at parameter t, returning two curves.
///
public (QuadraticBezier, QuadraticBezier) Subdivide(nfloat t);
}
///
/// Represents a 3-point quadratic spline segment (parabolic arc) defined by a start point, control point, and end point.
///
///
/// This spline uses the De Casteljau algorithm for interpolation and arc length approximation.
/// The curve passes through and , with acting as the control point that defines curvature.
///
public readonly struct QuadraticSpline : ICurve
{
/// The start point of the spline.
public readonly Point P0;
/// The control point that defines the curvature of the arc.
public readonly Point P1;
/// The end point of the spline.
public readonly Point P2;
///
/// Initializes a new with the given start, control, and end points.
///
public QuadraticSpline(Point p0, Point p1, Point p2);
///
/// Computes the point on the spline at parameter using De Casteljau interpolation.
///
/// A normalized parameter between 0 and 1.
public Point Lerp(nfloat t);
///
/// Computes the tangent vector at parameter on the spline.
///
/// A normalized parameter between 0 and 1.
public Vector Tangent(nfloat t);
///
/// Approximates the total arc length of the spline using a fixed 16-sample De Casteljau subdivision.
///
public nfloat Length();
///
/// Approximates the arc length with adaptive subdivision using the specified precision tolerance.
///
/// The maximum allowed error in the approximation.
public nfloat Length(nfloat precision);
///
/// Evaluates the point on the spline at parameter .
///
public Point this[nfloat t] { get; }
///
/// Converts this spline to a curve with the same control points.
///
public static implicit operator QuadraticBezier(QuadraticSpline s);
}
///
/// Represents a straight line segment from to .
/// Implements the interface for compatibility with other curve types.
///
public readonly struct Segment : ICurve
{
/// The starting point of the line segment.
public readonly Point P0;
/// The ending point of the line segment.
public readonly Point P1;
/// Initializes a new line from to .
public Segment(Point p0, Point p1);
///
/// Evaluates the curve at the given normalized parameter t in [0, 1].
///
public Point Lerp(nfloat t);
///
/// Computes the tangent vector at the specified t.
///
public Vector Tangent(nfloat t);
///
/// Provides indexer access as an alias for .
///
public Point this[nfloat t] { get; }
///
/// Computes an approximate arc length using 16 steps.
///
public nfloat Length();
///
/// Computes a refined approximation of arc length with a specified precision.
///
public nfloat Length(nfloat precision);
///
/// Converts a tuple to a .
///
public static implicit operator Segment((Point p0, Point p1) value);
}
///
/// Provides factory methods for creating spline segments of various degrees.
///
public static class Spline
{
///
/// Creates a linear spline (degree 1) between two points.
///
public static LinearSpline Linear(Point p0, Point p1);
///
/// Creates a quadratic spline (degree 2) between three points.
///
public static QuadraticSpline Quadratic(Point p0, Point p1, Point p2);
///
/// Creates a cubic spline (degree 3) using Catmull–Rom interpolation through P1 and P2.
///
///
/// This produces a smooth segment influenced by surrounding control points and .
///
public static CubicSpline Cubic(Point p0, Point p1, Point p2, Point p3);
}
}
namespace Xui.Core.Curves2D
{
///
/// Represents one or two segments that are each monotonic in the Y direction.
///
public readonly struct MonotonicArc3Point
{
/// The first monotonic segment.
public readonly Arc3Point First;
/// The optional second segment, if the arc was split.
public readonly Arc3Point? Second;
/// Creates a single-segment monotonic arc.
public MonotonicArc3Point(Arc3Point only);
/// Creates a two-segment Y-monotonic arc.
public MonotonicArc3Point(Arc3Point first, Arc3Point second);
/// True if the arc was split into two segments.
public bool IsSplit { get; }
}
///
/// Holds one, two, or three Y-monotonic cubic Bézier segments that together represent
/// the result of splitting a single cubic at its Y-derivative roots.
///
public readonly struct MonotonicCubicBezier
{
/// The first (and always present) Y-monotonic segment.
public readonly CubicBezier First;
/// The second Y-monotonic segment, or null if the original had at most one Y-extremum.
public readonly CubicBezier? Second;
/// The third Y-monotonic segment, or null if the original had fewer than two Y-extrema.
public readonly CubicBezier? Third;
/// Initializes the struct with one, two, or three Y-monotonic segments.
/// The first monotonic segment.
/// The second monotonic segment, if any.
/// The third monotonic segment, if any.
public MonotonicCubicBezier(CubicBezier first, CubicBezier? second = null, CubicBezier? third = null);
}
///
/// Holds one or two Y-monotonic quadratic Bézier segments that together represent
/// a single quadratic curve split at its Y-extremum.
///
public readonly struct MonotonicQuadraticBezier
{
/// The first (and always present) Y-monotonic segment.
public readonly QuadraticBezier First;
/// The second Y-monotonic segment, or null if no split was needed.
public readonly QuadraticBezier? Second;
/// Initializes the struct with one or two Y-monotonic segments.
/// The first monotonic segment.
/// The second monotonic segment, if any.
public MonotonicQuadraticBezier(QuadraticBezier first, QuadraticBezier? second = null);
}
}