cheshirekow  v0.1.0
Distance.hpp
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2012 Josh Bialkowski (jbialk@mit.edu)
3  *
4  * This file is part of mpblocks.
5  *
6  * mpblocks is free software: you can redistribute it and/or modify
7  * it under the terms of the GNU General Public License as published by
8  * the Free Software Foundation, either version 3 of the License, or
9  * (at your option) any later version.
10  *
11  * mpblocks is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14  * GNU General Public License for more details.
15  *
16  * You should have received a copy of the GNU General Public License
17  * along with mpblocks. If not, see <http://www.gnu.org/licenses/>.
18  */
27 #ifndef MPBLOCKS_KD_TREE_EUCLIDEAN_DISTANCE_HPP_
28 #define MPBLOCKS_KD_TREE_EUCLIDEAN_DISTANCE_HPP_
29 
30 
31 
32 namespace mpblocks {
33 namespace kd_tree {
34 namespace euclidean {
35 
36 template <class Traits>
37 typename Traits::Format_t
39 {
40  return (pa-pb).squaredNorm();
41 }
42 
43 template <class Traits>
44 typename Traits::Format_t
46 {
47  Format_t dist2 = 0;
48  Format_t dist2i = 0;
49 
50  for (unsigned int i=0; i < p.rows(); i++)
51  {
52  if (p[i] < h.minExt[i])
53  dist2i = h.minExt[i] - p[i];
54  else if(p[i] > h.maxExt[i])
55  dist2i = h.maxExt[i] - p[i];
56  else
57  dist2i = 0;
58 
59  dist2i *= dist2i;
60  dist2 += dist2i;
61  }
62 
63  return dist2;
64 }
65 
66 
67 
68 } // namespace euclidean
69 } // namespace kd_tree
70 } // namespace mpblocks
71 
72 
73 
74 #endif // DEFAULTDISTANCE_H_
Point_t maxExt
maximum extent of hyper-rectangle
Definition: HyperRect.h:30
Format_t operator()(const Point_t &pa, const Point_t &pb)
return the euclidean distance between two points
Definition: Distance.hpp:38
Eigen::Matrix< Format_t, Traits::NDim, 1 > Point_t
Definition: Distance.h:42
double Format_t
number format (i.e. double, float)
Definition: Traits.h:38
Point_t minExt
minimum extent of hyper-rectangle
Definition: HyperRect.h:29
an NDim dimensional hyperrectangle, represented as a min and max extent
Definition: HyperRect.h:23