38#ifndef LIB2GEOM_SEEN_BEZIER_H
39#define LIB2GEOM_SEEN_BEZIER_H
60 for(
unsigned i=1; i<n; i++){
63 tmp = (tmp + tn*bc*c_[i])*u;
65 return (tmp + tn*t*c_[n]);
83 if (!left && !right) {
89 std::copy(v, v +
order + 1, left);
91 for (std::size_t i =
order; i > 0; --i) {
92 for (std::size_t j = i; j <=
order; ++j) {
93 left[j] =
lerp(t, left[j-1], left[j]);
101 std::copy(v, v +
order + 1, right);
103 for (std::size_t i = 1; i <=
order; ++i) {
105 left[i-1] = right[0];
107 for (std::size_t j = i; j > 0; --j) {
108 right[j-1] =
lerp(t, right[j-1], right[j]);
113 left[
order] = right[0];
123 : boost::arithmetic< Bezier, double
124 , boost::additive< Bezier
128 std::valarray<Coord>
c_;
137 double l,
double r)
const;
147 unsigned size()
const {
return c_.size();}
152 if (
c_.size() != other.
c_.size() ) {
165 for (
size_t i = 0; i <
c_.size(); i++) {
166 if (
c_[i] != other.
c_[i]) {
175 return !(*
this == other);
182 operator unsigned()
const {
return order; }
196 c_[0] = c0;
c_[1] = c1;
199 c_[0] = c0;
c_[1] = c1;
c_[2] = c2;
202 c_[0] = c0;
c_[1] = c1;
c_[2] = c2;
c_[3] = c3;
205 c_[0] = c0;
c_[1] = c1;
c_[2] = c2;
c_[3] = c3;
c_[4] = c4;
209 c_[0] = c0;
c_[1] = c1;
c_[2] = c2;
c_[3] = c3;
c_[4] = c4;
214 c_[0] = c0;
c_[1] = c1;
c_[2] = c2;
c_[3] = c3;
c_[4] = c4;
215 c_[5] = c5;
c_[6] = c6;
219 c_[0] = c0;
c_[1] = c1;
c_[2] = c2;
c_[3] = c3;
c_[4] = c4;
220 c_[5] = c5;
c_[6] = c6;
c_[7] = c7;
224 c_[0] = c0;
c_[1] = c1;
c_[2] = c2;
c_[3] = c3;
c_[4] = c4;
225 c_[5] = c5;
c_[6] = c6;
c_[7] = c7;
c_[8] = c8;
229 c_[0] = c0;
c_[1] = c1;
c_[2] = c2;
c_[3] = c3;
c_[4] = c4;
230 c_[5] = c5;
c_[6] = c6;
c_[7] = c7;
c_[8] = c8;
c_[9] = c9;
233 template <
typename Iter>
235 c_.resize(std::distance(first, last));
236 for (std::size_t i = 0; first != last; ++first, ++i) {
255 for(
unsigned i = 0; i <=
order(); i++) {
256 if( !
are_near(
c_[i], 0., eps) )
return false;
261 for(
unsigned i = 1; i <=
order(); i++) {
267 for(
unsigned i = 0; i <=
order(); i++) {
268 if(!std::isfinite(
c_[i]))
return false;
295 std::vector<Coord>
roots()
const;
336Bezier
operator*(Bezier
const &f, Bezier
const &g);
344 for(
unsigned i = 0; i <= a.
order(); i++)
349Bezier
portion(
const Bezier & a,
double from,
double to);
353 std::vector<Point>
result;
354 for(
unsigned i = 0; i <= a[0].order(); i++) {
356 for(
unsigned d = 0; d < 2; d++) p[d] = a[d][i];
366OptInterval
bounds_local(Bezier
const &b, OptInterval
const &i);
372inline std::ostream &operator<< (std::ostream &os,
const Bezier & b) {
374 for(
unsigned i = 0; i < b.
order(); i++) {
372inline std::ostream &operator<< (std::ostream &os,
const Bezier & b) {
…}
Polynomial in Bernstein-Bezier basis.
Bezier & operator*=(double v)
void resize(unsigned int n, Coord v=0)
std::vector< Coord > valueAndDerivatives(Coord t, unsigned n_derivs) const
friend OptInterval bounds_fast(Bezier const &b)
Bezier elevate_to_degree(unsigned newDegree) const
void subdivide(Coord t, Bezier *left, Bezier *right) const
Bezier forward_difference(unsigned k) const
void find_bezier_roots(std::vector< double > &solutions, double l, double r) const
Bezier(Coord c0, Coord c1, Coord c2, Coord c3, Coord c4, Coord c5, Coord c6)
std::vector< Coord > roots() const
Coord const & operator[](unsigned ix) const
Bezier(std::vector< Coord > const &vec)
Bezier(Coord c0, Coord c1, Coord c2, Coord c3, Coord c4, Coord c5, Coord c6, Coord c7, Coord c8, Coord c9)
Bezier(Coord c0, Coord c1, Coord c2, Coord c3, Coord c4, Coord c5, Coord c6, Coord c7)
Bezier reduce_degree() const
friend Bezier derivative(const Bezier &a)
Coord operator()(double t) const
Bezier elevate_degree() const
bool operator!=(Bezier const &other) const
Bezier operator-() const
Unary minus.
Bezier(Coord c0, Coord c1)
Bezier(Coord c0, Coord c1, Coord c2, Coord c3)
bool isZero(double eps=EPSILON) const
Bezier & operator+=(double v)
Bezier & operator=(Bezier const &other)
std::valarray< Coord > c_
Bezier(Coord c0, Coord c1, Coord c2)
bool isConstant(double eps=EPSILON) const
Bezier & operator/=(double v)
Bezier(Coord const c[], unsigned ord)
Bezier(Coord c0, Coord c1, Coord c2, Coord c3, Coord c4, Coord c5, Coord c6, Coord c7, Coord c8)
Bezier(Coord c0, Coord c1, Coord c2, Coord c3, Coord c4, Coord c5)
Coord valueAt(double t) const
void setCoeff(unsigned ix, double val)
Bezier(Iter first, Iter last)
Bezier & operator-=(double v)
Coord & operator[](unsigned ix)
Bezier(Coord c0, Coord c1, Coord c2, Coord c3, Coord c4)
bool operator==(Bezier const &other) const
friend Bezier portion(const Bezier &a, Coord from, Coord to)
Adaptor that creates 2D functions from 1D ones.
Range of real numbers that is never empty.
Range of real numbers that can be empty.
Two-dimensional point that doubles as a vector.
Polynomial in symmetric power basis.
Integral and real coordinate types and some basic utilities.
Lifts one dimensional objects into 2D.
constexpr Coord lerp(Coord t, Coord a, Coord b)
Numerically stable linear interpolation.
double Coord
Floating point type used to store coordinates.
constexpr Coord EPSILON
Default "acceptably small" value.
Low level math functions and compatibility wrappers.
Various utility functions.
OptInterval bounds_exact(Bezier const &b)
Bezier reverse(const Bezier &a)
OptInterval bounds_local(Bezier const &b, OptInterval const &i)
T casteljau_subdivision(double t, T const *v, T *left, T *right, unsigned order)
Perform Casteljau subdivision of a Bezier polynomial.
std::vector< Point > bezier_points(const D2< Bezier > &a)
Bezier multiply(Bezier const &f, Bezier const &g)
Bezier operator*(Bezier const &f, Bezier const &g)
std::string format_coord_nice(Coord x)
Bezier portion(const Bezier &a, double from, double to)
Bezier integral(Bezier const &a)
Bezier derivative(Bezier const &a)
T bernstein_value_at(double t, T const *c_, unsigned n)
Compute the value of a Bernstein-Bezier polynomial.
OptInterval bounds_fast(Bezier const &b)
bool are_near(Affine const &a1, Affine const &a2, Coord eps=EPSILON)
void bezier_expand_to_image(Interval &range, Coord x0, Coord x1, Coord x2)
Expand an interval to the image of a Bézier-Bernstein polynomial, assuming it already contains the in...
SBasis bezier_to_sbasis(Coord const *handles, unsigned order)
std::vector< double > & solutions