36#ifndef SEEN_SBASIS_OF_H
37#define SEEN_SBASIS_OF_H
59class SBasisOf :
public std::vector<LinearOf<T> >{
79 if(this->empty())
return true;
80 for(
unsigned i = 0; i < this->
size(); i++) {
81 if(!(*
this)[i].isZero())
return false;
86 if (this->empty())
return true;
87 for (
unsigned i = 0; i < this->
size(); i++) {
88 if(!(*
this)[i].isConstant())
return false;
96 inline T
at0()
const {
97 if(this->empty())
return T(0);
else return (*
this)[0][0];
100 if(this->empty())
return T(0);
else return (*
this)[0][1];
105 T p0 = T(0.), p1 = T(0.);
106 for(
unsigned k = this->
size(); k > 0; k--) {
111 return p0*(1-t) + p1*t;
122 std::vector<T> ret(n+1);
125 for(
unsigned i = 0; i < n; i++) {
136 return std::max(fabs(
bs.min()),fabs(
bs.max()));
143 assert(i < this->
size());
144 return std::vector<LinearOf<T> >::operator[](i);
152 while(!this->empty() && this->back().
isZero())
175 std::vector<double>
const &levels,
192 for(
unsigned k = 0; k < a.size(); k++)
204 for(
unsigned i = 0; i < p.size(); i++) {
215 for(
unsigned i = 0; i < a.size(); i++)
216 c.push_back(a[i] * k);
230 for(
unsigned i = 0; i < a.size(); i++)
268 const unsigned out_size = std::max(a.size(), b.size());
269 const unsigned min_size = std::min(a.size(), b.size());
273 for(
unsigned i = 0; i < min_size; i++) {
274 result.push_back(a[i] + b[i]);
276 for(
unsigned i = min_size; i < a.size(); i++)
278 for(
unsigned i = min_size; i < b.size(); i++)
281 assert(
result.size() == out_size);
288 const unsigned out_size = std::max(a.size(), b.size());
289 const unsigned min_size = std::min(a.size(), b.size());
293 for(
unsigned i = 0; i < min_size; i++) {
294 result.push_back(a[i] - b[i]);
296 for(
unsigned i = min_size; i < a.size(); i++)
298 for(
unsigned i = min_size; i < b.size(); i++)
301 assert(
result.size() == out_size);
307 const unsigned out_size = std::max(a.size(), b.size());
308 const unsigned min_size = std::min(a.size(), b.size());
311 for(
unsigned i = 0; i < min_size; i++)
313 for(
unsigned i = min_size; i < b.size(); i++)
316 assert(a.size() == out_size);
322 const unsigned out_size = std::max(a.size(), b.size());
323 const unsigned min_size = std::min(a.size(), b.size());
326 for(
unsigned i = 0; i < min_size; i++)
328 for(
unsigned i = min_size; i < b.size(); i++)
331 assert(a.size() == out_size);
458 c.insert(
c.begin(), a.begin(), a.begin() + std::min(terms, (
unsigned)a.size()));
466 c.resize(a.size() + b.size(),
LinearOf<T>(T(0.),T(0.)));
467 for(
unsigned j = 0; j < b.size(); j++) {
468 for(
unsigned i = j; i < a.size()+j; i++) {
469 T tri = (b[j][1]-b[j][0])*(a[i-j][1]-a[i-j][0]);
473 for(
unsigned j = 0; j < b.size(); j++) {
474 for(
unsigned i = j; i < a.size()+j; i++) {
475 for(
unsigned dim = 0; dim < 2; dim++)
476 c[i][dim] += b[j][dim]*a[i-j][dim];
496 for(
int k =
c.size()-1; k >= 0; k--) {
497 aTri = (
HatOf<T>(
c[k]).
d + (k+1)*aTri/2)/(2*k+1);
512 for(
unsigned k = 0; k < a.size()-1; k++) {
513 T d = (2*k+1)*(a[k][1] - a[k][0]);
515 c[k][0] = d + (k+1)*a[k+1][0];
516 c[k][1] = d - (k+1)*a[k+1][1];
519 T d = (2*k+1)*(a[k][1] - a[k][0]);
534 for(
unsigned k = 0; k < this->
size()-1; k++) {
535 T d = (2*k+1)*((*
this)[k][1] - (*this)[k][0]);
537 (*this)[k][0] = d + (k+1)*(*
this)[k+1][0];
538 (*this)[k][1] = d - (k+1)*(*
this)[k+1][1];
540 int k = this->
size()-1;
541 T d = (2*k+1)*((*
this)[k][1] - (*this)[k][0]);
569 for(
int i = a.size()-1; i >= 0; i--) {
580 for(
int i = a.size()-1; i >= 0; i--) {
612inline std::ostream &operator<< (std::ostream &out_file,
const LinearOf<T> &bo) {
613 out_file <<
"{" << bo[0] <<
", " << bo[1] <<
"}";
618inline std::ostream &operator<< (std::ostream &out_file,
const SBasisOf<T> & p) {
619 for(
unsigned i = 0; i < p.size(); i++) {
620 out_file << p[i] <<
"s^" << i <<
" + ";
Defines the different types of exceptions that 2geom can throw.
Various utility functions.
Range of real numbers that is never empty.
SBasisOf< T > toSBasis() const
Range of real numbers that can be empty.
SBasisOf< T > toSBasis() const
T valueAt(double t) const
SBasisOf< T > operator()(SBasisOf< T > const &g) const
SBasisOf(SBasisOf< T > const &a)
LinearOf< T > operator[](unsigned i) const
LinearOf< T > & operator[](unsigned i)
double tailError(unsigned tail) const
SBasisOf(LinearOf< T > *bo)
T operator()(double t) const
void truncate(unsigned k)
SBasisOf(LinearOf< T > const &bo)
std::vector< T > valueAndDerivatives(double t, unsigned n) const
The size of the returned vector equals n+1.
Polynomial in symmetric power basis.
Simple closed interval class.
Linear fragment function class.
Various utility functions.
OptInterval bounds_exact(Bezier const &b)
Bezier reverse(const Bezier &a)
OptInterval bounds_local(Bezier const &b, OptInterval const &i)
Bezier multiply(Bezier const &f, Bezier const &g)
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)
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)
Bezier portion(const Bezier &a, double from, double to)
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)
D2< SBasis > truncate(D2< SBasis > const &a, unsigned terms)
OptInterval bounds_fast(Bezier const &b)
D2< T > operator/=(D2< T > &a, Point const &b)