Ipelib
Public Member Functions | Static Public Member Functions | Public Attributes | List of all members
ipe::Bezier Class Reference

#include <ipegeo.h>

Public Member Functions

 Bezier ()
 
 Bezier (const Vector &p0, const Vector &p1, const Vector &p2, const Vector &p3)
 
Vector point (double t) const
 
Vector tangent (double t) const
 
double distance (const Vector &v, double bound)
 
bool straight (double precision) const
 
void subdivide (Bezier &l, Bezier &r) const
 
void approximate (double precision, std::vector< Vector > &result) const
 
Rect bbox () const
 
bool snap (const Vector &v, double &t, Vector &pos, double &bound) const
 
void intersect (const Line &l, std::vector< Vector > &result) const
 
void intersect (const Segment &l, std::vector< Vector > &result) const
 
void intersect (const Bezier &b, std::vector< Vector > &result) const
 

Static Public Member Functions

static Bezier quadBezier (const Vector &p0, const Vector &p1, const Vector &p2)
 
static void oldSpline (int n, const Vector *v, std::vector< Bezier > &result)
 
static void spline (int n, const Vector *v, std::vector< Bezier > &result)
 
static void cardinalSpline (int n, const Vector *v, double tension, std::vector< Bezier > &result)
 
static void spiroSpline (int n, const Vector *v, std::vector< Bezier > &result)
 
static void closedSpline (int n, const Vector *v, std::vector< Bezier > &result)
 

Public Attributes

Vector iV [4]
 

Detailed Description

A cubic Bezier spline.

Constructor & Destructor Documentation

◆ Bezier() [1/2]

ipe::Bezier::Bezier ( )
inline

Default constructor, uninitialized curve.

Referenced by cardinalSpline(), closedSpline(), intersect(), oldSpline(), quadBezier(), spiroSpline(), and spline().

◆ Bezier() [2/2]

ipe::Bezier::Bezier ( const Vector p0,
const Vector p1,
const Vector p2,
const Vector p3 
)
inline

Constructor with four control points.

References iV.

Member Function Documentation

◆ point()

Vector Bezier::point ( double  t) const

Return point on curve with parameter t (from 0.0 to 1.0).

References iV.

Referenced by snap().

◆ tangent()

Vector Bezier::tangent ( double  t) const

Return tangent direction of curve at parameter t (from 0.0 to 1.0).

The returned vector is not normalized.

References iV.

Referenced by ipe::Snap::setEdge().

◆ distance()

double Bezier::distance ( const Vector v,
double  bound 
)

Return distance to Bezier spline.

But may just return bound if actual distance is larger. The Bezier spline is approximated to a precision of 1.0, and the distance to the approximation is returned.

References ipe::Rect::addPoint(), approximate(), ipe::Rect::certainClearance(), and iV.

◆ straight()

bool Bezier::straight ( double  precision) const

Returns true if the Bezier curve is nearly identical to the line segment iV[0]..iV[3].

References ipe::Line::distance(), iV, and ipe::Line::through().

Referenced by approximate(), ipe::Arc::intersect(), intersect(), and snap().

◆ subdivide()

void Bezier::subdivide ( Bezier l,
Bezier r 
) const

Subdivide this Bezier curve in the middle.

References iV.

Referenced by approximate(), ipe::Arc::intersect(), intersect(), and snap().

◆ approximate()

void Bezier::approximate ( double  precision,
std::vector< Vector > &  result 
) const

Approximate by a polygonal chain.

result must be empty when calling this.

References approximate(), iV, straight(), and subdivide().

Referenced by approximate(), bbox(), and distance().

◆ bbox()

Rect Bezier::bbox ( ) const

Return a tight bounding box (accurate to within 0.5).

References ipe::Rect::addPoint(), approximate(), ipe::Rect::bottomLeft(), iV, and ipe::Rect::topRight().

Referenced by ipe::BBoxPainter::doCurveTo().

◆ snap()

bool Bezier::snap ( const Vector v,
double &  t,
Vector pos,
double &  bound 
) const

