36#ifndef LIB2GEOM_SEEN_BEZIER_CURVE_H
37#define LIB2GEOM_SEEN_BEZIER_CURVE_H
85 virtual void setPoints(std::vector<Point>
const &ps) {
87 if (ps.size() !=
order() + 1)
88 THROW_LOGICALERROR(
"BezierCurve::setPoints: incorrect number of points in vector");
89 for(
unsigned i = 0; i <=
order(); i++) {
116 if(i->min() == 0 && i->max() == 1)
return boundsFast();
133 using Curve::operator*=;
135 for (
unsigned i = 0; i <
size(); ++i) {
141 for (
unsigned i = 0; i <
size(); ++i) {
147 for (
unsigned i = 0; i <
size(); ++i) {
156 return 2 * (
order() + 1);
159 return (
inner[d] - v).roots();
166 return inner.valueAndDerivatives(t, n);
178template <
unsigned degree>
182 template <
unsigned required_degree>
205 unsigned ord = points.size() - 1;
206 if (ord !=
degree) THROW_LOGICALERROR(
"BezierCurve<degree> does not match number of points");
207 for (
unsigned d = 0; d < 2; ++d) {
209 for(
unsigned i = 0; i <= ord; i++)
210 inner[d][i] = points[i][d];
216 assert_degree<1>(
this);
217 for(
unsigned d = 0; d < 2; d++)
223 assert_degree<2>(
this);
224 for(
unsigned d = 0; d < 2; d++)
230 assert_degree<3>(
this);
231 for(
unsigned d = 0; d < 2; d++)
246 std::pair<Bezier, Bezier> sx =
inner[
X].subdivide(t), sy =
inner[
Y].subdivide(t);
247 return std::make_pair(
257 if constexpr (
degree == 1) {
320template <
unsigned degree>
pair< double, double > Point
Bernstein-Bezier polynomial.
3x3 matrix representing an affine transformation.
Bezier curve with compile-time specified order.
bool isDegenerate() const override
Check whether the curve has exactly zero length.
std::pair< BezierCurveN, BezierCurveN > subdivide(Coord t) const
Divide a Bezier curve into two curves.
BezierCurveN(Point c0, Point c1)
Construct a linear segment from its endpoints.
Curve * portion(Coord f, Coord t) const override
Create a curve that corresponds to a part of this curve.
Curve * duplicate() const override
Create an exact copy of this curve.
void feed(PathSink &sink, bool moveto_initial) const override
Feed the curve to a PathSink.
BezierCurveN(Point c0, Point c1, Point c2)
Construct a quadratic Bezier curve from its control points.
BezierCurveN(D2< Bezier > const &x)
Construct from 2D Bezier polynomial.
std::vector< CurveIntersection > intersect(Curve const &other, Coord eps=EPSILON) const override
Compute intersections with another curve.
BezierCurveN(Bezier x, Bezier y)
Construct from two 1D Bezier polynomials of the same order.
int winding(Point const &p) const override
Compute the partial winding number of this curve.
static void assert_degree(BezierCurveN< required_degree > const *)
Coord nearestTime(Point const &p, Coord from=0, Coord to=1) const override
Compute a time value at which the curve comes closest to a specified point.
bool isLineSegment() const override
Return false if there are at least 3 distinct control points, true otherwise.
Curve * derivative() const override
Create a derivative of this curve.
BezierCurveN()
Construct a Bezier curve of the specified order with all points zero.
void expandToTransformed(Rect &bbox, Affine const &transform) const override
Expand the given rectangle to include the transformed curve, assuming it already contains its initial...
BezierCurveN(Point c0, Point c1, Point c2, Point c3)
Construct a cubic Bezier curve from its control points.
Curve * reverse() const override
Create a reversed version of this curve.
BezierCurveN(std::vector< Point > const &points)
Construct a Bezier curve from a vector of its control points.
Two-dimensional Bezier curve of arbitrary order.
Curve * duplicate() const override
Create an exact copy of this curve.
bool isLineSegment() const override
Return false if there are at least 3 distinct control points, true otherwise.
OptRect boundsLocal(OptInterval const &i, unsigned deg) const override
BezierCurve(D2< Bezier > const &b)
bool isDegenerate() const override
Check whether the curve has exactly zero length.
Rect boundsExact() const override
Compute the curve's exact bounding box.
void setInitial(Point const &v) override
Change the starting point of the curve.
std::vector< Coord > timesWithRadiusOfCurvature(double radius) const
Computes the times where the radius of curvature of the bezier curve equals the given radius.
Rect boundsFast() const override
Quickly compute the curve's approximate bounding box.
void operator*=(Scale const &s) override
void operator*=(Translate const &tr) override
D2< SBasis > toSBasis() const override
Convert the curve to a symmetric power basis polynomial.
unsigned size() const
Get the number of control points.
Curve * derivative() const override
Create a derivative of this curve.
D2< Bezier > const & fragment() const
Coord length(Coord tolerance) const override
Compute the arc length of this curve.
bool _equalTo(Curve const &c) const override
Coord nearestTime(Point const &p, Coord from=0, Coord to=1) const override
Compute a time value at which the curve comes closest to a specified point.
void operator*=(Affine const &m) override
virtual void setPoints(std::vector< Point > const &ps)
Set new control points.
Coord valueAt(Coord t, Dim2 d) const override
Evaluate one of the coordinates at the specified time value.
Point finalPoint() const override
Retrieve the end of the curve.
bool isNear(Curve const &c, Coord precision) const override
Test whether two curves are approximately the same.
Point pointAt(Coord t) const override
Evaluate the curve at a specified time value.
void feed(PathSink &sink, bool) const override
Feed the curve to a PathSink.
Point initialPoint() const override
Retrieve the start of the curve.
BezierCurve(Bezier const &x, Bezier const &y)
void setFinal(Point const &v) override
Change the ending point of the curve.
std::vector< CurveIntersection > intersect(Curve const &other, Coord eps=EPSILON) const override
Compute intersections with another curve.
int degreesOfFreedom() const override
Return the number of independent parameters required to represent all variations of this curve.
Curve * reverse() const override
Create a reversed version of this curve.
std::vector< Coord > roots(Coord v, Dim2 d) const override
Computes time values at which the curve intersects an axis-aligned line.
void setPoint(unsigned ix, Point const &v)
Modify a control point.
Point controlPoint(unsigned ix) const
Access control points of the curve.
std::vector< Point > controlPoints() const
Get the control points.
Point operator[](unsigned ix) const
Curve * portion(Coord f, Coord t) const override
Create a curve that corresponds to a part of this curve.
unsigned order() const
Get the order of the Bezier curve.
void expandToTransformed(Rect &bbox, Affine const &transform) const override
Expand the given rectangle to include the transformed curve, assuming it already contains its initial...
std::vector< Point > pointAndDerivatives(Coord t, unsigned n) const override
Evaluate the curve and its derivatives.
Polynomial in Bernstein-Bezier basis.
Abstract continuous curve on a plane defined on [0,1].
virtual int winding(Point const &p) const
Compute the partial winding number of this curve.
void transform(Affine const &m)
Transform this curve by an affine transformation.
Adaptor that creates 2D functions from 1D ones.
Range of real numbers that can be empty.
Axis-aligned rectangle that can be empty.
Callback interface for processing path data.
Two-dimensional point that doubles as a vector.
Axis aligned, non-empty rectangle.
double inner(valarray< double > const &x, valarray< double > const &y)
BezierCurveN< 3 > CubicBezier
Cubic (order 3) Bezier curve.
BezierCurveN< 1 > LineSegment
Line segment.
BezierCurveN< 2 > QuadraticBezier
Quadratic (order 2) Bezier curve.
Dim2
2D axis enumeration (X or Y).
double Coord
Floating point type used to store coordinates.
constexpr Coord EPSILON
Default "acceptably small" value.
Various utility functions.
Coord length(LineSegment const &seg)
OptInterval bounds_exact(Bezier const &b)
Bezier reverse(const Bezier &a)
OptInterval bounds_local(Bezier const &b, OptInterval const &i)
std::vector< Point > bezier_points(const D2< Bezier > &a)
Angle distance(Angle const &a, Angle const &b)
Coord bezier_length(std::vector< Point > const &points, Coord tolerance=0.01)
Compute the length of a bezier curve given by a vector of its control points.
Bezier portion(const Bezier &a, double from, double to)
Bezier derivative(Bezier const &a)
OptInterval bounds_fast(Bezier const &b)
Point middle_point(LineSegment const &_segment)
Symmetric power basis curve.