From: johanengelen Date: Mon, 23 Nov 2009 21:15:06 +0000 (+0000) Subject: update 2geom. needed for extrude lpe X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=7bec4f8084ba5b469390ba2b910f2146258eaff8;p=inkscape.git update 2geom. needed for extrude lpe --- diff --git a/src/2geom/d2-sbasis.cpp b/src/2geom/d2-sbasis.cpp index 2c52e4782..aef989fc7 100644 --- a/src/2geom/d2-sbasis.cpp +++ b/src/2geom/d2-sbasis.cpp @@ -58,8 +58,19 @@ Piecewise > rot90(Piecewise > const &M){ return result; } -Piecewise dot(Piecewise > const &a, - Piecewise > const &b){ +/** @brief Calculates the 'dot product' or 'inner product' of \c a and \c b + * @return \f[ + * f(t) \rightarrow \left\{ + * \begin{array}{c} + * a_1 \bullet b_1 \\ + * a_2 \bullet b_2 \\ + * \ldots \\ + * a_n \bullet b_n \\ + * \end{array}\right. + * \f] + * @relates Piecewise */ +Piecewise dot(Piecewise > const &a, Piecewise > const &b) +{ Piecewise result; if (a.empty() || b.empty()) return result; Piecewise > aa = partition(a,b.cuts); @@ -72,6 +83,30 @@ Piecewise dot(Piecewise > const &a, return result; } +/** @brief Calculates the 'dot product' or 'inner product' of \c a and \c b + * @return \f[ + * f(t) \rightarrow \left\{ + * \begin{array}{c} + * a_1 \bullet b \\ + * a_2 \bullet b \\ + * \ldots \\ + * a_n \bullet b \\ + * \end{array}\right. + * \f] + * @relates Piecewise */ +Piecewise dot(Piecewise > const &a, Point const &b) +{ + Piecewise result; + if (a.empty()) return result; + + result.push_cut(a.cuts.front()); + for (unsigned i = 0; i < a.size(); ++i){ + result.push(dot(a.segs[i],b), a.cuts[i+1]); + } + return result; +} + + Piecewise cross(Piecewise > const &a, Piecewise > const &b){ Piecewise result; diff --git a/src/2geom/d2-sbasis.h b/src/2geom/d2-sbasis.h index c61052da7..d404e0618 100644 --- a/src/2geom/d2-sbasis.h +++ b/src/2geom/d2-sbasis.h @@ -73,6 +73,7 @@ Piecewise > sectionize(D2 > const &a); D2 > make_cuts_independent(Piecewise > const &a); Piecewise > rot90(Piecewise > const &a); Piecewise dot(Piecewise > const &a, Piecewise > const &b); +Piecewise dot(Piecewise > const &a, Point const &b); Piecewise cross(Piecewise > const &a, Piecewise > const &b); Piecewise > operator*(Piecewise > const &a, Matrix const &m); diff --git a/src/2geom/d2.h b/src/2geom/d2.h index 547d8c658..b2a0f8866 100644 --- a/src/2geom/d2.h +++ b/src/2geom/d2.h @@ -99,7 +99,7 @@ class D2{ std::vector x = f[X].valueAndDerivatives(t, n), y = f[Y].valueAndDerivatives(t, n); // always returns a vector of size n+1 std::vector res(n+1); - for (unsigned i = 0; i <= n; i++) { + for(unsigned i = 0; i <= n; i++) { res[i] = Point(x[i], y[i]); } return res; @@ -321,6 +321,25 @@ dot(D2 const & a, D2 const & b) { return r; } +/** @brief Calculates the 'dot product' or 'inner product' of \c a and \c b + * @return \f$a \bullet b = a_X b_X + a_Y b_Y\f$. + * @relates D2 */ +template +inline T +dot(D2 const & a, Point const & b) { + boost::function_requires >(); + boost::function_requires >(); + + T r; + for(unsigned i = 0; i < 2; i++) { + r += a[i] * b[i]; + } + return r; +} + +/** @brief Calculates the 'cross product' or 'outer product' of \c a and \c b + * @return \f$a \times b = a_Y b_X - a_X b_Y\f$. + * @relates D2 */ template inline T cross(D2 const & a, D2 const & b) { diff --git a/src/2geom/piecewise.h b/src/2geom/piecewise.h index a5be42587..a0628daf1 100644 --- a/src/2geom/piecewise.h +++ b/src/2geom/piecewise.h @@ -58,7 +58,7 @@ namespace Geom { * \begin{array}{cc} * s_1,& t <= c_2 \\ * s_2,& c_2 <= t <= c_3\\ - * \ldots + * \ldots \\ * s_n,& c_n <= t * \end{array}\right. * \f] @@ -105,6 +105,10 @@ class Piecewise { inline output_type lastValue() const { return valueAt(cuts.back()); } + + /** + * The size of the returned vector equals n_derivs+1. + */ std::vector valueAndDerivatives(double t, unsigned n_derivs) const { unsigned n = segN(t); std::vector ret, val = segs[n].valueAndDerivatives(segT(t, n), n_derivs); @@ -115,6 +119,7 @@ class Piecewise { } return ret; } + //TODO: maybe it is not a good idea to have this? Piecewise operator()(SBasis f); Piecewise operator()(Piecewisef); @@ -773,10 +778,10 @@ Piecewise reverse(Piecewise const &f) { return ret; } - /** * Interpolates between a and b. * \return a if t = 0, b if t = 1, or an interpolation between a and b for t in [0,1] + * \relates Piecewise */ template Piecewise lerp(double t, Piecewise const &a, Piecewise b) {