#pragma once #include #include #include "point.hpp" namespace kd { namespace math { using byte = unsigned char; // returns the squared distance between two points template T distance_sq(const Point& a, const Point& b) { auto dx = a.longitude - b.longitude; auto dy = a.latitude - b.latitude; return dx * dx + dy * dy; } // returns the distance between two points template T distance(const Point& a, const Point& b) { return std::sqrt(distance_sq(a, b)); } // returns the distance between two points looking at a specific axis // \param axis 0 if abscissa else 1 if ordinate template T axial_distance(const Point& a, const Point& b, byte axis) { return axis == 0 ? a.longitude - b.longitude : a.latitude - b.latitude; } } }