1 /*\r
2 * nearest point routines for D2<SBasis> and Piecewise<D2<SBasis>>\r
3 *\r
4 *\r
5 * Authors:\r
6 * \r
7 * Marco Cecchetti <mrcekets at gmail.com>\r
8 * \r
9 * Copyright 2007-2008 authors\r
10 *\r
11 * This library is free software; you can redistribute it and/or\r
12 * modify it either under the terms of the GNU Lesser General Public\r
13 * License version 2.1 as published by the Free Software Foundation\r
14 * (the "LGPL") or, at your option, under the terms of the Mozilla\r
15 * Public License Version 1.1 (the "MPL"). If you do not alter this\r
16 * notice, a recipient may use your version of this file under either\r
17 * the MPL or the LGPL.\r
18 *\r
19 * You should have received a copy of the LGPL along with this library\r
20 * in the file COPYING-LGPL-2.1; if not, write to the Free Software\r
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA\r
22 * You should have received a copy of the MPL along with this library\r
23 * in the file COPYING-MPL-1.1\r
24 *\r
25 * The contents of this file are subject to the Mozilla Public License\r
26 * Version 1.1 (the "License"); you may not use this file except in\r
27 * compliance with the License. You may obtain a copy of the License at\r
28 * http://www.mozilla.org/MPL/\r
29 *\r
30 * This software is distributed on an "AS IS" basis, WITHOUT WARRANTY\r
31 * OF ANY KIND, either express or implied. See the LGPL or the MPL for\r
32 * the specific language governing rights and limitations.\r
33 */\r
34 \r
35 \r
36 #ifndef _NEAREST_POINT_H_\r
37 #define _NEAREST_POINT_H_\r
38 \r
39 \r
40 #include <vector>\r
41 \r
42 #include "d2.h"\r
43 #include "piecewise.h"\r
44 #include "exception.h"\r
45 \r
46 \r
47 \r
48 namespace Geom\r
49 {\r
50 \r
51 ////////////////////////////////////////////////////////////////////////////////\r
52 // D2<SBasis> versions\r
53 \r
54 /*\r
55 * Return the parameter t of a nearest point on the portion of the curve "c", \r
56 * related to the interval [from, to], to the point "p".\r
57 * The needed curve derivative "dc" is passed as parameter.\r
58 * The function return the first nearest point to "p" that is found.\r
59 */\r
60 double nearest_point( Point const& p,\r
61 D2<SBasis> const& c, D2<SBasis> const& dc, \r
62 double from = 0, double to = 1 );\r
63 \r
64 inline\r
65 double nearest_point( Point const& p, \r
66 D2<SBasis> const& c, \r
67 double from = 0, double to = 1 )\r
68 {\r
69 return nearest_point(p, c, Geom::derivative(c), from, to);\r
70 }\r
71 \r
72 /*\r
73 * Return the parameters t of all the nearest points on the portion of \r
74 * the curve "c", related to the interval [from, to], to the point "p".\r
75 * The needed curve derivative "dc" is passed as parameter.\r
76 */\r
77 std::vector<double> \r
78 all_nearest_points( Point const& p, \r
79 D2<SBasis> const& c, D2<SBasis> const& dc, \r
80 double from = 0, double to = 1 );\r
81 \r
82 inline\r
83 std::vector<double> \r
84 all_nearest_points( Point const& p, \r
85 D2<SBasis> const& c, \r
86 double from = 0, double to = 1 )\r
87 {\r
88 return all_nearest_points(p, c, Geom::derivative(c), from, to);\r
89 }\r
90 \r
91 \r
92 ////////////////////////////////////////////////////////////////////////////////\r
93 // Piecewise< D2<SBasis> > versions\r
94 \r
95 double nearest_point( Point const& p, \r
96 Piecewise< D2<SBasis> > const& c, \r
97 double from, double to );\r
98 \r
99 inline\r
100 double nearest_point( Point const& p, Piecewise< D2<SBasis> > const& c ) \r
101 {\r
102 return nearest_point(p, c, c.cuts[0], c.cuts[c.size()]);\r
103 }\r
104 \r
105 \r
106 std::vector<double> \r
107 all_nearest_points( Point const& p, \r
108 Piecewise< D2<SBasis> > const& c, \r
109 double from, double to );\r
110 \r
111 inline\r
112 std::vector<double> \r
113 all_nearest_points( Point const& p, Piecewise< D2<SBasis> > const& c ) \r
114 {\r
115 return all_nearest_points(p, c, c.cuts[0], c.cuts[c.size()]);\r
116 }\r
117 \r
118 } // end namespace Geom\r
119 \r
120 \r
121 \r
122 #endif /*_NEAREST_POINT_H_*/\r