From 04b06fe3ed0824c37cf65b425bf820d8b6f226a2 Mon Sep 17 00:00:00 2001 From: "Johan B. C. Engelen" Date: Tue, 1 Apr 2014 01:25:06 +0200 Subject: 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) --- src/2geom/path.cpp | 34 +++++++++++++++++++++++++++++++--- 1 file changed, 31 insertions(+), 3 deletions(-) (limited to 'src/2geom/path.cpp') 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 - +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(&**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 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; -- cgit v1.2.3