diff options
| author | Liam P. White <inkscapebronyat-signgmaildotcom> | 2014-04-01 00:30:50 +0000 |
|---|---|---|
| committer | Liam P. White <inkscapebronyat-signgmaildotcom> | 2014-04-01 00:30:50 +0000 |
| commit | f438b6b2ed8fb3013ef75832ef0763d27aa130eb (patch) | |
| tree | 57dbdbd030a0efb418ff714992520fc23af4597a /src/2geom | |
| parent | Update to trunk (diff) | |
| parent | partial 2geom update: (diff) | |
| download | inkscape-f438b6b2ed8fb3013ef75832ef0763d27aa130eb.tar.gz inkscape-f438b6b2ed8fb3013ef75832ef0763d27aa130eb.zip | |
Update to trunk
(bzr r13090.1.39)
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/recursive-bezier-intersection.cpp | 16 | ||||
| -rw-r--r-- | src/2geom/sbasis-curve.h | 7 | ||||
| -rw-r--r-- | src/2geom/sbasis-roots.cpp | 4 | ||||
| -rw-r--r-- | src/2geom/svg-path-parser.cpp | 2 |
10 files changed, 110 insertions, 23 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/recursive-bezier-intersection.cpp b/src/2geom/recursive-bezier-intersection.cpp index 0c7977970..548065196 100644 --- a/src/2geom/recursive-bezier-intersection.cpp +++ b/src/2geom/recursive-bezier-intersection.cpp @@ -13,6 +13,8 @@ unsigned intersect_steps = 0; using std::vector; +using std::swap; + namespace Geom { class OldBezier { @@ -31,7 +33,7 @@ public: minax = p[0][X]; // These are the most likely to be extremal maxax = p.back()[X]; if( minax > maxax ) - std::swap(minax, maxax); + swap(minax, maxax); for(unsigned i = 1; i < p.size()-1; i++) { if( p[i][X] < minax ) minax = p[i][X]; @@ -42,7 +44,7 @@ public: minay = p[0][Y]; // These are the most likely to be extremal maxay = p.back()[Y]; if( minay > maxay ) - std::swap(minay, maxay); + swap(minay, maxay); for(unsigned i = 1; i < p.size()-1; i++) { if( p[i][Y] < minay ) minay = p[i][Y]; @@ -71,9 +73,6 @@ find_intersections_bezier_recursive( std::vector<std::pair<double, double> > &xs } -/* The value of 1.0 / (1L<<14) is enough for most applications */ -const double INV_EPS = (1L<<14); - /* * split the curve at the midpoint, returning an array with the two parts * Temporary storage is minimized by using part of the storage for the result @@ -318,9 +317,14 @@ double Lmax(Point p) { return std::max(fabs(p[X]), fabs(p[Y])); } + unsigned wangs_theorem(OldBezier /*a*/) { return 6; // seems a good approximation! - /*double la1 = Lmax( ( a.p[2] - a.p[1] ) - (a.p[1] - a.p[0]) ); + + /* + const double INV_EPS = (1L<<14); // The value of 1.0 / (1L<<14) is enough for most applications + + double la1 = Lmax( ( a.p[2] - a.p[1] ) - (a.p[1] - a.p[0]) ); double la2 = Lmax( ( a.p[3] - a.p[2] ) - (a.p[2] - a.p[1]) ); double l0 = std::max(la1, la2); unsigned ra; 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)); } diff --git a/src/2geom/sbasis-roots.cpp b/src/2geom/sbasis-roots.cpp index 813e471e8..acf4e1abc 100644 --- a/src/2geom/sbasis-roots.cpp +++ b/src/2geom/sbasis-roots.cpp @@ -114,7 +114,7 @@ OptInterval bounds_fast(const SBasis &sb, int order) { res[1]=lerp(t, a+v*t, b); } } - if (order>0) res*=pow(.25,order); + if (order>0) res*=std::pow(.25,order); return res; } @@ -151,7 +151,7 @@ OptInterval bounds_local(const SBasis &sb, const OptInterval &i, int order) { } } Interval res = Interval(lo,hi); - if (order>0) res*=pow(.25,order); + if (order>0) res*=std::pow(.25,order); return res; } diff --git a/src/2geom/svg-path-parser.cpp b/src/2geom/svg-path-parser.cpp index fa31b57b5..ccc383920 100644 --- a/src/2geom/svg-path-parser.cpp +++ b/src/2geom/svg-path-parser.cpp @@ -1144,7 +1144,7 @@ static const char _svg_path_trans_actions[] = { static const int svg_path_start = 1; static const int svg_path_first_final = 270; -static const int svg_path_en_main = 1; +//static const int svg_path_en_main = 1; #line 144 "/home/tweenk/src/lib2geom/src/2geom/svg-path-parser.rl" |
