79 else if (d>0) {
return 1;}
101 if(polyCount){free(polys);}
110 for( i=0 ; i<count ; i++ )
112 if( !c || sps[i].start!=polys[c-1].start ) polys[c++] = sps[i];
113 else{polys[c-1].
p+=sps[i].
p;}
117 template <
int Degree>
123 if(polyCount){free(polys);}
147 template<
int Degree2>
150 for(
int i=0;i<int(polyCount);i++){
151 polys[i].start=p.
polys[i].start;
152 polys[i].p=p.
polys[i].p;
161 for(
int i=0 ; i<int(polyCount) && t>polys[i].start ; i++ ) v+=polys[i].p(t);
169 double start,end,s,v=0;
177 for(
int i=0;i<int(polyCount) && polys[i].start<end;i++){
178 if(start<polys[i].start){s=polys[i].start;}
180 v+=polys[i].p.integral(s,end);
196 else if (i>=
int( polyCount)-1) {q.
polys[idx]=p.
polys[++j];}
197 else if(polys[i+1].start<p.
polys[j+1].start){q.
polys[idx]= polys[++i];}
213 else if (i>=
int( polyCount)-1) {q.
polys[idx].start=p.
polys[++j].start;q.
polys[idx].p=p.
polys[j].p*(-1.0);}
214 else if(polys[i+1].start<p.
polys[j+1].start){q.
polys[idx]= polys[++i];}
224 std::size_t idx=0,cnt=0,oldPolyCount=polyCount;
229 while(cnt<polyCount){
230 if (j>=
int( p.
polyCount)-1) {polys[idx]=oldPolys[++i];}
231 else if (i>=
int(oldPolyCount)-1) {polys[idx].
start= p.
polys[++j].start;polys[idx].p=p.
polys[j].p*scale;}
232 else if (oldPolys[i+1].start<p.
polys[j+1].start){polys[idx]=oldPolys[++i];}
233 else {polys[idx].
start= p.
polys[++j].start;polys[idx].p=p.
polys[j].p*scale;}
234 if(idx && polys[idx].start==polys[idx-1].start) {polys[idx-1].p+=polys[idx].p;}
243 template<
int Degree2>
247 int i,j,spCount=int(polyCount*p.
polyCount);
250 for(i=0;i<int(polyCount);i++){
260 template<
int Degree2>
264 for(
int i=0;i<int(polyCount);i++){
265 q.
polys[i].start=polys[i].start;
266 q.
polys[i].p=polys[i].p*p;
275 for(std::size_t i=0;i<polyCount;i++){q.
polys[i]=polys[i].scale(s);}
283 for(std::size_t i=0;i<polyCount;i++){q.
polys[i]=polys[i].shift(s);}
290 for(std::size_t i=0;i<polyCount;i++){
291 q.polys[i].
start=polys[i].start;
292 q.polys[i].p=polys[i].p.derivative();
301 for(i=0;i<int(polyCount);i++){
302 q.
polys[i].start=polys[i].start;
303 q.
polys[i].p=polys[i].p.integral();
315 for(
int i=0;i<int(polyCount);i++){polys[i].p*=s;}
321 for(std::size_t i=0;i<polyCount;i++){polys[i].p/=s;}
359 printf(
"[-Infinity,Infinity]\n");
362 for(std::size_t i=0;i<polyCount;i++){
364 if (polys[i ].start== DBL_MAX){printf(
"Infinity,");}
365 else if (polys[i ].start==-DBL_MAX){printf(
"-Infinity,");}
366 else {printf(
"%f,",polys[i].start);}
367 if(i+1==polyCount) {printf(
"Infinity]\t");}
368 else if (polys[i+1].start== DBL_MAX){printf(
"Infinity]\t");}
369 else if (polys[i+1].start==-DBL_MAX){printf(
"-Infinity]\t");}
370 else {printf(
"%f]\t",polys[i+1].start);}
383 q.
polys[0].start=-radius;
384 q.
polys[1].start= radius;
386 q.
polys[0].p.coefficients[0]= 1.0;
387 q.
polys[1].p.coefficients[0]=-1.0;
390 template<
int Degree >
404 for(
int i=0;i<int(polyCount);i++){
405 sps[2*i ].
start=polys[i].start-radius;
406 sps[2*i+1].
start=polys[i].start+radius;
407 p=polys[i].p.
integral()-polys[i].p.integral()(polys[i].start);
408 sps[2*i ].
p=p.
shift(-radius);
409 sps[2*i+1].
p=p.
shift( radius)*-1;
411 A.
set(sps,
int(polyCount*2));
413 return A*1.0/(2*radius);
418 std::vector<double> tempRoots;
421 for(std::size_t i=0;i<polyCount;i++){
423 if(polys[i].start>max){
break;}
424 if(i<polyCount-1 && polys[i+1].start<min){
continue;}
426 for(std::size_t j=0;j<tempRoots.size();j++){
427 if(tempRoots[j]>polys[i].start && (i+1==polyCount || tempRoots[j]<=polys[i+1].start)){
428 if(tempRoots[j]>min && tempRoots[j]<max){roots.push_back(tempRoots[j]);}
436 fwrite(&samples,
sizeof(
int),1,fp);
437 for(
int i=0;i<samples;i++){
438 double x=min+i*(max-min)/(samples-1);
440 fwrite(&v,
sizeof(
float),1,fp);
PPolynomial operator-(const PPolynomial &p) const
PPolynomial operator/(double s) const
StartingPolynomial< Degree > * polys
PPolynomial & operator-=(double s)
PPolynomial shift(double t) const
void getSolutions(double c, std::vector< double > &roots, double EPS, double min=-DBL_MAX, double max=DBL_MAX) const
PPolynomial & operator=(const PPolynomial &p)
double operator()(double t) const
PPolynomial & operator+=(double s)
PPolynomial & operator/=(double s)
PPolynomial & operator*=(double s)
void write(FILE *fp, int samples, double min, double max) const
void reset(std::size_t newSize)
PPolynomial operator+(const PPolynomial &p) const
PPolynomial scale(double s) const
PPolynomial< Degree+1 > integral(void) const
static PPolynomial BSpline(double radius=0.5)
PPolynomial< Degree+Degree2 > operator*(const Polynomial< Degree2 > &p) const
void set(std::size_t size)
PPolynomial & addScaled(const PPolynomial &poly, double scale)
PPolynomial< Degree-1 > derivative(void) const
PPolynomial< Degree+1 > MovingAverage(double radius)
double Integral(void) const
Polynomial shift(double t) const
void getSolutions(double c, std::vector< double > &roots, double EPS) const
double integral(double tMin, double tMax) const
StartingPolynomial shift(double t) const
StartingPolynomial< Degree+Degree2 > operator*(const StartingPolynomial< Degree2 > &p) const
StartingPolynomial scale(double s) const
int operator<(const StartingPolynomial &sp) const
static int Compare(const void *v1, const void *v2)