diff options
Diffstat (limited to 'include/framework/RecordInterface.h')
| -rw-r--r-- | include/framework/RecordInterface.h | 30 |
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); } }; |