Gudhi  1.1.0
 All Classes Functions Typedefs Friends Groups Pages
distance_functions.h
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 Sophia Antipolis-Méditerranée (France)
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 /* Compute the Euclidean distance between two Points given
24  * by a range of coordinates. The points are assumed to have
25  * the same dimension. */
26 template< typename Point >
27 double euclidean_distance( Point &p1, Point &p2)
28 {
29  double dist = 0.;
30  auto it1 = p1.begin(); auto it2 = p2.begin();
31  for(; it1 != p1.end(); ++it1, ++it2)
32  {
33  double tmp = *it1 - *it2;
34  dist += tmp*tmp;
35  }
36  return sqrt(dist);
37 }