diff options
| author | Jon A. Cruz <jon@joncruz.org> | 2009-10-14 07:18:26 +0000 |
|---|---|---|
| committer | joncruz <joncruz@users.sourceforge.net> | 2009-10-14 07:18:26 +0000 |
| commit | da507beea868c07d95b2065bfeac2950393c15a7 (patch) | |
| tree | a9831f2b7704ab752c7f88d6a0cdecf7a52f3fa3 /src | |
| parent | Swedish translation update by elias. (diff) | |
| download | inkscape-da507beea868c07d95b2065bfeac2950393c15a7.tar.gz inkscape-da507beea868c07d95b2065bfeac2950393c15a7.zip | |
Applying second patch for bug #425557.
(bzr r8768)
Diffstat (limited to 'src')
| -rw-r--r-- | src/2geom/bezier.h | 33 | ||||
| -rw-r--r-- | src/2geom/d2.h | 8 |
2 files changed, 25 insertions, 16 deletions
diff --git a/src/2geom/bezier.h b/src/2geom/bezier.h index 1fe846935..9e68d93ae 100644 --- a/src/2geom/bezier.h +++ b/src/2geom/bezier.h @@ -46,7 +46,7 @@ namespace Geom { inline Coord subdivideArr(Coord t, Coord const *v, Coord *left, Coord *right, unsigned order) { /* * Bernstein : - * Evaluate a Bernstein function at a particular parameter value + * Evaluate a Bernstein function at a particular parameter value * Fill in control points for resulting sub-curves. * */ @@ -236,25 +236,34 @@ public: //inline Coord const &operator[](unsigned ix) const { return c_[ix]; } inline void setPoint(unsigned ix, double val) { c_[ix] = val; } - /* This is inelegant, as it uses several extra stores. I think there might be a way to - * evaluate roughly in situ. */ - + /** + * The size of the returned vector equals n_derivs+1. + */ std::vector<Coord> valueAndDerivatives(Coord t, unsigned n_derivs) const { - std::vector<Coord> val_n_der; + /* This is inelegant, as it uses several extra stores. I think there might be a way to + * evaluate roughly in situ. */ + + // initialize return vector with zeroes, such that we only need to replace the non-zero derivs + std::vector<Coord> val_n_der(n_derivs + 1, Coord(0.0)); + + // initialize temp storage variables std::valarray<Coord> d_(order()+1); - unsigned nn = n_derivs + 1; // the size of the result vector equals n_derivs+1 ... - if(nn > order()) - nn = order()+1; // .. but with a maximum of order() + 1! - for(unsigned i = 0; i < size(); i++) + for (unsigned i = 0; i < size(); i++) { d_[i] = c_[i]; - val_n_der.resize(nn); - for(unsigned di = 0; di < nn; di++) { + } + + unsigned nn = n_derivs + 1; + if(n_derivs > order()) { + nn = order()+1; // only calculate the non zero derivs + } + for (unsigned di = 0; di < nn; di++) { //val_n_der[di] = (subdivideArr(t, &d_[0], NULL, NULL, order() - di)); val_n_der[di] = bernsteinValueAt(t, &d_[0], order() - di); - for(unsigned i = 0; i < order() - di; i++) { + for (unsigned i = 0; i < order() - di; i++) { d_[i] = (order()-di)*(d_[i+1] - d_[i]); } } + return val_n_der; } diff --git a/src/2geom/d2.h b/src/2geom/d2.h index afa00b40d..547d8c658 100644 --- a/src/2geom/d2.h +++ b/src/2geom/d2.h @@ -97,10 +97,10 @@ class D2{ } std::vector<Point > valueAndDerivatives(double t, unsigned n) const { std::vector<Coord> x = f[X].valueAndDerivatives(t, n), - y = f[Y].valueAndDerivatives(t, n); - std::vector<Point> res; - for(unsigned i = 0; i <= n; i++) { - res.push_back(Point(x[i], y[i])); + y = f[Y].valueAndDerivatives(t, n); // always returns a vector of size n+1 + std::vector<Point> res(n+1); + for (unsigned i = 0; i <= n; i++) { + res[i] = Point(x[i], y[i]); } return res; } |
