From ca276ca5471a4e7a137f68a81feb150282eae62f Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 7 Feb 2024 23:50:50 +0000 Subject: Add stripiter A generic iterator wrapper returning a tuple of 3 references to the original values, as processed in the fashion of an OpenGL triangle strip. --- lib/collections.h | 60 +++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 60 insertions(+) (limited to 'lib') diff --git a/lib/collections.h b/lib/collections.h index 943b986..6cee10c 100644 --- a/lib/collections.h +++ b/lib/collections.h @@ -2,6 +2,7 @@ #include #include +#include #include #include #include @@ -160,3 +161,62 @@ template struct pair_range { }; template pair_range(std::pair) -> pair_range; + +template struct stripiter { + [[nodiscard]] constexpr bool + operator!=(const stripiter & other) const + { + return current != other.current; + } + + [[nodiscard]] constexpr bool + operator==(const stripiter & other) const + { + return current == other.current; + } + + constexpr stripiter & + operator++() + { + ++current; + off = 1 - off; + return *this; + } + + constexpr stripiter & + operator--() + { + --current; + off = 1 - off; + return *this; + } + + constexpr auto + operator-(const stripiter & other) const + { + return current - other.current; + } + + constexpr auto + operator*() const + { + return std::tie(*(current - (2 - off)), *(current - off - 1), *current); + } + + iter current; + uint8_t off {}; +}; + +template struct std::iterator_traits> : std::iterator_traits { }; + +constexpr auto +strip_begin(IterableCollection auto & cont) +{ + return stripiter {cont.begin() + 2}; +} + +constexpr auto +strip_end(IterableCollection auto & cont) +{ + return stripiter {cont.end()}; +} -- cgit v1.2.3 From fa48542d7387ba376b56dc4f60f90fccbd037f92 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 12 Feb 2024 20:28:50 +0000 Subject: Cast relative position accordingly in geometric plane --- lib/geometricPlane.h | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) (limited to 'lib') diff --git a/lib/geometricPlane.h b/lib/geometricPlane.h index 3f95d3c..3b1a0e4 100644 --- a/lib/geometricPlane.h +++ b/lib/geometricPlane.h @@ -27,7 +27,7 @@ public: [[nodiscard]] inline PlaneRelation getRelation(PositionType point) const { - const auto d = glm::dot(normal, point - origin); + const auto d = glm::dot(normal, RelativePosition3D(point - origin)); return d < 0.F ? PlaneRelation::Below : d > 0.F ? PlaneRelation::Above : PlaneRelation::On; } -- cgit v1.2.3 From 40f5a59dba7d5061821e143cebcfa30f6faa9464 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Mon, 12 Feb 2024 20:32:01 +0000 Subject: Add materializeRange override for naked iterator pair --- lib/collections.h | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) (limited to 'lib') diff --git a/lib/collections.h b/lib/collections.h index 6cee10c..dd603be 100644 --- a/lib/collections.h +++ b/lib/collections.h @@ -130,18 +130,25 @@ vectorOfN(std::integral auto N, T start = {}, T step = 1) return v; } +template typename Rtn = std::vector, typename In> +[[nodiscard]] auto +materializeRange(const In begin, const In end) +{ + return Rtn(begin, end); +} + template typename Rtn = std::vector, IterableCollection In> [[nodiscard]] auto -materializeRange(In && in) +materializeRange(const In & in) { - return Rtn(in.begin(), in.end()); + return materializeRange(in.begin(), in.end()); } template typename Rtn = std::vector, typename In> [[nodiscard]] auto materializeRange(const std::pair & in) { - return Rtn(in.first, in.second); + return materializeRange(in.first, in.second); } template struct pair_range { -- cgit v1.2.3 From 861c046ed527474a18a1358246a818ce70bb0b75 Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Wed, 14 Feb 2024 02:07:04 +0000 Subject: Check ray intersects triangle 'in front' of start --- lib/ray.h | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) (limited to 'lib') diff --git a/lib/ray.h b/lib/ray.h index e1f43c3..67fdd12 100644 --- a/lib/ray.h +++ b/lib/ray.h @@ -47,11 +47,11 @@ public: RelativeDistance & distance) const { if constexpr (std::is_floating_point_v) { - return glm::intersectRayTriangle(start, direction, t0, t1, t2, bary, distance); + return glm::intersectRayTriangle(start, direction, t0, t1, t2, bary, distance) && distance >= 0.F; } else { const RelativePosition3D t0r = t0 - start, t1r = t1 - start, t2r = t2 - start; - return glm::intersectRayTriangle({}, direction, t0r, t1r, t2r, bary, distance); + return glm::intersectRayTriangle({}, direction, t0r, t1r, t2r, bary, distance) && distance >= 0.F; } } -- cgit v1.2.3