summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: e8d86b8)
raw | patch | inline | side by side (parent: e8d86b8)
author | joncruz <joncruz@users.sourceforge.net> | |
Wed, 14 Oct 2009 07:18:26 +0000 (07:18 +0000) | ||
committer | joncruz <joncruz@users.sourceforge.net> | |
Wed, 14 Oct 2009 07:18:26 +0000 (07:18 +0000) |
src/2geom/bezier.h | patch | blob | history | |
src/2geom/d2.h | patch | blob | history |
diff --git a/src/2geom/bezier.h b/src/2geom/bezier.h
index 1fe846935eb21bb39acba881b9b14c134c76812a..9e68d93aec45fd1e798a576184c1c9ef5120485e 100644 (file)
--- a/src/2geom/bezier.h
+++ b/src/2geom/bezier.h
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.
*
*/
//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 afa00b40d2e3b5f00af3268682ba3181a21c756f..547d8c658717e136c6724ec7bace77ce0bda27a0 100644 (file)
--- a/src/2geom/d2.h
+++ b/src/2geom/d2.h
}
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;
}