Donner 0.5.0
Embeddable browser-grade SVG2 engine
Loading...
Searching...
No Matches
Bezier Utilities

Free functions for evaluating, splitting, approximating, and computing bounding boxes of quadratic and cubic Bezier curves. More...

Functions

Vector2d donner::EvalQuadratic (const Vector2d &p0, const Vector2d &p1, const Vector2d &p2, double t)
 Evaluate a quadratic Bezier curve at parameter t using the standard basis expansion.
Vector2d donner::EvalCubic (const Vector2d &p0, const Vector2d &p1, const Vector2d &p2, const Vector2d &p3, double t)
 Evaluate a cubic Bezier curve at parameter t using the standard basis expansion.
std::pair< std::array< Vector2d, 3 >, std::array< Vector2d, 3 > > donner::SplitQuadratic (const Vector2d &p0, const Vector2d &p1, const Vector2d &p2, double t)
 Split a quadratic Bezier curve at parameter t using De Casteljau subdivision.
std::pair< std::array< Vector2d, 4 >, std::array< Vector2d, 4 > > donner::SplitCubic (const Vector2d &p0, const Vector2d &p1, const Vector2d &p2, const Vector2d &p3, double t)
 Split a cubic Bezier curve at parameter t using De Casteljau subdivision.
void donner::ApproximateCubicWithQuadratics (const Vector2d &p0, const Vector2d &p1, const Vector2d &p2, const Vector2d &p3, double tolerance, std::vector< Vector2d > &out)
 Approximate a cubic Bezier curve as a sequence of quadratic Bezier curves within a given tolerance.
SmallVector< double, 1 > donner::QuadraticYExtrema (const Vector2d &p0, const Vector2d &p1, const Vector2d &p2)
 Find parameter values where the Y-derivative is zero for a quadratic Bezier curve.
SmallVector< double, 2 > donner::CubicYExtrema (const Vector2d &p0, const Vector2d &p1, const Vector2d &p2, const Vector2d &p3)
 Find parameter values where the Y-derivative is zero for a cubic Bezier curve.
Box2d donner::QuadraticBounds (const Vector2d &p0, const Vector2d &p1, const Vector2d &p2)
 Compute the tight axis-aligned bounding box of a quadratic Bezier curve.
Box2d donner::CubicBounds (const Vector2d &p0, const Vector2d &p1, const Vector2d &p2, const Vector2d &p3)
 Compute the tight axis-aligned bounding box of a cubic Bezier curve.

Detailed Description

Free functions for evaluating, splitting, approximating, and computing bounding boxes of quadratic and cubic Bezier curves.

These are used by the GPU rendering backend (Geode) for path processing.

Function Documentation

◆ ApproximateCubicWithQuadratics()

void donner::ApproximateCubicWithQuadratics ( const Vector2d & p0,
const Vector2d & p1,
const Vector2d & p2,
const Vector2d & p3,
double tolerance,
std::vector< Vector2d > & out )

Approximate a cubic Bezier curve as a sequence of quadratic Bezier curves within a given tolerance.

Appends quadratic control-point pairs (control, end) to out. The start point of each quadratic is the end point of the previous one (or p0 for the first). Uses recursive subdivision with a maximum depth of 10 to avoid infinite loops.

Parameters
p0Start point.
p1First control point.
p2Second control point.
p3End point.
toleranceMaximum allowed distance between the cubic and its quadratic approximation.
[out]outOutput vector to which (control, end) point pairs are appended.

◆ CubicBounds()

Box2d donner::CubicBounds ( const Vector2d & p0,
const Vector2d & p1,
const Vector2d & p2,
const Vector2d & p3 )

Compute the tight axis-aligned bounding box of a cubic Bezier curve.

Evaluates the curve at both X and Y extrema (not just the control-point hull) to produce the tightest axis-aligned bounds.

Parameters
p0Start point.
p1First control point.
p2Second control point.
p3End point.
Returns
The tight bounding box.

◆ CubicYExtrema()

SmallVector< double, 2 > donner::CubicYExtrema ( const Vector2d & p0,
const Vector2d & p1,
const Vector2d & p2,
const Vector2d & p3 )

Find parameter values where the Y-derivative is zero for a cubic Bezier curve.

These are the Y-monotonic split points. Returns 0, 1, or 2 parameter values in the open interval (0, 1), sorted in ascending order.

Parameters
p0Start point.
p1First control point.
p2Second control point.
p3End point.
Returns
A SmallVector containing 0 to 2 parameter values.

◆ EvalCubic()

Vector2d donner::EvalCubic ( const Vector2d & p0,
const Vector2d & p1,
const Vector2d & p2,
const Vector2d & p3,
double t )

Evaluate a cubic Bezier curve at parameter t using the standard basis expansion.

\( B(t) = (1-t)^3 p_0 + 3t(1-t)^2 p_1 + 3t^2(1-t) p_2 + t^3 p_3 \)

Parameters
p0Start point.
p1First control point.
p2Second control point.
p3End point.
tParameter in [0, 1].
Returns
The point on the curve at parameter t.

◆ EvalQuadratic()

Vector2d donner::EvalQuadratic ( const Vector2d & p0,
const Vector2d & p1,
const Vector2d & p2,
double t )

Evaluate a quadratic Bezier curve at parameter t using the standard basis expansion.

\( B(t) = (1-t)^2 p_0 + 2t(1-t) p_1 + t^2 p_2 \)

Parameters
p0Start point.
p1Control point.
p2End point.
tParameter in [0, 1].
Returns
The point on the curve at parameter t.

◆ QuadraticBounds()

Box2d donner::QuadraticBounds ( const Vector2d & p0,
const Vector2d & p1,
const Vector2d & p2 )

Compute the tight axis-aligned bounding box of a quadratic Bezier curve.

Evaluates the curve at both X and Y extrema (not just the control-point hull) to produce the tightest axis-aligned bounds.

Parameters
p0Start point.
p1Control point.
p2End point.
Returns
The tight bounding box.

◆ QuadraticYExtrema()

SmallVector< double, 1 > donner::QuadraticYExtrema ( const Vector2d & p0,
const Vector2d & p1,
const Vector2d & p2 )

Find parameter values where the Y-derivative is zero for a quadratic Bezier curve.

These are the Y-monotonic split points. Returns 0 or 1 parameter values in the open interval (0, 1).

Parameters
p0Start point.
p1Control point.
p2End point.
Returns
A SmallVector containing 0 or 1 parameter values.

◆ SplitCubic()

std::pair< std::array< Vector2d, 4 >, std::array< Vector2d, 4 > > donner::SplitCubic ( const Vector2d & p0,
const Vector2d & p1,
const Vector2d & p2,
const Vector2d & p3,
double t )

Split a cubic Bezier curve at parameter t using De Casteljau subdivision.

Returns two cubic curves whose union equals the original curve.

Parameters
p0Start point.
p1First control point.
p2Second control point.
p3End point.
tSplit parameter in [0, 1].
Returns
A pair of {left, right} point arrays, each describing a cubic Bezier.

◆ SplitQuadratic()

std::pair< std::array< Vector2d, 3 >, std::array< Vector2d, 3 > > donner::SplitQuadratic ( const Vector2d & p0,
const Vector2d & p1,
const Vector2d & p2,
double t )

Split a quadratic Bezier curve at parameter t using De Casteljau subdivision.

Returns two quadratic curves whose union equals the original curve.

Parameters
p0Start point.
p1Control point.
p2End point.
tSplit parameter in [0, 1].
Returns
A pair of {left, right} point arrays, each describing a quadratic Bezier.