#include <sbasis.h>

List of all members.

Public Types

typedef double output_type

Public Member Functions

size_t size () const
Linear operator[] (unsigned i) const
Linearoperator[] (unsigned i)
Linear const * begin () const
Linear const * end () const
Linearbegin ()
Linearend ()
bool empty () const
Linearback ()
Linear const & back () const
void pop_back ()
void resize (unsigned n)
void resize (unsigned n, Linear const &l)
void reserve (unsigned n)
void clear ()
void insert (Linear *before, const Linear *src_begin, const Linear *src_end)
Linearat (unsigned i)
bool operator== (SBasis const &B) const
bool operator!= (SBasis const &B) const
 operator std::vector< Linear > ()
 SBasis ()
 SBasis (double a)
 SBasis (double a, double b)
 SBasis (SBasis const &a)
 SBasis (Linear const &bo)
 SBasis (Linear *bo)
 SBasis (size_t n, Linear const &l)
bool isZero () const
bool isConstant () const
bool isFinite () const
 test all coefficients are finite
double at0 () const
double at1 () const
int degreesOfFreedom () const
double valueAt (double t) const
double operator() (double t) const
std::vector< doublevalueAndDerivatives (double t, unsigned n) const
 Compute the value and the first n derivatives.
SBasis toSBasis () const
double tailError (unsigned tail) const
 bound the error from term truncation
SBasis operator() (SBasis const &g) const
void normalize ()
void truncate (unsigned k)

Private Member Functions

void push_back (Linear const &l)
void derive ()
 Compute the derivative of this inplace (Exact).

Private Attributes

std::vector< Lineard

Detailed Description

Definition at line 67 of file sbasis.h.


Member Typedef Documentation

Definition at line 118 of file sbasis.h.


Constructor & Destructor Documentation

Geom::SBasis::SBasis (  )  [inline]

Definition at line 99 of file sbasis.h.

{}

Geom::SBasis::SBasis ( double  a  )  [inline, explicit]

Definition at line 100 of file sbasis.h.

                              {
        push_back(Linear(a,a));
    }

Geom::SBasis::SBasis ( double  a,
double  b 
) [inline, explicit]

Definition at line 103 of file sbasis.h.

                                        {
        push_back(Linear(a,b));
    }

Geom::SBasis::SBasis ( SBasis const &  a  )  [inline]

Definition at line 106 of file sbasis.h.

                             :
        d(a.d)
    {}

Geom::SBasis::SBasis ( Linear const &  bo  )  [inline]

Definition at line 109 of file sbasis.h.

                              {
        push_back(bo);
    }

Geom::SBasis::SBasis ( Linear bo  )  [inline]

Definition at line 112 of file sbasis.h.

                       {
        push_back(*bo);
    }

Geom::SBasis::SBasis ( size_t  n,
Linear const &  l 
) [inline, explicit]

Definition at line 115 of file sbasis.h.

: d(n, l) {}


Member Function Documentation

Linear& Geom::SBasis::at ( unsigned  i  )  [inline]

Definition at line 92 of file sbasis.h.

References d.

Referenced by Geom::unitVector().

{ return d.at(i);}

double Geom::SBasis::at0 (  )  const [inline]

Definition at line 135 of file sbasis.h.

Referenced by Geom::arc_length_parametrization(), Geom::centroid(), and Geom::sqrt_internal().

                              { 
        if(empty()) return 0; else return (*this)[0][0];
    }

double Geom::SBasis::at1 (  )  const [inline]

Definition at line 138 of file sbasis.h.

Referenced by Geom::arc_length_parametrization(), Geom::centroid(), and Geom::sqrt_internal().

                             {
        if(empty()) return 0; else return (*this)[0][1];
    }

Linear& Geom::SBasis::back (  )  [inline]

Definition at line 83 of file sbasis.h.

References d.

{return d.back();}

Linear const& Geom::SBasis::back (  )  const [inline]

Definition at line 84 of file sbasis.h.

References d.

{return d.back();}

Linear const* Geom::SBasis::begin (  )  const [inline]

Definition at line 78 of file sbasis.h.

References d.

Referenced by divide_by_sk().

