34#ifndef LIB2GEOM_SEEN_SBASIS_H
35#define LIB2GEOM_SEEN_SBASIS_H
49#if defined(USE_SBASIS_OF)
53#elif defined(USE_SBASISN)
59class SBasis :
public SBasisN<1>;
71 std::vector<Linear>
d;
76 size_t size()
const {
return d.size();}
77 typedef std::vector<Linear>::iterator
iterator;
87 bool empty()
const {
return d.size() == 1 && d[0][0] == 0 && d[0][1] == 0; }
98 void resize(
unsigned n) { d.resize(std::max<unsigned>(n, 1));}
99 void resize(
unsigned n,
Linear const& l) { d.resize(std::max<unsigned>(n, 1), l);}
131 : d(1, bo ? *bo :
Linear(0, 0))
183 template <
typename Iter>
185 assert(std::distance(first, last) % 2 == 0);
186 assert(std::distance(first, last) >= 2);
187 for (; first != last; ++first) {
189 push_back(
Linear(*first, *last));
195 inline bool isZero(
double eps=EPSILON)
const {
197 for(
unsigned i = 0; i <
size(); i++) {
198 if(!(*
this)[i].isZero(eps))
return false;
204 if(!(*
this)[0].isConstant(eps))
return false;
205 for (
unsigned i = 1; i <
size(); i++) {
206 if(!(*
this)[i].isZero(eps))
return false;
211 bool isFinite()
const;
222 double p0 = 0, p1 = 0;
223 for(
unsigned k =
size(); k > 0; k--) {
224 const Linear &lin = (*this)[k-1];
228 return (1-t)*p0 + t*p1;
236 std::vector<double> valueAndDerivatives(
double t,
unsigned n)
const;
240 double tailError(
unsigned tail)
const;
248 while(
size() > 1 && back().isZero(0))
274 for(
unsigned k = 0; k < a.size(); k++)
281 if(p.isZero())
return SBasis();
284 for(
unsigned i = 0; i < p.size(); i++) {
332 if(a.isZero())
return Linear(b, b);
338 if(a.isZero())
return Linear(-b, -b);
363 c.
insert(
c.begin(), a.begin(), a.begin() + std::min(terms, (
unsigned)a.size()));
398 while( val<a.size() &&
399 fabs(a[val][0])<tol &&
400 fabs(a[val][1])<tol )
428inline std::ostream &operator<< (std::ostream &out_file,
const Linear &bo) {
429 out_file <<
"{" << bo[0] <<
", " << bo[1] <<
"}";
433inline std::ostream &operator<< (std::ostream &out_file,
const SBasis & p) {
434 for(
unsigned i = 0; i < p.size(); i++) {
438 out_file << p[i] <<
"s^" << i;
450 std::vector<double>
const &levels,
498 std::vector<double>
const &levels,
512 std::vector<Interval>
const &levels,
Defines the different types of exceptions that 2geom can throw.
Various utility functions.
Range of real numbers that is never empty.
SBasisOf< double > toSBasis() const
Function that interpolates linearly between two values.
Range of real numbers that can be empty.
double operator()(double t) const
Polynomial in symmetric power basis.
Linear & operator[](unsigned i)
const_iterator end() const
bool isZero(double eps=EPSILON) const
Linear const & back() const
void push_back(Linear const &l)
SBasis(Coord c0, Coord c1, Coord c2, Coord c3, Coord c4, Coord c5)
SBasis(size_t n, Linear const &l)
int degreesOfFreedom() const
void insert(iterator before, const_iterator src_begin, const_iterator src_end)
SBasis(double a, double b)
const_iterator begin() const
SBasis(Iter first, Iter last)
std::vector< Linear >::const_iterator const_iterator
SBasis(Coord c0, Coord c1, Coord c2, Coord c3)
SBasis(Coord c0, Coord c1, Coord c2, Coord c3, Coord c4, Coord c5, Coord c6, Coord c7)
unsigned valuation(SBasis const &a, double tol=0)
Returns the degree of the first non zero coefficient.
std::vector< Linear >::iterator iterator
void resize(unsigned n, Linear const &l)
SBasis(Coord c0, Coord c1, Coord c2, Coord c3, Coord c4, Coord c5, Coord c6, Coord c7, Coord c8, Coord c9)
SBasis portion(const SBasis &t, double from, double to)
Returns the sbasis on domain [0,1] that was t on [from, to].
double valueAt(double t) const
bool operator==(SBasis const &B) const
bool operator!=(SBasis const &B) const
SBasis reverse(SBasis const &a)
Returns a function which reverses the domain of a.
Linear operator[](unsigned i) const
SBasis(std::vector< Linear > ls)
bool isConstant(double eps=EPSILON) const
void truncate(unsigned k)
double operator()(double t) const
double Coord
Floating point type used to store coordinates.
Simple closed interval class.
Linear fragment function class.
Various utility functions.
SBasisN< n > cos(LinearN< n > bo, int k)
Geom::SBasisOf< double > SBasis
std::vector< std::vector< Interval > > level_sets(D2< SBasis > const &f, std::vector< Rect > regions)
OptInterval bounds_exact(Bezier const &b)
SBasisN< n > divide(SBasisN< n > const &a, SBasisN< n > const &b, int k)
OptInterval bounds_local(Bezier const &b, OptInterval const &i)
SBasisN< n > compose_inverse(SBasisN< n > const &f, SBasisN< n > const &g, unsigned order=2, double tol=1e-3)
SBasisN< n > inverse(SBasisN< n > a, int k)
Bezier multiply(Bezier const &f, Bezier const &g)
SBasisN< n > reciprocal(LinearN< n > const &a, int k)
D2< T > operator+=(D2< T > &a, D2< T > const &b)
D2< T > operator/(D2< T > const &a, Point const &b)
D2< T > operator-(D2< T > const &a, D2< T > const &b)
D2< T > operator*=(D2< T > &a, Point const &b)
SBasisN< n > sqrt(SBasisN< n > const &a, int k)
SBasisOf< T > shift(SBasisOf< T > const &a, int sh)
Bezier operator*(Bezier const &f, Bezier const &g)
D2< T > operator-=(D2< T > &a, D2< T > const &b)
D2< T > compose(D2< T > const &a, T const &b)
std::vector< double > roots(SBasis const &s)
SBasisOf< T > multiply_add(SBasisOf< T > const &a, SBasisOf< T > const &b, SBasisOf< T > c)
Bezier integral(Bezier const &a)
Bezier derivative(Bezier const &a)
D2< T > operator+(D2< T > const &a, D2< T > const &b)
std::vector< std::vector< double > > multi_roots(SBasis const &f, std::vector< double > const &levels, double htol=1e-7, double vtol=1e-7, double a=0, double b=1)
OptInterval bounds_fast(Bezier const &b)
SBasisN< n > sin(LinearN< n > bo, int k)
std::vector< Interval > level_set(D2< SBasis > const &f, Rect region)
D2< T > operator/=(D2< T > &a, Point const &b)
Defines S-power basis function class with coefficient in arbitrary ring.
Multi-dimensional symmetric power basis function.