summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: f0adf27)
raw | patch | inline | side by side (parent: f0adf27)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Mon, 23 Nov 2009 21:15:06 +0000 (21:15 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Mon, 23 Nov 2009 21:15:06 +0000 (21:15 +0000) |
src/2geom/d2-sbasis.cpp | patch | blob | history | |
src/2geom/d2-sbasis.h | patch | blob | history | |
src/2geom/d2.h | patch | blob | history | |
src/2geom/piecewise.h | patch | blob | history |
index 2c52e4782908d282dc16585f1267ca92ba78c388..aef989fc7a25b7a38fcb43f0f4115e7a186af38a 100644 (file)
--- a/src/2geom/d2-sbasis.cpp
+++ b/src/2geom/d2-sbasis.cpp
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);
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 c61052da71689af952349f592e4eea84af1b58b2..d404e061837da864654465c5b96db2fecaeeb59e 100644 (file)
--- a/src/2geom/d2-sbasis.h
+++ b/src/2geom/d2-sbasis.h
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 547d8c658717e136c6724ec7bace77ce0bda27a0..b2a0f886694ef36658efbffa1e5e98bada92b87e 100644 (file)
--- a/src/2geom/d2.h
+++ b/src/2geom/d2.h
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;
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 a5be42587c0be602eb02c28677769e14943bfed7..a0628daf1347f18569d4450dc93dcab5c329abb0 100644 (file)
--- a/src/2geom/piecewise.h
+++ b/src/2geom/piecewise.h
* \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]
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);
}
return ret;
}
+
//TODO: maybe it is not a good idea to have this?
Piecewise<T> operator()(SBasis f);
Piecewise<T> operator()(Piecewise<SBasis>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) {