aboutsummaryrefslogtreecommitdiff
path: root/src/shared/math/coords.cc
diff options
context:
space:
mode:
authorNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 21:57:46 +1100
committerNicolas James <Eele1Ephe7uZahRie@tutanota.com>2025-02-12 21:57:46 +1100
commite4483eca01b48b943cd0461e24a74ae1a3139ed4 (patch)
treeed58c3c246e3af1af337697695d780aa31f6ad9a /src/shared/math/coords.cc
parent1cc08c51eb4b0f95c30c0a98ad1fc5ad3459b2df (diff)
Update to most recent version (old initial commit)
Diffstat (limited to 'src/shared/math/coords.cc')
-rw-r--r--src/shared/math/coords.cc30
1 files changed, 30 insertions, 0 deletions
diff --git a/src/shared/math/coords.cc b/src/shared/math/coords.cc
new file mode 100644
index 0000000..37fb19a
--- /dev/null
+++ b/src/shared/math/coords.cc
@@ -0,0 +1,30 @@
+#include "shared/math/coords.hh"
+
+namespace shared {
+namespace math {
+
+bool coords::is_inside_draw(const coords& a, const coords& b,
+ const std::int32_t draw_distance) noexcept {
+ const auto x2 = (a.x - b.x) * (a.x - b.x);
+ const auto z2 = (a.z - b.z) * (a.z - b.z);
+ const auto dd2 = draw_distance * draw_distance;
+
+ return (x2 < dd2 - z2) && (z2 < dd2 - x2);
+}
+
+coords coords::operator+(const coords& c) const noexcept {
+ auto ret = *this;
+ ret.x += c.x;
+ ret.z += c.z;
+ return ret;
+}
+
+coords coords::operator-(const coords& c) const noexcept {
+ auto ret = *this;
+ ret.x -= c.x;
+ ret.z -= c.z;
+ return ret;
+}
+
+} // namespace math
+} // namespace shared