From 335e9c6b4bbc5bbf1a861ac16abf612f5519dd5e Mon Sep 17 00:00:00 2001 From: Dan Goodliffe Date: Fri, 5 Jan 2024 20:20:14 +0000 Subject: Template GeometicPlane on Position type --- lib/geometricPlane.cpp | 8 ++++++++ lib/geometricPlane.h | 23 +++++++++++------------ 2 files changed, 19 insertions(+), 12 deletions(-) create mode 100644 lib/geometricPlane.cpp (limited to 'lib') diff --git a/lib/geometricPlane.cpp b/lib/geometricPlane.cpp new file mode 100644 index 0000000..7aadf6a --- /dev/null +++ b/lib/geometricPlane.cpp @@ -0,0 +1,8 @@ +#include "geometricPlane.h" + +bool +GeometricPlane::isIntersect(PlaneRelation a, PlaneRelation b) +{ + return ((a == PlaneRelation::Above && b == PlaneRelation::Below) + || (a == PlaneRelation::Below && b == PlaneRelation::Above)); +} diff --git a/lib/geometricPlane.h b/lib/geometricPlane.h index 5be76ec..fd3a1d7 100644 --- a/lib/geometricPlane.h +++ b/lib/geometricPlane.h @@ -8,18 +8,24 @@ #include class GeometricPlane { +public: + enum class PlaneRelation { Above, Below, On }; + + static bool isIntersect(PlaneRelation a, PlaneRelation b); +}; + +template class GeometricPlaneT : public GeometricPlane { public: struct DistAndPosition { - float dist; - Position3D position; + PositionType::value_type dist; + PositionType position; }; - enum class PlaneRelation { Above, Below, On }; - Position3D origin; + PositionType origin; Normal3D normal; [[nodiscard]] inline PlaneRelation - getRelation(Position3D point) const + getRelation(PositionType point) const { const auto d = glm::dot(normal, point - origin); return d < 0.F ? PlaneRelation::Below : d > 0.F ? PlaneRelation::Above : PlaneRelation::On; @@ -34,11 +40,4 @@ public: } return DistAndPosition {dist, ray.start + (ray.direction * dist)}; } - - inline static bool - isIntersect(PlaneRelation a, PlaneRelation b) - { - return ((a == PlaneRelation::Above && b == PlaneRelation::Below) - || (a == PlaneRelation::Below && b == PlaneRelation::Above)); - } }; -- cgit v1.2.3