3
* \brief nearest point routines for D2<SBasis> and Piecewise<D2<SBasis>>
7
* Marco Cecchetti <mrcekets at gmail.com>
9
* Copyright 2007-2008 authors
11
* This library is free software; you can redistribute it and/or
12
* modify it either under the terms of the GNU Lesser General Public
13
* License version 2.1 as published by the Free Software Foundation
14
* (the "LGPL") or, at your option, under the terms of the Mozilla
15
* Public License Version 1.1 (the "MPL"). If you do not alter this
16
* notice, a recipient may use your version of this file under either
17
* the MPL or the LGPL.
19
* You should have received a copy of the LGPL along with this library
20
* in the file COPYING-LGPL-2.1; if not, write to the Free Software
21
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22
* You should have received a copy of the MPL along with this library
23
* in the file COPYING-MPL-1.1
25
* The contents of this file are subject to the Mozilla Public License
26
* Version 1.1 (the "License"); you may not use this file except in
27
* compliance with the License. You may obtain a copy of the License at
28
* http://www.mozilla.org/MPL/
30
* This software is distributed on an "AS IS" basis, WITHOUT WARRANTY
31
* OF ANY KIND, either express or implied. See the LGPL or the MPL for
32
* the specific language governing rights and limitations.
36
#ifndef _NEAREST_POINT_H_
37
#define _NEAREST_POINT_H_
43
#include <2geom/piecewise.h>
44
#include <2geom/exception.h>
52
* Given a line L specified by a point A and direction vector v,
53
* return the point on L nearest to p. Note that the returned value
54
* is with respect to the _normalized_ direction of v!
56
inline double nearest_point(Point const &p, Point const &A, Point const &v)
59
return d[0] * v[0] + d[1] * v[1];
62
////////////////////////////////////////////////////////////////////////////////
63
// D2<SBasis> versions
66
* Return the parameter t of a nearest point on the portion of the curve "c",
67
* related to the interval [from, to], to the point "p".
68
* The needed curve derivative "dc" is passed as parameter.
69
* The function return the first nearest point to "p" that is found.
71
double nearest_point( Point const& p,
72
D2<SBasis> const& c, D2<SBasis> const& dc,
73
double from = 0, double to = 1 );
76
double nearest_point( Point const& p,
78
double from = 0, double to = 1 )
80
return nearest_point(p, c, Geom::derivative(c), from, to);
84
* Return the parameters t of all the nearest points on the portion of
85
* the curve "c", related to the interval [from, to], to the point "p".
86
* The needed curve derivative "dc" is passed as parameter.
89
all_nearest_points( Point const& p,
90
D2<SBasis> const& c, D2<SBasis> const& dc,
91
double from = 0, double to = 1 );
95
all_nearest_points( Point const& p,
97
double from = 0, double to = 1 )
99
return all_nearest_points(p, c, Geom::derivative(c), from, to);
103
////////////////////////////////////////////////////////////////////////////////
104
// Piecewise< D2<SBasis> > versions
106
double nearest_point( Point const& p,
107
Piecewise< D2<SBasis> > const& c,
108
double from, double to );
111
double nearest_point( Point const& p, Piecewise< D2<SBasis> > const& c )
113
return nearest_point(p, c, c.cuts[0], c.cuts[c.size()]);
118
all_nearest_points( Point const& p,
119
Piecewise< D2<SBasis> > const& c,
120
double from, double to );
124
all_nearest_points( Point const& p, Piecewise< D2<SBasis> > const& c )
126
return all_nearest_points(p, c, c.cuts[0], c.cuts[c.size()]);
129
} // end namespace Geom
133
#endif /*_NEAREST_POINT_H_*/