Skip to content

Commit 519622c

Browse files
committed
Removed support for L2 due to updated query.
1 parent 8bfad6c commit 519622c

File tree

5 files changed

+44
-34
lines changed

5 files changed

+44
-34
lines changed

examples/pico_understory/CMakeLists.txt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ target_link_libraries(pico_understory INTERFACE PicoTree::PicoTree)
55
target_sources(pico_understory
66
INTERFACE
77
${CMAKE_CURRENT_LIST_DIR}/pico_understory/cover_tree.hpp
8+
${CMAKE_CURRENT_LIST_DIR}/pico_understory/metric.hpp
89
)

examples/pico_understory/pico_understory/cover_tree.hpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,10 @@
44
#include <numeric>
55
#include <pico_tree/internal/memory.hpp>
66
#include <pico_tree/internal/search_visitor.hpp>
7-
#include <pico_tree/metric.hpp>
87
#include <random>
98

9+
#include "metric.hpp"
10+
1011
// Use this define to enable a simplified version of the nearest ancestor tree
1112
// or disable it to use the regular one from "Faster Cover Trees".
1213
//
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
#pragma once
2+
3+
#include <pico_tree/metric.hpp>
4+
5+
namespace pico_tree {
6+
7+
//! \brief L2 metric for measuring Euclidean distances between points.
8+
//! \details https://en.wikipedia.org/wiki/Euclidean_distance
9+
//! \see L1
10+
template <typename Traits>
11+
class L2 {
12+
private:
13+
using Scalar = typename Traits::ScalarType;
14+
15+
public:
16+
//! \brief Calculates the distance between points \p p0 and \p p1.
17+
//! \tparam P0 Point type.
18+
//! \tparam P1 Point type.
19+
//! \param p0 Point.
20+
//! \param p1 Point.
21+
template <typename P0, typename P1>
22+
// The enable_if is not required but it forces implicit casts which are
23+
// handled by operator()(Scalar, Scalar).
24+
inline typename std::enable_if<
25+
!std::is_fundamental<P0>::value && !std::is_fundamental<P1>::value,
26+
Scalar>::type
27+
operator()(P0 const& p0, P1 const& p1) const {
28+
return std::sqrt(internal::Sum<Traits, internal::SqrdDiff>::Op(p0, p1));
29+
}
30+
31+
//! \brief Calculates the distance between two coordinates.
32+
inline Scalar operator()(Scalar const x, Scalar const y) const {
33+
return std::abs(x - y);
34+
}
35+
36+
//! \brief Returns the absolute value of \p x.
37+
inline Scalar operator()(Scalar const x) const { return std::abs(x); }
38+
};
39+
40+
} // namespace pico_tree

src/pico_tree/pico_tree/metric.hpp

Lines changed: 0 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -88,39 +88,6 @@ class L1 {
8888
inline Scalar operator()(Scalar const x) const { return std::abs(x); }
8989
};
9090

91-
//! \brief L2 metric for measuring Euclidean distances between points.
92-
//! \details https://en.wikipedia.org/wiki/Euclidean_distance
93-
//! \see L1
94-
template <typename Traits>
95-
class L2 {
96-
private:
97-
using Scalar = typename Traits::ScalarType;
98-
99-
public:
100-
//! \brief Calculates the distance between points \p p0 and \p p1.
101-
//! \tparam P0 Point type.
102-
//! \tparam P1 Point type.
103-
//! \param p0 Point.
104-
//! \param p1 Point.
105-
template <typename P0, typename P1>
106-
// The enable_if is not required but it forces implicit casts which are
107-
// handled by operator()(Scalar, Scalar).
108-
inline typename std::enable_if<
109-
!std::is_fundamental<P0>::value && !std::is_fundamental<P1>::value,
110-
Scalar>::type
111-
operator()(P0 const& p0, P1 const& p1) const {
112-
return std::sqrt(internal::Sum<Traits, internal::SqrdDiff>::Op(p0, p1));
113-
}
114-
115-
//! \brief Calculates the distance between two coordinates.
116-
inline Scalar operator()(Scalar const x, Scalar const y) const {
117-
return std::abs(x - y);
118-
}
119-
120-
//! \brief Returns the absolute value of \p x.
121-
inline Scalar operator()(Scalar const x) const { return std::abs(x); }
122-
};
123-
12491
//! \brief The L2Squared semimetric measures squared Euclidean distances between
12592
//! points. It does not satisfy the triangle inequality.
12693
//! \see L1

test/pico_tree/metric_test.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
#include <pico_toolshed/point.hpp>
44
#include <pico_tree/metric.hpp>
5+
#include <pico_understory/metric.hpp>
56

67
using PointX = Point2f;
78
using SpaceX = std::vector<PointX>;

0 commit comments

Comments
 (0)