diff options
| author | Johan B. C. Engelen <jbc.engelen@swissonline.ch> | 2014-03-31 23:25:06 +0000 |
|---|---|---|
| committer | Johan B. C. Engelen <j.b.c.engelen@alumnus.utwente.nl> | 2014-03-31 23:25:06 +0000 |
| commit | 04b06fe3ed0824c37cf65b425bf820d8b6f226a2 (patch) | |
| tree | ed85a3f16e78220b3e3ae818296e08ee0b59cea4 /src/2geom | |
| parent | 2geom: silence warning (diff) | |
| download | inkscape-04b06fe3ed0824c37cf65b425bf820d8b6f226a2.tar.gz inkscape-04b06fe3ed0824c37cf65b425bf820d8b6f226a2.zip | |
partial 2geom update:
- main reason for update: better swap for Path (fixes C++11 warning/error)
- faster implementation for Path * Translate (~6x), Inkscape's code has to be modified to use it though
(bzr r13248)
Diffstat (limited to 'src/2geom')
| -rw-r--r-- | src/2geom/bezier-curve.h | 11 | ||||
| -rw-r--r-- | src/2geom/bezier.h | 12 | ||||
| -rw-r--r-- | src/2geom/curve.h | 16 | ||||
| -rw-r--r-- | src/2geom/elliptical-arc.h | 7 | ||||
| -rw-r--r-- | src/2geom/path.cpp | 34 | ||||
| -rw-r--r-- | src/2geom/path.h | 24 | ||||
| -rw-r--r-- | src/2geom/sbasis-curve.h | 7 |
7 files changed, 97 insertions, 14 deletions
diff --git a/src/2geom/bezier-curve.h b/src/2geom/bezier-curve.h index c0224e850..d379526fa 100644 --- a/src/2geom/bezier-curve.h +++ b/src/2geom/bezier-curve.h @@ -39,6 +39,7 @@ #include <2geom/curve.h> #include <2geom/sbasis-curve.h> // for non-native winding method #include <2geom/bezier.h> +#include <2geom/transforms.h> namespace Geom { @@ -118,6 +119,7 @@ public: virtual Curve *reverse() const { return new BezierCurve(Geom::reverse(inner)); } + virtual Curve *transformed(Affine const &m) const { BezierCurve *ret = new BezierCurve(); std::vector<Point> ps = points(); @@ -127,6 +129,11 @@ public: ret->setPoints(ps); return ret; } + virtual Curve &operator*=(Translate const &m) { + inner += m.vector(); + return *this; + }; + virtual Curve *derivative() const { return new BezierCurve(Geom::derivative(inner[X]), Geom::derivative(inner[Y])); } @@ -248,6 +255,10 @@ public: return ret; } } + virtual Curve &operator*=(Translate const &m) { + inner += m.vector(); + return *this; + } virtual Curve *derivative() const; // the method below is defined so that LineSegment can specialize it diff --git a/src/2geom/bezier.h b/src/2geom/bezier.h index 176128328..51d5211d9 100644 --- a/src/2geom/bezier.h +++ b/src/2geom/bezier.h @@ -391,6 +391,18 @@ inline Bezier operator-(const Bezier & a, double v) { return result; } +inline Bezier& operator+=(Bezier & a, double v) { + for(unsigned i = 0; i <= a.order(); ++i) + a[i] = a[i] + v; + return a; +} + +inline Bezier& operator-=(Bezier & a, double v) { + for(unsigned i = 0; i <= a.order(); ++i) + a[i] = a[i] - v; + return a; +} + inline Bezier operator*(const Bezier & a, double v) { Bezier result = Bezier(Bezier::Order(a)); for(unsigned i = 0; i <= a.order(); i++) diff --git a/src/2geom/curve.h b/src/2geom/curve.h index 77f6808e1..172fd7ddc 100644 --- a/src/2geom/curve.h +++ b/src/2geom/curve.h @@ -162,6 +162,7 @@ public: /** @brief Create an exact copy of this curve. * @return Pointer to a newly allocated curve, identical to the original */ virtual Curve *duplicate() const = 0; + /** @brief Create a curve transformed by an affine transformation. * This method returns a new curve instead modifying the existing one, because some curve * types are not closed under affine transformations. The returned curve may be of different @@ -169,6 +170,15 @@ public: * @param m Affine describing the affine transformation * @return Pointer to a new, transformed curve */ virtual Curve *transformed(Affine const &m) const = 0; + + /** @brief Translate the curve (i.e. displace by Point) + * This method modifies the curve; all curve types are closed under + * translations (the result can be expressed in its own curve type). + * This function yields the same result as transformed(m). + * @param p Point by which to translate the curve + * @return reference to self */ + virtual Curve &operator*=(Translate const &m) = 0; + /** @brief Create a curve that corresponds to a part of this curve. * For \f$a > b\f$, the returned portion will be reversed with respect to the original. * The returned curve will always be of the same type. @@ -282,6 +292,12 @@ Coord nearest_point(Point const& p, Curve const& c) { return c.nearestPoint(p); } +// for make benefit glorious library of Boost Pointer Container +inline +Curve *new_clone(Curve const &c) { + return c.duplicate(); +} + } // end namespace Geom diff --git a/src/2geom/elliptical-arc.h b/src/2geom/elliptical-arc.h index e1e757207..5527aa6bc 100644 --- a/src/2geom/elliptical-arc.h +++ b/src/2geom/elliptical-arc.h @@ -229,6 +229,13 @@ public: virtual int degreesOfFreedom() const { return 7; } virtual Curve *derivative() const; virtual Curve *transformed(Affine const &m) const; + virtual Curve &operator*=(Translate const &m) { + _initial_point += m.vector(); + _final_point += m.vector(); + _center += m.vector(); + return *this; + } + /** * The size of the returned vector equals n+1. diff --git a/src/2geom/path.cpp b/src/2geom/path.cpp index 93def6c55..5797f475c 100644 --- a/src/2geom/path.cpp +++ b/src/2geom/path.cpp @@ -35,9 +35,10 @@ #include <2geom/path.h> +#include <2geom/transforms.h> #include <algorithm> - +using std::swap; using namespace Geom::PathInternal; namespace Geom @@ -102,10 +103,35 @@ Path &Path::operator*=(Affine const &m) { return *this; } +Path &Path::operator*=(Translate const &m) { + unshare(); + Sequence::iterator last = get_curves().end() - 1; + Sequence::iterator it; + Point prev; + for (it = get_curves().begin() ; it != last ; ++it) { + *(const_cast<Curve*>(&**it)) *= m; + if ( it != get_curves().begin() && (*it)->initialPoint() != prev ) { + THROW_CONTINUITYERROR(); + } + prev = (*it)->finalPoint(); + } + for ( int i = 0 ; i < 2 ; ++i ) { + final_->setPoint(i, (*final_)[i] + m.vector()); + } + if (get_curves().size() > 1) { + if ( front().initialPoint() != initialPoint() || back().finalPoint() != finalPoint() ) { + THROW_CONTINUITYERROR(); + } + } + return *this; +} + std::vector<double> Path::allNearestPoints(Point const& _point, double from, double to) const { - if ( from > to ) std::swap(from, to); + using std::swap; + + if ( from > to ) swap(from, to); const Path& _path = *this; unsigned int sz = _path.size(); if ( _path.closed() ) ++sz; @@ -215,7 +241,9 @@ Path::nearestPointPerCurve(Point const& _point) const double Path::nearestPoint(Point const &_point, double from, double to, double *distance_squared) const { - if ( from > to ) std::swap(from, to); + using std::swap; + + if ( from > to ) swap(from, to); const Path& _path = *this; unsigned int sz = _path.size(); if ( _path.closed() ) ++sz; diff --git a/src/2geom/path.h b/src/2geom/path.h index 48d7acaaf..28d2a25e4 100644 --- a/src/2geom/path.h +++ b/src/2geom/path.h @@ -40,6 +40,7 @@ #include <boost/shared_ptr.hpp> #include <2geom/curve.h> #include <2geom/bezier-curve.h> +#include <2geom/transforms.h> namespace Geom { @@ -205,11 +206,14 @@ public: // Path &operator=(Path const &other) - use default assignment operator + /// \todo Add noexcept specifiers for C++11 void swap(Path &other) { - std::swap(other.curves_, curves_); - std::swap(other.final_, final_); - std::swap(other.closed_, closed_); + using std::swap; + swap(other.curves_, curves_); + swap(other.final_, final_); + swap(other.closed_, closed_); } + friend inline void swap(Path &a, Path &b) { a.swap(b); } Curve const &operator[](unsigned i) const { return *get_curves()[i]; } Curve const &at_index(unsigned i) const { return *get_curves()[i]; } @@ -289,8 +293,14 @@ public: ret *= m; return ret; } + Path operator*(Translate const &m) const { // specialization over Affine, for faster computation + Path ret(*this); + ret *= m; + return ret; + } Path &operator*=(Affine const &m); + Path &operator*=(Translate const &m); // specialization over Affine, for faster computation Point pointAt(double t) const { @@ -686,14 +696,6 @@ Coord nearest_point(Point const& p, Path const& c) } // end namespace Geom -namespace std { - -template <> -inline void swap<Geom::Path>(Geom::Path &a, Geom::Path &b) { - a.swap(b); -} - -} // end namespace std #endif // LIB2GEOM_SEEN_PATH_H diff --git a/src/2geom/sbasis-curve.h b/src/2geom/sbasis-curve.h index 554b702e6..a5c3f2ca7 100644 --- a/src/2geom/sbasis-curve.h +++ b/src/2geom/sbasis-curve.h @@ -39,6 +39,7 @@ #include <2geom/curve.h> #include <2geom/nearest-point.h> #include <2geom/sbasis-geometric.h> +#include <2geom/transforms.h> namespace Geom { @@ -117,7 +118,13 @@ public: virtual Curve *portion(Coord f, Coord t) const { return new SBasisCurve(Geom::portion(inner, f, t)); } + virtual Curve *transformed(Affine const &m) const { return new SBasisCurve(inner * m); } + virtual Curve &operator*=(Translate const &m) { + inner += m.vector(); + return *this; + }; + virtual Curve *derivative() const { return new SBasisCurve(Geom::derivative(inner)); } |
