distance_functions.h
Go to the documentation of this file.
1 /* This file is part of the Gudhi Library. The Gudhi library
2  * (Geometric Understanding in Higher Dimensions) is a generic C++
3  * library for computational topology.
4  *
5  * Author(s): ClĂ©ment Maria
6  *
7  * Copyright (C) 2014 INRIA
8  *
9  * This program is free software: you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation, either version 3 of the License, or
12  * (at your option) any later version.
13  *
14  * This program is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17  * GNU General Public License for more details.
18  *
19  * You should have received a copy of the GNU General Public License
20  * along with this program. If not, see <http://www.gnu.org/licenses/>.
21  */
22 
23 #ifndef DISTANCE_FUNCTIONS_H_
24 #define DISTANCE_FUNCTIONS_H_
25 
26 #include <cmath> // for std::sqrt
27 #include <type_traits> // for std::decay
28 #include <iterator> // for std::begin, std::end
29 
30 namespace Gudhi {
31 
39  public:
40  template< typename Point >
41  auto operator()(const Point& p1, const Point& p2) const -> typename std::decay<decltype(*std::begin(p1))>::type {
42  auto it1 = p1.begin();
43  auto it2 = p2.begin();
44  typename Point::value_type dist = 0.;
45  for (; it1 != p1.end(); ++it1, ++it2) {
46  typename Point::value_type tmp = (*it1) - (*it2);
47  dist += tmp*tmp;
48  }
49  return std::sqrt(dist);
50  }
51 };
52 
53 } // namespace Gudhi
54 
55 #endif // DISTANCE_FUNCTIONS_H_
Compute the Euclidean distance between two Points given by a range of coordinates. The points are assumed to have the same dimension.
Definition: distance_functions.h:38
Definition: SimplicialComplexForAlpha.h:26
GUDHI  Version 2.0.1  - C++ library for Topological Data Analysis (TDA) and Higher Dimensional Geometry Understanding. Generated on Mon Oct 2 2017 10:20:49 for GUDHI by doxygen 1.8.11