From: johanengelen Date: Sun, 3 Aug 2008 18:45:24 +0000 (+0000) Subject: update 2geom X-Git-Url: https://git.tokkee.org/?a=commitdiff_plain;h=5ccda7cd3740fe4a91141c2712b2d2c62211f2be;p=inkscape.git update 2geom --- diff --git a/src/2geom/matrix.h b/src/2geom/matrix.h index dcf765c50..c81efab68 100644 --- a/src/2geom/matrix.h +++ b/src/2geom/matrix.h @@ -73,13 +73,15 @@ class Matrix { Point xAxis() const; Point yAxis() const; - Point translation() const; void setXAxis(Point const &vec); void setYAxis(Point const &vec); + + Point translation() const; void setTranslation(Point const &loc); double expansionX() const; double expansionY() const; + inline Point expansion() const { return Point(expansionX(), expansionY()); } void setExpansionX(double val); void setExpansionY(double val); diff --git a/src/2geom/nearest-point.cpp b/src/2geom/nearest-point.cpp index 7fef8c120..705767f13 100644 --- a/src/2geom/nearest-point.cpp +++ b/src/2geom/nearest-point.cpp @@ -2,9 +2,9 @@ * nearest point routines for D2 and Piecewise> * * Authors: - * + * * Marco Cecchetti - * + * * Copyright 2007-2008 authors * * This library is free software; you can redistribute it and/or @@ -33,6 +33,8 @@ #include <2geom/nearest-point.h> +#include + namespace Geom { @@ -41,15 +43,15 @@ namespace Geom // D2 versions /* - * Return the parameter t of a nearest point on the portion of the curve "c", + * Return the parameter t of a nearest point on the portion of the curve "c", * related to the interval [from, to], to the point "p". * The needed curve derivative "dc" is passed as parameter. * The function return the first nearest point to "p" that is found. */ -double nearest_point( Point const& p, - D2 const& c, - D2 const& dc, +double nearest_point( Point const& p, + D2 const& c, + D2 const& dc, double from, double to ) { if ( from > to ) std::swap(from, to); @@ -57,10 +59,10 @@ double nearest_point( Point const& p, { THROW_RANGEERROR("[from,to] interval out of bounds"); } - - SBasis dd = dot(c - p, dc); + if (c.isConstant()) return from; + SBasis dd = dot(c - p, dc); std::vector zeros = Geom::roots(dd); - + double closest = from; double min_dist_sq = L2sq(c(from) - p); double distsq; @@ -80,15 +82,15 @@ double nearest_point( Point const& p, } /* - * Return the parameters t of all the nearest points on the portion of + * Return the parameters t of all the nearest points on the portion of * the curve "c", related to the interval [from, to], to the point "p". * The needed curve derivative "dc" is passed as parameter. */ -std::vector -all_nearest_points( Point const& p, - D2 const& c, - D2 const& /*dc*/, +std::vector +all_nearest_points( Point const& p, + D2 const& c, + D2 const& dc, double from, double to ) { std::swap(from, to); @@ -99,8 +101,13 @@ all_nearest_points( Point const& p, } std::vector result; - SBasis dd = dot(c - p, Geom::derivative(c)); - + if (c.isConstant()) + { + result.push_back(from); + return result; + } + SBasis dd = dot(c - p, dc); + std::vector zeros = Geom::roots(dd); std::vector candidates; candidates.push_back(from); @@ -137,7 +144,7 @@ all_nearest_points( Point const& p, // Piecewise< D2 > versions -double nearest_point( Point const& p, +double nearest_point( Point const& p, Piecewise< D2 > const& c, double from, double to ) { @@ -146,7 +153,7 @@ double nearest_point( Point const& p, { THROW_RANGEERROR("[from,to] interval out of bounds"); } - + unsigned int si = c.segN(from); unsigned int ei = c.segN(to); if ( si == ei ) @@ -190,9 +197,9 @@ double nearest_point( Point const& p, return c.mapToDomain(nearest, ni); } -std::vector -all_nearest_points( Point const& p, - Piecewise< D2 > const& c, +std::vector +all_nearest_points( Point const& p, + Piecewise< D2 > const& c, double from, double to ) { if ( from > to ) std::swap(from, to); @@ -200,12 +207,12 @@ all_nearest_points( Point const& p, { THROW_RANGEERROR("[from,to] interval out of bounds"); } - + unsigned int si = c.segN(from); unsigned int ei = c.segN(to); if ( si == ei ) { - std::vector all_nearest = + std::vector all_nearest = all_nearest_points(p, c[si], c.segT(from, si), c.segT(to, si)); for ( unsigned int i = 0; i < all_nearest.size(); ++i ) { @@ -270,6 +277,8 @@ all_nearest_points( Point const& p, all_nearest.push_back( c.mapToDomain(all_np[i][j], ni[i]) ); } } + all_nearest.erase(std::unique(all_nearest.begin(), all_nearest.end()), + all_nearest.end()); return all_nearest; } diff --git a/src/2geom/nearest-point.h b/src/2geom/nearest-point.h index c8588214b..0ca28c4f2 100644 --- a/src/2geom/nearest-point.h +++ b/src/2geom/nearest-point.h @@ -3,9 +3,9 @@ * * * Authors: - * + * * Marco Cecchetti - * + * * Copyright 2007-2008 authors * * This library is free software; you can redistribute it and/or @@ -63,37 +63,37 @@ inline double nearest_point(Point const &p, Point const &A, Point const &v) // D2 versions /* - * Return the parameter t of a nearest point on the portion of the curve "c", + * Return the parameter t of a nearest point on the portion of the curve "c", * related to the interval [from, to], to the point "p". * The needed curve derivative "dc" is passed as parameter. * The function return the first nearest point to "p" that is found. */ double nearest_point( Point const& p, - D2 const& c, D2 const& dc, + D2 const& c, D2 const& dc, double from = 0, double to = 1 ); inline -double nearest_point( Point const& p, - D2 const& c, +double nearest_point( Point const& p, + D2 const& c, double from = 0, double to = 1 ) { return nearest_point(p, c, Geom::derivative(c), from, to); } /* - * Return the parameters t of all the nearest points on the portion of + * Return the parameters t of all the nearest points on the portion of * the curve "c", related to the interval [from, to], to the point "p". * The needed curve derivative "dc" is passed as parameter. */ -std::vector -all_nearest_points( Point const& p, - D2 const& c, D2 const& dc, +std::vector +all_nearest_points( Point const& p, + D2 const& c, D2 const& dc, double from = 0, double to = 1 ); inline -std::vector -all_nearest_points( Point const& p, - D2 const& c, +std::vector +all_nearest_points( Point const& p, + D2 const& c, double from = 0, double to = 1 ) { return all_nearest_points(p, c, Geom::derivative(c), from, to); @@ -103,25 +103,25 @@ all_nearest_points( Point const& p, //////////////////////////////////////////////////////////////////////////////// // Piecewise< D2 > versions -double nearest_point( Point const& p, - Piecewise< D2 > const& c, +double nearest_point( Point const& p, + Piecewise< D2 > const& c, double from, double to ); inline -double nearest_point( Point const& p, Piecewise< D2 > const& c ) +double nearest_point( Point const& p, Piecewise< D2 > const& c ) { return nearest_point(p, c, c.cuts[0], c.cuts[c.size()]); } -std::vector -all_nearest_points( Point const& p, - Piecewise< D2 > const& c, +std::vector +all_nearest_points( Point const& p, + Piecewise< D2 > const& c, double from, double to ); inline -std::vector -all_nearest_points( Point const& p, Piecewise< D2 > const& c ) +std::vector +all_nearest_points( Point const& p, Piecewise< D2 > const& c ) { return all_nearest_points(p, c, c.cuts[0], c.cuts[c.size()]); } diff --git a/src/2geom/path.cpp b/src/2geom/path.cpp index 5f321d517..2943d6a92 100644 --- a/src/2geom/path.cpp +++ b/src/2geom/path.cpp @@ -4,7 +4,7 @@ * Authors: * MenTaLguY * Marco Cecchetti - * + * * Copyright 2007-2008 authors * * This library is free software; you can redistribute it and/or @@ -35,10 +35,12 @@ #include <2geom/path.h> +#include + using namespace Geom::PathInternal; -namespace Geom +namespace Geom { Rect Path::boundsFast() const { @@ -98,7 +100,7 @@ Path &Path::operator*=(Matrix const &m) { return *this; } -std::vector +std::vector Path::allNearestPoints(Point const& _point, double from, double to) const { if ( from > to ) std::swap(from, to); @@ -125,7 +127,7 @@ Path::allNearestPoints(Point const& _point, double from, double to) const } if ( si == ei ) { - std::vector all_nearest = + std::vector all_nearest = _path[si].allNearestPoints(_point, st, et); for ( unsigned int i = 0; i < all_nearest.size(); ++i ) { @@ -139,7 +141,7 @@ Path::allNearestPoints(Point const& _point, double from, double to) const std::vector ni; ni.push_back(si); double dsq; - double mindistsq + double mindistsq = distanceSq( _point, _path[si].pointAt( all_np.front().front() ) ); Rect bb; for ( unsigned int i = si + 1; i < ei; ++i ) @@ -191,7 +193,9 @@ Path::allNearestPoints(Point const& _point, double from, double to) const all_nearest.push_back( ni[i] + all_np[i][j] ); } } - return all_nearest; + all_nearest.erase(std::unique(all_nearest.begin(), all_nearest.end()), + all_nearest.end()); + return all_nearest; } double Path::nearestPoint(Point const &_point, double from, double to, double *distance_squared) const @@ -221,7 +225,8 @@ double Path::nearestPoint(Point const &_point, double from, double to, double *d if ( si == ei ) { double nearest = _path[si].nearestPoint(_point, st, et); - *distance_squared = distanceSq(_point, _path[si].pointAt(nearest)); + if (distance_squared != NULL) + *distance_squared = distanceSq(_point, _path[si].pointAt(nearest)); return si + nearest; } @@ -259,9 +264,9 @@ double Path::nearestPoint(Point const &_point, double from, double to, double *d } } - if (distance_squared) { + if (distance_squared != NULL) *distance_squared = mindistsq; - } + return ni + nearest; }