summaryrefslogtreecommitdiffhomepage
path: root/src/point.cpp
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-03-03 08:06:16 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-03-04 06:58:10 +0100
commit89d90859bd9a6788528ca2b6dec342d22ccfb925 (patch)
treed9cdae53e2251348dc005ddeafe9c58d24629f28 /src/point.cpp
parent4026dde896c0935b7f31a44db62058031d2de3c5 (diff)
src: add point distance tests
Diffstat (limited to 'src/point.cpp')
-rw-r--r--src/point.cpp29
1 files changed, 28 insertions, 1 deletions
diff --git a/src/point.cpp b/src/point.cpp
index 3e970ba3..7b810fca 100644
--- a/src/point.cpp
+++ b/src/point.cpp
@@ -1,5 +1,6 @@
-#include "point.hpp"
#include "compat/int-hash.hpp"
+#include "point.inl"
+#include "tile-constants.hpp"
namespace floormat {
@@ -35,4 +36,30 @@ Debug& operator<<(Debug& dbg, const point& pt)
return dbg;
}
+namespace {
+
+constexpr auto chunk_size = iTILE_SIZE2 * TILE_MAX_DIM;
+
+static_assert(point::distance_l2(
+ point{{ 1, 2, 0}, {3, 4}, {32, 32}},
+ point{{ 0, 0, 0}, {0, 0}, {32, 32}}
+) == (uint32_t)Math::abs((Vector2i(1, 2)*chunk_size + Vector2i{3, 4} * iTILE_SIZE2 + Vector2i{0, 0}).sum()));
+
+static_assert(point::distance_l2(
+ point{{ 0, 0, 0}, {0, 0}, {30, 30}},
+ point{{ 1, 2, 0}, {3, 4}, {31, 31}}
+) == (uint32_t)Math::abs((Vector2i(1, 2)*chunk_size + Vector2i{3, 4} * iTILE_SIZE2 + Vector2i{1, 1}).sum()));
+
+static_assert(point::distance_l2(
+ point{{ 2, 3, 0}, {4, 5}, {32, 32}},
+ point{{ 1, 2, 0}, {3, 4}, {31, 31}}
+) == (uint32_t)Math::abs((Vector2i(1, 1)*chunk_size + Vector2i{1, 1} * iTILE_SIZE2 + Vector2i{1, 1}).sum()));
+
+static_assert(point::distance_l2(
+ point{{ 1, 2, 0}, {3, 4}, {31, 31}},
+ point{{ 2, 3, 0}, {4, 5}, {32, 32}}
+) == (uint32_t)Math::abs((Vector2i(1, 1)*chunk_size + Vector2i{1, 1} * iTILE_SIZE2 + Vector2i{1, 1}).sum()));
+
+} // namespace
+
} // namespace floormat