diff --git a/geom/ray.hpp b/geom/ray.hpp index dc782d93..e87785ff 100644 --- a/geom/ray.hpp +++ b/geom/ray.hpp @@ -27,22 +27,6 @@ namespace util::geom { template struct ray { - constexpr ray () = default; - - constexpr ray (point _origin, vector _direction) noexcept: - origin (_origin), - direction (_direction) - { - CHECK (is_normalised (direction)); - } - - constexpr ray (point _origin, point _distant) noexcept: - ray (_origin, _origin.to (_distant )) - { - CHECK (is_normalised (direction)); - } - - // queries T closest (point) const; @@ -80,6 +64,8 @@ namespace util::geom { constexpr T distance (const ray r, const plane p) { + CHECK_SANITY (r); + return dot (p.coefficients, r.origin. template redim (1)) / dot (p.coefficients, r.direction.template redim (0)); @@ -105,6 +91,8 @@ namespace util::geom { constexpr T distance (const ray r, const aabb b) { + CHECK_SANITY (r); + const auto t1 = (b.lo - r.origin) / r.direction; const auto t2 = (b.hi - r.origin) / r.direction; diff --git a/test/geom/ray.cpp b/test/geom/ray.cpp index 164d3885..7209d988 100644 --- a/test/geom/ray.cpp +++ b/test/geom/ray.cpp @@ -1,7 +1,8 @@ -#include "../../geom/aabb.hpp" -#include "../../geom/plane.hpp" -#include "../../geom/ray.hpp" -#include "../../tap.hpp" +#include "geom/aabb.hpp" +#include "geom/plane.hpp" +#include "geom/ray.hpp" +#include "geom/iostream.hpp" +#include "tap.hpp" using util::geom::ray2f; using util::geom::ray3f; @@ -12,7 +13,7 @@ void test_intersect_plane (util::TAP::logger &tap) { // trivial case: origin ray facing z, plane at unit z facing -z. - const util::geom::ray3f l (util::point3f {0,0,0}, util::vector3f {0,0, 1}); + const util::geom::ray3f l { .origin = 0, .direction = {0, 0, 1} }; const util::geom::plane3f p (util::point3f {0,0,1}, util::vector3f {0,0,-1}); tap.expect_eq (distance (l, p), 1.f, "ray-plane intersect");