diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2009-11-23 21:15:06 +0000 |
|---|---|---|
| committer | johanengelen <johanengelen@users.sourceforge.net> | 2009-11-23 21:15:06 +0000 |
| commit | b0a9bcb9e1da6e5192cf37aedcd3b87a4041b911 (patch) | |
| tree | b302be68624c043cb13d55f9f17d0eb993cf1acb /src | |
| parent | work on the lpe group undo bug. it's not solved, but i think LPE code does ev... (diff) | |
| download | inkscape-b0a9bcb9e1da6e5192cf37aedcd3b87a4041b911.tar.gz inkscape-b0a9bcb9e1da6e5192cf37aedcd3b87a4041b911.zip | |
update 2geom. needed for extrude lpe
(bzr r8840)
Diffstat (limited to 'src')
| -rw-r--r-- | src/2geom/d2-sbasis.cpp | 39 | ||||
| -rw-r--r-- | src/2geom/d2-sbasis.h | 1 | ||||
| -rw-r--r-- | src/2geom/d2.h | 21 | ||||
| -rw-r--r-- | src/2geom/piecewise.h | 9 |
4 files changed, 65 insertions, 5 deletions
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<D2<SBasis> > rot90(Piecewise<D2<SBasis> > const &M){ return result; } -Piecewise<SBasis> dot(Piecewise<D2<SBasis> > const &a, - Piecewise<D2<SBasis> > 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<SBasis> dot(Piecewise<D2<SBasis> > const &a, Piecewise<D2<SBasis> > const &b) +{ Piecewise<SBasis > result; if (a.empty() || b.empty()) return result; Piecewise<D2<SBasis> > aa = partition(a,b.cuts); @@ -72,6 +83,30 @@ Piecewise<SBasis> dot(Piecewise<D2<SBasis> > 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<SBasis> dot(Piecewise<D2<SBasis> > const &a, Point const &b) +{ + Piecewise<SBasis > 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<SBasis> cross(Piecewise<D2<SBasis> > const &a, Piecewise<D2<SBasis> > const &b){ Piecewise<SBasis > 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<D2<SBasis> > sectionize(D2<Piecewise<SBasis> > const &a); D2<Piecewise<SBasis> > make_cuts_independent(Piecewise<D2<SBasis> > const &a); Piecewise<D2<SBasis> > rot90(Piecewise<D2<SBasis> > const &a); Piecewise<SBasis> dot(Piecewise<D2<SBasis> > const &a, Piecewise<D2<SBasis> > const &b); +Piecewise<SBasis> dot(Piecewise<D2<SBasis> > const &a, Point const &b); Piecewise<SBasis> cross(Piecewise<D2<SBasis> > const &a, Piecewise<D2<SBasis> > const &b); Piecewise<D2<SBasis> > operator*(Piecewise<D2<SBasis> > 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<Coord> x = f[X].valueAndDerivatives(t, n), 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++) { + for(unsigned i = 0; i <= n; i++) { res[i] = Point(x[i], y[i]); } return res; @@ -321,6 +321,25 @@ dot(D2<T> const & a, D2<T> 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 <typename T> +inline T +dot(D2<T> const & a, Point const & b) { + boost::function_requires<AddableConcept<T> >(); + boost::function_requires<ScalableConcept<T> >(); + + 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 <typename T> inline T cross(D2<T> const & a, D2<T> 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<output_type> valueAndDerivatives(double t, unsigned n_derivs) const { unsigned n = segN(t); std::vector<output_type> 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<T> operator()(SBasis f); Piecewise<T> operator()(Piecewise<SBasis>f); @@ -773,10 +778,10 @@ Piecewise<T> reverse(Piecewise<T> 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<typename T> Piecewise<T> lerp(double t, Piecewise<T> const &a, Piecewise<T> b) { |
