diff options
| author | Krzysztof Kosi??ski <tweenk.pl@gmail.com> | 2011-02-05 01:06:18 +0000 |
|---|---|---|
| committer | Krzysztof KosiĆski <tweenk.pl@gmail.com> | 2011-02-05 01:06:18 +0000 |
| commit | f6809cd36481d5e20de106c23e3db527b026b417 (patch) | |
| tree | 2c44b8e15ce76314a357d7098a5c2039e336a201 /src/2geom | |
| parent | temporary work around 2geom matrix bug to make inkscape more usable (diff) | |
| download | inkscape-f6809cd36481d5e20de106c23e3db527b026b417.tar.gz inkscape-f6809cd36481d5e20de106c23e3db527b026b417.zip | |
Properly fix seltrans brokenness in 2Geom and pull updated files
into Inkscape
(bzr r10034)
Diffstat (limited to 'src/2geom')
| -rw-r--r-- | src/2geom/affine.h | 15 | ||||
| -rw-r--r-- | src/2geom/point.cpp | 14 | ||||
| -rw-r--r-- | src/2geom/point.h | 13 | ||||
| -rw-r--r-- | src/2geom/transforms.cpp | 4 | ||||
| -rw-r--r-- | src/2geom/transforms.h | 3 | ||||
| -rw-r--r-- | src/2geom/utils.h | 17 |
6 files changed, 42 insertions, 24 deletions
diff --git a/src/2geom/affine.h b/src/2geom/affine.h index 9a6352f8b..277d8b4ee 100644 --- a/src/2geom/affine.h +++ b/src/2geom/affine.h @@ -16,6 +16,7 @@ #include <boost/operators.hpp> #include <2geom/forward.h> #include <2geom/point.h> +#include <2geom/utils.h> namespace Geom { @@ -57,15 +58,13 @@ namespace Geom { */ class Affine : boost::equality_comparable< Affine // generates operator!= from operator== - , boost::multipliable< Affine - , boost::multipliable< Affine, Translate - , boost::multipliable< Affine, Scale - , boost::multipliable< Affine, Rotate - , boost::multipliable< Affine, HShear - , boost::multipliable< Affine, VShear + , boost::multipliable1< Affine + , MultipliableNoncommutative< Affine, Translate + , MultipliableNoncommutative< Affine, Scale + , MultipliableNoncommutative< Affine, Rotate + , MultipliableNoncommutative< Affine, HShear + , MultipliableNoncommutative< Affine, VShear > > > > > > > - // boost::multipliable< A, B > generates operator*(A const &, B const &) - // and operator*(B const &, A const &) from A::operator*=(B const &) { Coord _c[6]; public: diff --git a/src/2geom/point.cpp b/src/2geom/point.cpp index 9df88df92..a9005ef61 100644 --- a/src/2geom/point.cpp +++ b/src/2geom/point.cpp @@ -146,8 +146,8 @@ Point unit_vector(Point const &a) } /** @brief Return the "absolute value" of the point's vector. * This is defined in terms of the default lexicographical ordering. If the point is "larger" - * that the origin (0, 0), its negation is returned. This corresponds to making the Y coordinate - * positive. You can check whether the points' vectors have the same direction (e.g. lie + * that the origin (0, 0), its negation is returned. You can check whether + * the points' vectors have the same direction (e.g. lie * on the same line passing through the origin) using * @code abs(a).normalize() == abs(b).normalize() @endcode. * To check with some margin of error, use @@ -158,8 +158,14 @@ Point unit_vector(Point const &a) * @relates Point */ Point abs(Point const &b) { - Point ret = b; - ret[Y] = fabs(ret[Y]); + Point ret; + if (b[Y] < 0.0) { + ret = -b; + } else if (b[Y] == 0.0) { + ret = b[X] < 0.0 ? -b : b; + } else { + ret = b; + } return ret; } diff --git a/src/2geom/point.h b/src/2geom/point.h index 97f5142e3..3c6e12eff 100644 --- a/src/2geom/point.h +++ b/src/2geom/point.h @@ -44,6 +44,7 @@ #include <2geom/coord.h> #include <2geom/isnan.h> //temporary fix for isnan() #include <2geom/math-utils.h> +#include <2geom/utils.h> namespace Geom { @@ -51,12 +52,12 @@ class Point : boost::additive< Point , boost::totally_ordered< Point , boost::multiplicative< Point, Coord - , boost::multiplicative< Point, Affine - , boost::multiplicative< Point, Translate - , boost::multiplicative< Point, Rotate - , boost::multiplicative< Point, Scale - , boost::multiplicative< Point, HShear - , boost::multiplicative< Point, VShear + , MultipliableNoncommutative< Point, Affine + , MultipliableNoncommutative< Point, Translate + , MultipliableNoncommutative< Point, Rotate + , MultipliableNoncommutative< Point, Scale + , MultipliableNoncommutative< Point, HShear + , MultipliableNoncommutative< Point, VShear > > > > > > > > > // this uses chaining so it looks weird, but works { Coord _pt[2]; diff --git a/src/2geom/transforms.cpp b/src/2geom/transforms.cpp index 2658719c4..3a1866c13 100644 --- a/src/2geom/transforms.cpp +++ b/src/2geom/transforms.cpp @@ -60,12 +60,12 @@ Point &Point::operator*=(Rotate const &r) } Point &Point::operator*=(HShear const &h) { - _pt[X] += h.f * _pt[X]; + _pt[X] += h.f * _pt[Y]; return *this; } Point &Point::operator*=(VShear const &v) { - _pt[Y] += v.f * _pt[Y]; + _pt[Y] += v.f * _pt[X]; return *this; } diff --git a/src/2geom/transforms.h b/src/2geom/transforms.h index b8db82f14..1c965eb9f 100644 --- a/src/2geom/transforms.h +++ b/src/2geom/transforms.h @@ -56,12 +56,9 @@ struct TransformConcept { m = t * m; p *= t; p = p * t; - p = t * p; t *= t; t = t * t; t = pow(t, 3); - p /= t; // multiplication by inverse - p = p / t; bool_ = (t == t); bool_ = (t != t); t = T::identity(); diff --git a/src/2geom/utils.h b/src/2geom/utils.h index 31468a204..ecd1b7283 100644 --- a/src/2geom/utils.h +++ b/src/2geom/utils.h @@ -33,7 +33,6 @@ * */ -#include <2geom/math-utils.h> #include <vector> namespace Geom { @@ -43,6 +42,22 @@ inline bool logical_xor (bool a, bool b) { return (a || b) && !(a && b); } void binomial_coefficients(std::vector<size_t>& bc, size_t n); +struct EmptyClass {}; + +/** + * @brief Noncommutative multiplication helper. + * Generates operator*(T, U) from operator*=(T, U). Does not generate operator*(U, T) + * like boost::multipliable does. This makes it suitable for noncommutative cases, + * such as transforms. + */ +template <class T, class U, class B = EmptyClass> +struct MultipliableNoncommutative : B +{ + friend T operator*(T const &lhs, U const &rhs) { + T nrv(lhs); nrv *= rhs; return nrv; + } +}; + } #endif |
