summaryrefslogtreecommitdiffstats
path: root/include/framework/RecordInterface.h
diff options
context:
space:
mode:
authorDouglas Rumbaugh <dbr4@psu.edu>2023-07-17 13:50:42 -0400
committerDouglas Rumbaugh <dbr4@psu.edu>2023-07-17 13:50:42 -0400
commit99d957ea185c3641e407b73a757bc9e2b5673686 (patch)
treebb33917884aba70f628f1544cc3302cd20b9f4af /include/framework/RecordInterface.h
parentc4a1b596483b494ead45755dca1805cae6b5615c (diff)
downloaddynamic-extension-99d957ea185c3641e407b73a757bc9e2b5673686.tar.gz
VPTree: changed Point format to a D-dimensional point.
Diffstat (limited to 'include/framework/RecordInterface.h')
-rw-r--r--include/framework/RecordInterface.h30
1 files changed, 24 insertions, 6 deletions
diff --git a/include/framework/RecordInterface.h b/include/framework/RecordInterface.h
index ab4c6f9..a3f6814 100644
--- a/include/framework/RecordInterface.h
+++ b/include/framework/RecordInterface.h
@@ -100,22 +100,40 @@ struct WeightedRecord {
}
};
-template <typename V>
+template <typename V, size_t D=2>
struct Point{
- V x;
- V y;
+ V data[D];
inline bool operator==(const Point& other) const {
- return x == other.x && y == other.y;
+ for (size_t i=0; i<D; i++) {
+ if (data[i] != other.data[i]) {
+ return false;
+ }
+ }
+
+ return true;
}
// lexicographic order
inline bool operator<(const Point& other) const {
- return x < other.x || (x == other.x && y < other.y);
+ for (size_t i=0; i<D; i++) {
+ if (data[i] < other.data[i]) {
+ return true;
+ } else if (data[i] > other.data[i]) {
+ return false;
+ }
+ }
+
+ return false;
}
inline double calc_distance(const Point& other) const {
- return sqrt(pow(x - other.x, 2) + pow(y - other.y, 2));
+ double dist = 0;
+ for (size_t i=0; i<D; i++) {
+ dist += pow(data[i] - other.data[i], 2);
+ }
+
+ return sqrt(dist);
}
};