summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorJohan B. C. Engelen <jbc.engelen@swissonline.ch>2008-08-03 18:45:24 +0000
committerjohanengelen <johanengelen@users.sourceforge.net>2008-08-03 18:45:24 +0000
commit9e7e3bc54debf9d887842ba9b86834830629df82 (patch)
treefeacc2502555d21562e989be06f02d5271a01174 /src
parentconvert path to linears and cubics only before creating outline. (workaround ... (diff)
downloadinkscape-9e7e3bc54debf9d887842ba9b86834830629df82.tar.gz
inkscape-9e7e3bc54debf9d887842ba9b86834830629df82.zip
update 2geom
(bzr r6549)
Diffstat (limited to 'src')
-rw-r--r--src/2geom/matrix.h4
-rw-r--r--src/2geom/nearest-point.cpp55
-rw-r--r--src/2geom/nearest-point.h42
-rw-r--r--src/2geom/path.cpp23
4 files changed, 70 insertions, 54 deletions
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<SBasis> and Piecewise<D2<SBasis>>
*
* Authors:
- *
+ *
* Marco Cecchetti <mrcekets at gmail.com>
- *
+ *
* 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 <algorithm>
+
namespace Geom
{
@@ -41,15 +43,15 @@ namespace Geom
// D2<SBasis> 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<SBasis> const& c,
- D2<SBasis> const& dc,
+double nearest_point( Point const& p,
+ D2<SBasis> const& c,
+ D2<SBasis> 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<double> 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<double>
-all_nearest_points( Point const& p,
- D2<SBasis> const& c,
- D2<SBasis> const& /*dc*/,
+std::vector<double>
+all_nearest_points( Point const& p,
+ D2<SBasis> const& c,
+ D2<SBasis> const& dc,
double from, double to )
{
std::swap(from, to);
@@ -99,8 +101,13 @@ all_nearest_points( Point const& p,
}
std::vector<double> 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<double> zeros = Geom::roots(dd);
std::vector<double> candidates;
candidates.push_back(from);
@@ -137,7 +144,7 @@ all_nearest_points( Point const& p,
// Piecewise< D2<SBasis> > versions
-double nearest_point( Point const& p,
+double nearest_point( Point const& p,
Piecewise< D2<SBasis> > 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<double>
-all_nearest_points( Point const& p,
- Piecewise< D2<SBasis> > const& c,
+std::vector<double>
+all_nearest_points( Point const& p,
+ Piecewise< D2<SBasis> > 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<double> all_nearest =
+ std::vector<double> 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 <mrcekets at gmail.com>
- *
+ *
* 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<SBasis> 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<SBasis> const& c, D2<SBasis> const& dc,
+ D2<SBasis> const& c, D2<SBasis> const& dc,
double from = 0, double to = 1 );
inline
-double nearest_point( Point const& p,
- D2<SBasis> const& c,
+double nearest_point( Point const& p,
+ D2<SBasis> 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<double>
-all_nearest_points( Point const& p,
- D2<SBasis> const& c, D2<SBasis> const& dc,
+std::vector<double>
+all_nearest_points( Point const& p,
+ D2<SBasis> const& c, D2<SBasis> const& dc,
double from = 0, double to = 1 );
inline
-std::vector<double>
-all_nearest_points( Point const& p,
- D2<SBasis> const& c,
+std::vector<double>
+all_nearest_points( Point const& p,
+ D2<SBasis> 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<SBasis> > versions
-double nearest_point( Point const& p,
- Piecewise< D2<SBasis> > const& c,
+double nearest_point( Point const& p,
+ Piecewise< D2<SBasis> > const& c,
double from, double to );
inline
-double nearest_point( Point const& p, Piecewise< D2<SBasis> > const& c )
+double nearest_point( Point const& p, Piecewise< D2<SBasis> > const& c )
{
return nearest_point(p, c, c.cuts[0], c.cuts[c.size()]);
}
-std::vector<double>
-all_nearest_points( Point const& p,
- Piecewise< D2<SBasis> > const& c,
+std::vector<double>
+all_nearest_points( Point const& p,
+ Piecewise< D2<SBasis> > const& c,
double from, double to );
inline
-std::vector<double>
-all_nearest_points( Point const& p, Piecewise< D2<SBasis> > const& c )
+std::vector<double>
+all_nearest_points( Point const& p, Piecewise< D2<SBasis> > 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 <mental@rydia.net>
* Marco Cecchetti <mrcekets at gmail.com>
- *
+ *
* Copyright 2007-2008 authors
*
* This library is free software; you can redistribute it and/or
@@ -35,10 +35,12 @@
#include <2geom/path.h>
+#include <algorithm>
+
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<double>
+std::vector<double>
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<double> all_nearest =
+ std::vector<double> 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<unsigned int> 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;
}