Table of Contents

Struct QuadraticBezier

Namespace
Xui.Core.Curves2D
Assembly
Core.dll

Represents a quadratic Bézier curve defined by three control points.

public readonly struct QuadraticBezier : ICurve
Implements
Inherited Members

Remarks

A quadratic Bézier curve smoothly interpolates between P0 and P2. The curve is influenced by a single control point P1. Quadratic Béziers are widely used in vector graphics, font rendering, and easing functions.

Constructors

QuadraticBezier(Point, Point, Point)

Initializes a new quadratic Bézier curve with the specified control points.

public QuadraticBezier(Point p0, Point p1, Point p2)

Parameters

p0 Point
p1 Point
p2 Point

Fields

P0

The starting point of the curve.

public readonly Point P0

Field Value

Point

P1

The control point that influences the curvature of the segment.

public readonly Point P1

Field Value

Point

P2

The ending point of the curve.

public readonly Point P2

Field Value

Point

Properties

this[NFloat]

Evaluates the point on the curve at the specified parameter.

public Point this[NFloat t] { get; }

Parameters

t NFloat

Property Value

Point

Methods

ClosestT(Point)

Finds the t value where the curve is closest to target. Uses uniform sampling across 16 points.

public NFloat ClosestT(Point target)

Parameters

target Point

Returns

NFloat

ClosestT(Point, NFloat)

Finds the t value where the curve is closest to target. Uses recursive ternary subdivision with the specified precision.

public NFloat ClosestT(Point target, NFloat precision)

Parameters

target Point
precision NFloat

Returns

NFloat

Drag(NFloat, Vector)

Adjusts the control point to drag the curve at t by the given delta. Keeps P0 and P2 fixed.

public QuadraticBezier Drag(NFloat t, Vector delta)

Parameters

t NFloat
delta Vector

Returns

QuadraticBezier

DragAt(Point, Vector)

Adjusts the control point so that the curve is moved near origin by delta. Uses coarse sampling to find the closest point.

public QuadraticBezier DragAt(Point origin, Vector delta)

Parameters

origin Point
delta Vector

Returns

QuadraticBezier

DragAt(Point, Vector, NFloat)

Adjusts the control point so that the curve is moved near origin by delta. Uses adaptive precision to locate the closest point.

public QuadraticBezier DragAt(Point origin, Vector delta, NFloat precision)

Parameters

origin Point
delta Vector
precision NFloat

Returns

QuadraticBezier

Length()

Approximates the arc length using uniform sampling over 16 segments.

public NFloat Length()

Returns

NFloat

The approximate total length of the curve.

Length(NFloat)

Approximates the arc length using recursive adaptive subdivision.

public NFloat Length(NFloat precision)

Parameters

precision NFloat

The maximum allowed error for curve flatness.

Returns

NFloat

Lerp(NFloat)

Evaluates the curve at parameter t using De Casteljau’s algorithm.

public Point Lerp(NFloat t)

Parameters

t NFloat

A normalized parameter in the range [0, 1].

Returns

Point

The interpolated point on the curve.

SplitIntoYMonotonicCurves()

Splits the current quadratic Bézier curve into two segments if it is not monotonic in the Y direction.

public MonotonicQuadraticBezier SplitIntoYMonotonicCurves()

Returns

MonotonicQuadraticBezier

A MonotonicQuadraticBezier 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.

Remarks

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.

Subdivide(NFloat)

Subdivides this quadratic Bézier curve at parameter t, returning two curves.

public (QuadraticBezier, QuadraticBezier) Subdivide(NFloat t)

Parameters

t NFloat

Returns

(QuadraticBezier, QuadraticBezier)

Tangent(NFloat)

Computes the tangent vector at parameter t.

public Vector Tangent(NFloat t)

Parameters

t NFloat

A normalized parameter in the range [0, 1].

Returns

Vector

The tangent vector at the specified point.

Operators

implicit operator QuadraticBezier((Point p0, Point p1, Point p2))

Converts a tuple of 3 points to a QuadraticBezier.

public static implicit operator QuadraticBezier((Point p0, Point p1, Point p2) value)

Parameters

value (Point p0, Point p1, Point p2)

Returns

QuadraticBezier

implicit operator QuadraticBezier(QuadraticSpline)

public static implicit operator QuadraticBezier(QuadraticSpline spline)

Parameters

spline QuadraticSpline

Returns

QuadraticBezier