summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2024-03-21 14:24:01 +0100
committerStanislaw Halik <sthalik@misaki.pl>2024-03-21 17:19:58 +0100
commit89cdca0583c0fee6ce5cc5617b275446ee829d6b (patch)
tree7e39950a1056fc7c009365ac3b9a6fac666caed1
parent0152ed8f2704ae4e77df98ea908835f436535335 (diff)
point wip
-rw-r--r--src/point.cpp27
-rw-r--r--src/point.hpp2
2 files changed, 24 insertions, 5 deletions
diff --git a/src/point.cpp b/src/point.cpp
index 7b810fca..1c62b2ad 100644
--- a/src/point.cpp
+++ b/src/point.cpp
@@ -38,27 +38,44 @@ Debug& operator<<(Debug& dbg, const point& pt)
namespace {
-constexpr auto chunk_size = iTILE_SIZE2 * TILE_MAX_DIM;
+constexpr auto Ch = 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()));
+) == (uint32_t)Math::abs((Vector2i(1, 2)*Ch + 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()));
+) == (uint32_t)Math::abs((Vector2i(1, 2)*Ch + 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()));
+) == (uint32_t)Math::abs((Vector2i(1, 1)*Ch + 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()));
+) == (uint32_t)Math::abs((Vector2i(1, 1)*Ch + Vector2i{1, 1} * iTILE_SIZE2 + Vector2i{1, 1}).sum()));
+
+namespace krap {
+
+constexpr auto T = iTILE_SIZE2;
+using V2 = Vector2i;
+using P = point;
+
+static_assert(P{{}, {}, {}} - P{{}, {}, {}} == V2{});
+static_assert(P{{}, {}, {}} - P{{}, {1, 0}, {}} == T * V2{-1, 0} );
+static_assert(P{{}, {2, 3}, {}} - P{{}, {4, 6}, {}} == T * V2{-2, -3} );
+static_assert(P{{}, {6, 4}, {}} - P{{}, {2, 3}, {}} == T * V2{4, 1} );
+static_assert(P{{7, 8, 0}, {6, 4}, {}} - P{{}, {2, 3}, {}} == T * V2{4, 1} + Ch * V2{7, 8} );
+static_assert(P{{7, 8, 0}, {6, 4}, {}} - P{{9, -11, 0}, {2, 3}, {}} == T * V2{4, 1} + Ch * V2{-2, 19} );
+static_assert(P{{7, 8, 1}, {6, 4}, {24, 16}} - P{{9, -11, 1}, {2, 3}, {-16, 24}} == T * V2{4, 1} + Ch * V2{-2, 19} + V2{40, -8} );
+
+} // namespace krap
+
} // namespace
diff --git a/src/point.hpp b/src/point.hpp
index 6d3caf72..285d2f30 100644
--- a/src/point.hpp
+++ b/src/point.hpp
@@ -38,6 +38,8 @@ struct point
static constexpr uint32_t distance(point a, point b);
static constexpr uint32_t distance_l2(point a, point b);
+ friend constexpr Vector2i operator-(const point& p1, const point& p2);
+
private:
int16_t cx = 0, cy = 0;
int8_t cz = 0;