{ return (Linear const*)&*d.begin();}

Linear* Geom::SBasis::begin (  )  [inline]

Definition at line 80 of file sbasis.h.

References d.

{ return (Linear*)&*d.begin();}

void Geom::SBasis::clear (  )  [inline]

Definition at line 89 of file sbasis.h.

References d.

Referenced by Geom::bezier_to_sbasis(), and Geom::NL::LFMSBasis::instance().

{d.clear();}

int Geom::SBasis::degreesOfFreedom (  )  const [inline]

Definition at line 142 of file sbasis.h.

{ return size()*2;}

void Geom::SBasis::derive (  )  [private]

Compute the derivative of this inplace (Exact).

Definition at line 345 of file sbasis.cpp.

References isZero(), pop_back(), and size().

Referenced by valueAndDerivatives().

                    { // in place version
    if(isZero()) return;
    for(unsigned k = 0; k < size()-1; k++) {
        double d = (2*k+1)*((*this)[k][1] - (*this)[k][0]);
        
        (*this)[k][0] = d + (k+1)*(*this)[k+1][0];
        (*this)[k][1] = d - (k+1)*(*this)[k+1][1];
    }
    int k = size()-1;
    double d = (2*k+1)*((*this)[k][1] - (*this)[k][0]);
    if(d == 0)
        pop_back();
    else {
        (*this)[k][0] = d;
        (*this)[k][1] = d;
    }
}

bool Geom::SBasis::empty (  )  const [inline]

Definition at line 82 of file sbasis.h.

References d.

Referenced by Geom::force_continuity().

{return d.empty();}

Linear* Geom::SBasis::end (  )  [inline]

Definition at line 81 of file sbasis.h.

References d.

{ return (Linear*)&*d.end();}

Linear const* Geom::SBasis::end (  )  const [inline]

Definition at line 79 of file sbasis.h.

References d.

Referenced by divide_by_sk().

{ return (Linear const*)&*d.end();}

void Geom::SBasis::insert ( Linear before,
const Linear src_begin,
const Linear src_end 
) [inline]

Definition at line 90 of file sbasis.h.

References d.

Referenced by divide_by_sk().

{ d.insert(std::vector<Linear>::iterator(before), src_begin, src_end);}

bool Geom::SBasis::isConstant (  )  const [inline]

Definition at line 126 of file sbasis.h.

References Barcode::Code39Ext::i.

                                   {
        if (empty()) return true;
        for (unsigned i = 0; i < size(); i++) {
            if(!(*this)[i].isConstant()) return false;
        }
        return true;
    }

bool Geom::SBasis::isFinite (  )  const

test all coefficients are finite

Definition at line 52 of file sbasis.cpp.

References Barcode::Code39Ext::i, and size().

                            {
    for(unsigned i = 0; i < size(); i++) {
        if(!(*this)[i].isFinite())
            return false;
    }
    return true;
}

bool Geom::SBasis::isZero (  )  const [inline]

Definition at line 119 of file sbasis.h.

References Barcode::Code39Ext::i.

Referenced by Geom::compose(), derive(), and Geom::sqrt_internal().

                               {
        if(empty()) return true;
        for(unsigned i = 0; i < size(); i++) {
            if(!(*this)[i].isZero()) return false;
        }
        return true;
    }

void Geom::SBasis::normalize (  )  [inline]

Definition at line 171 of file sbasis.h.

                     {
        while(!empty() && 0 == back()[0] && 0 == back()[1])
            pop_back();
    }

Geom::SBasis::operator std::vector< Linear > (  )  [inline]

Definition at line 96 of file sbasis.h.

References d.

{ return d;}

bool Geom::SBasis::operator!= ( SBasis const &  B  )  const [inline]

Definition at line 95 of file sbasis.h.

References d.

{ return d != B.d;}

SBasis Geom::SBasis::operator() ( SBasis const &  g  )  const [inline]

Definition at line 346 of file sbasis.h.

References Geom::compose().

                                         {
    return compose(*this, g);
}

double Geom::SBasis::operator() ( double  t  )  const [inline]

Definition at line 156 of file sbasis.h.

                                      {
        return valueAt(t);
    }