Find (approximately) nearest point on Bezier spline.

Find point on spline nearest to v, but only if it is closer than bound. If a point is found, sets t to the parameter value and pos to the actual point, and returns true.

References ipe::Rect::addPoint(), ipe::Rect::certainClearance(), iV, point(), ipe::Vector::snap(), snap(), straight(), and subdivide().

Referenced by ipe::Snap::setEdge(), and snap().

◆ quadBezier()

Bezier Bezier::quadBezier ( const Vector p0,
const Vector p1,
const Vector p2 
)
static

Convert a quadratic Bezier-spline to a cubic one.

The quadratic Bezier-spline with control points p0, p1, p2 is identical to the cubic Bezier-spline with control points q0 = p0, q1 = (2p1 + p0)/3, q2 = (2p1 + p2)/3, q3 = p2.

References Bezier().

Referenced by spline().

◆ oldSpline()

void Bezier::oldSpline ( int  n,
const Vector v,
std::vector< Bezier > &  result 
)
static

Convert an old-style Ipe B-spline to a series of Bezier splines.

For some reason lost in the mist of time, this was the definition of splines in Ipe for many years. It doesn't use knots. The first and last control point are simply given multiplicity 3.

Bezier splines are appended to result.

References Bezier().

Referenced by ipe::CurveSegment::beziers().

◆ spline()

void Bezier::spline ( int  n,
const Vector v,
std::vector< Bezier > &  result 
)
static

Convert a clamped uniform B-spline to a series of Bezier splines.

See Thomas Sederberg, Computer-Aided Geometric Design, Chapter 6.

In polar coordinates, a control point is defined by three knots, so n control points need n + 2 knots. To clamp the spline to the first and last control point, the first and last knot are repeated three times. This leads to k knot intervals and the knot sequence [0, 0, 0, 1, 2, 3, 4, 5, 6, ..., k-2, k-1, k, k, k] There are k + 5 = n + 2 knots in this sequence, so k = n-3 is the number of knot intervals and therefore the number of output Bezier curves.

If n = 4, the knot sequence is [0, 0, 0, 1, 1, 1] and the result is simply the Bezier curve on the four control points.

When n in {2, 3}, returns a single Bezier curve that is a segment or quadratic Bezier spline. This is different from the behaviour of the "old" Ipe splines.

Bezier splines are appended to result.

References Bezier(), and quadBezier().

Referenced by ipe::CurveSegment::beziers(), and spiroSpline().

◆ cardinalSpline()

void Bezier::cardinalSpline ( int  n,
const Vector v,
double  tension,
std::vector< Bezier > &  result 
)
static

Convert a cardinal spline to a series of Bezier splines.

Bezier splines are appended to result.

References Bezier().

Referenced by ipe::CurveSegment::beziers().

◆ spiroSpline()

void Bezier::spiroSpline ( int  n,
const Vector v,
std::vector< Bezier > &  result 
)
static

◆ closedSpline()

void Bezier::closedSpline ( int  n,
const Vector v,
std::vector< Bezier > &  result 
)
static

Convert a closed uniform cubic B-spline to a series of Bezier splines.

Bezier splines are appended to result.

References Bezier().

Referenced by ipe::ClosedSpline::beziers().

◆ intersect() [1/3]

void Bezier::intersect ( const Line l,
std::vector< Vector > &  result 
) const

Compute intersection points of Bezier with Line.

References intersect(), iV, ipe::Line::side(), straight(), and subdivide().

Referenced by intersect().

◆ intersect() [2/3]

void Bezier::intersect ( const Segment l,
std::vector< Vector > &  result 
) const

Compute intersection points of Bezier with Segment.

References Bezier(), ipe::Segment::iP, and ipe::Segment::iQ.

◆ intersect() [3/3]

void Bezier::intersect ( const Bezier b,
std::vector< Vector > &  result 
) const

Compute intersection points of Bezier with Bezier.

Member Data Documentation

◆ iV

Vector ipe::Bezier::iV[4]

The documentation for this class was generated from the following files: