diff options
author | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-12-08 22:17:04 +0000 |
---|---|---|
committer | vrouvrea <vrouvrea@636b058d-ea47-450e-bf9e-a15bfbe3eedb> | 2016-12-08 22:17:04 +0000 |
commit | b41fb07d4dbaf4e12c31b952cc2bc24e30c55384 (patch) | |
tree | 0393f116d51636a64287d5cab8815cf08735b2c4 /src/common/include | |
parent | ccc1ca066fa7c1fb35929eceb52f2f36179aea37 (diff) |
replace euclidean_distance with a class Euclidean_distance containing an operator()
git-svn-id: svn+ssh://scm.gforge.inria.fr/svnroot/gudhi/branches/distance_matrix_in_rips_module@1840 636b058d-ea47-450e-bf9e-a15bfbe3eedb
Former-commit-id: b1619401ac0ef978257709c5deeb7e19fbcff32c
Diffstat (limited to 'src/common/include')
-rw-r--r-- | src/common/include/gudhi/distance_functions.h | 23 |
1 files changed, 13 insertions, 10 deletions
diff --git a/src/common/include/gudhi/distance_functions.h b/src/common/include/gudhi/distance_functions.h index 58a513e7..5c7f3d55 100644 --- a/src/common/include/gudhi/distance_functions.h +++ b/src/common/include/gudhi/distance_functions.h @@ -31,16 +31,19 @@ /** @brief Compute the Euclidean distance between two Points given by a range of coordinates. The points are assumed to * have the same dimension. */ -template< typename Filtration_value, typename Point > -Filtration_value euclidean_distance(const Point &p1, const Point &p2) { - Filtration_value dist = 0.; - auto it1 = p1.begin(); - auto it2 = p2.begin(); - for (; it1 != p1.end(); ++it1, ++it2) { - Filtration_value tmp = static_cast<double>(*it1) - static_cast<double>(*it2); - dist += tmp*tmp; +class Euclidean_distance { + public: + template< typename Point > + auto operator()(const Point& p1, const Point& p2) -> typename Point::value_type { + auto it1 = p1.begin(); + auto it2 = p2.begin(); + typename Point::value_type dist = 0.; + for (; it1 != p1.end(); ++it1, ++it2) { + typename Point::value_type tmp = (*it1) - (*it2); + dist += tmp*tmp; + } + return std::sqrt(dist); } - return std::sqrt(dist); -} +}; #endif // DISTANCE_FUNCTIONS_H_ |