bool Geom::SBasis::operator== ( SBasis const &  B  )  const [inline]

Definition at line 94 of file sbasis.h.

References d.

{ return d == B.d;}

Linear& Geom::SBasis::operator[] ( unsigned  i  )  [inline]

Definition at line 77 of file sbasis.h.

References d.

{ return d.at(i); }

Linear Geom::SBasis::operator[] ( unsigned  i  )  const [inline]

Definition at line 74 of file sbasis.h.

References d.

                                        {
        return d[i];
    }

void Geom::SBasis::pop_back (  )  [inline]

Definition at line 85 of file sbasis.h.

References d.

Referenced by derive().

{ d.pop_back();}

void Geom::SBasis::push_back ( Linear const &  l  )  [inline, private]

Definition at line 69 of file sbasis.h.

References d.

Referenced by Geom::cheb(), and Geom::subdiv_sbasis().

{ d.push_back(l); }

void Geom::SBasis::reserve ( unsigned  n  )  [inline]

Definition at line 88 of file sbasis.h.

References d.

{ d.reserve(n);}

void Geom::SBasis::resize ( unsigned  n,
Linear const &  l 
) [inline]

Definition at line 87 of file sbasis.h.

References d.

{ d.resize(n, l);}

void Geom::SBasis::resize ( unsigned  n  )  [inline]

Definition at line 86 of file sbasis.h.

References d.

Referenced by Geom::bezier_to_sbasis(), Geom::NL::LFMSBasis::instance(), and Geom::sqrt_internal().

{ d.resize(n);}

size_t Geom::SBasis::size (  )  const [inline]

Definition at line 73 of file sbasis.h.

References d.

Referenced by derive(), divide_by_sk(), isFinite(), Geom::multi_roots_internal(), Geom::sqrt_internal(), and Geom::unitVector().

{return d.size();}

double Geom::SBasis::tailError ( unsigned  tail  )  const

bound the error from term truncation

Parameters:
tail first term to chop
Returns:
the largest possible error this truncation could give

Definition at line 45 of file sbasis.cpp.

References Geom::bounds_fast(), Geom::Interval::max(), Geom::max(), and Geom::Interval::min().

Referenced by Geom::sqrt_internal(), Geom::subdiv_sbasis(), and Geom::unitVector().

                                            {
  Interval bs = *bounds_fast(*this, tail);
  return std::max(fabs(bs.min()),fabs(bs.max()));
}

SBasis Geom::SBasis::toSBasis (  )  const [inline]

Definition at line 162 of file sbasis.h.

{ return SBasis(*this); }

void Geom::SBasis::truncate ( unsigned  k  )  [inline]

Definition at line 176 of file sbasis.h.

Referenced by Geom::sqrt_internal().

{ if(k < size()) resize(k); }

std::vector< double > Geom::SBasis::valueAndDerivatives ( double  t,
unsigned  n 
) const

Compute the value and the first n derivatives.

Parameters:
t position to evaluate
n number of derivatives (not counting value)
Returns:
a vector with the value and the n derivative evaluations

There is an elegant way to compute the value and n derivatives for a polynomial using a variant of horner's rule. Someone will someday work out how for sbasis.

Definition at line 67 of file sbasis.cpp.

References derive(), Barcode::Code39Ext::i, and valueAt().

                                                                        {
    std::vector<double> ret(n+1);
    ret[0] = valueAt(t);
    SBasis tmp = *this;
    for(unsigned i = 1; i < n+1; i++) {
        tmp.derive();
        ret[i] = tmp.valueAt(t);
    }
    return ret;
}

double Geom::SBasis::valueAt ( double  t  )  const [inline]

Definition at line 144 of file sbasis.h.

Referenced by valueAndDerivatives().

                                   {
        double s = t*(1-t);
        double p0 = 0, p1 = 0;
        for(unsigned k = size(); k > 0; k--) {
            const Linear &lin = (*this)[k-1];
            p0 = p0*s + lin[0];
            p1 = p1*s + lin[1];
        }
        return (1-t)*p0 + t*p1;
    }


Member Data Documentation


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