summary | shortlog | log | commit | commitdiff | tree
raw | patch | inline | side by side (parent: bebb322)
raw | patch | inline | side by side (parent: bebb322)
author | johanengelen <johanengelen@users.sourceforge.net> | |
Sun, 3 Aug 2008 18:45:24 +0000 (18:45 +0000) | ||
committer | johanengelen <johanengelen@users.sourceforge.net> | |
Sun, 3 Aug 2008 18:45:24 +0000 (18:45 +0000) |
src/2geom/matrix.h | patch | blob | history | |
src/2geom/nearest-point.cpp | patch | blob | history | |
src/2geom/nearest-point.h | patch | blob | history | |
src/2geom/path.cpp | patch | blob | history |
diff --git a/src/2geom/matrix.h b/src/2geom/matrix.h
index dcf765c50ae9dde84cc1ab1911049c0be81bd8bc..c81efab68a452576dffab8b7eb1fc8582ff09f84 100644 (file)
--- a/src/2geom/matrix.h
+++ b/src/2geom/matrix.h
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);
index 7fef8c12002fd216b51952ab6b9d7a472a39b82f..705767f13d58bddec830726981f7b78a441f1abc 100644 (file)
* 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
#include <2geom/nearest-point.h>
+#include <algorithm>
+
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);
{
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;
}
/*
- * 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);
}
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);
// 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 )
{
{
THROW_RANGEERROR("[from,to] interval out of bounds");
}
-
+
unsigned int si = c.segN(from);
unsigned int ei = c.segN(to);
if ( si == ei )
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);
{
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 )
{
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;
}
index c8588214bfc3d1f35e7e5c00c77d01374c858229..0ca28c4f218fcfdb8d024cac2da94e23d182b43a 100644 (file)
*
*
* Authors:
- *
+ *
* Marco Cecchetti <mrcekets at gmail.com>
- *
+ *
* Copyright 2007-2008 authors
*
* This library is free software; you can redistribute it and/or
// 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);
////////////////////////////////////////////////////////////////////////////////
// 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 5f321d5175be09153fc29c132393de6056800fe2..2943d6a9279142aec5dfe8ba73ae8678a51ddf30 100644 (file)
--- a/src/2geom/path.cpp
+++ b/src/2geom/path.cpp
* 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
#include <2geom/path.h>
+#include <algorithm>
+
using namespace Geom::PathInternal;
-namespace Geom
+namespace Geom
{
Rect Path::boundsFast() const {
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);
}
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 )
{
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 )
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;
}