geom/ray: remove constructors so we have a POD

This commit is contained in:
Danny Robson 2018-04-16 15:57:54 +10:00
parent ce246f8aa2
commit a8b3737b8b
2 changed files with 10 additions and 21 deletions

View File

@ -27,22 +27,6 @@
namespace util::geom { namespace util::geom {
template <size_t S, typename T> template <size_t S, typename T>
struct ray { struct ray {
constexpr ray () = default;
constexpr ray (point<S,T> _origin, vector<S,T> _direction) noexcept:
origin (_origin),
direction (_direction)
{
CHECK (is_normalised (direction));
}
constexpr ray (point<S,T> _origin, point <S,T> _distant) noexcept:
ray (_origin, _origin.to (_distant ))
{
CHECK (is_normalised (direction));
}
// queries // queries
T closest (point<S,T>) const; T closest (point<S,T>) const;
@ -80,6 +64,8 @@ namespace util::geom {
constexpr T constexpr T
distance (const ray<S,T> r, const plane<S,T> p) distance (const ray<S,T> r, const plane<S,T> p)
{ {
CHECK_SANITY (r);
return dot (p.coefficients, r.origin. template redim<S+1> (1)) / return dot (p.coefficients, r.origin. template redim<S+1> (1)) /
dot (p.coefficients, r.direction.template redim<S+1> (0)); dot (p.coefficients, r.direction.template redim<S+1> (0));
@ -105,6 +91,8 @@ namespace util::geom {
constexpr T constexpr T
distance (const ray<S,T> r, const aabb<S,T> b) distance (const ray<S,T> r, const aabb<S,T> b)
{ {
CHECK_SANITY (r);
const auto t1 = (b.lo - r.origin) / r.direction; const auto t1 = (b.lo - r.origin) / r.direction;
const auto t2 = (b.hi - r.origin) / r.direction; const auto t2 = (b.hi - r.origin) / r.direction;

View File

@ -1,7 +1,8 @@
#include "../../geom/aabb.hpp" #include "geom/aabb.hpp"
#include "../../geom/plane.hpp" #include "geom/plane.hpp"
#include "../../geom/ray.hpp" #include "geom/ray.hpp"
#include "../../tap.hpp" #include "geom/iostream.hpp"
#include "tap.hpp"
using util::geom::ray2f; using util::geom::ray2f;
using util::geom::ray3f; using util::geom::ray3f;
@ -12,7 +13,7 @@ void
test_intersect_plane (util::TAP::logger &tap) test_intersect_plane (util::TAP::logger &tap)
{ {
// trivial case: origin ray facing z, plane at unit z facing -z. // 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}); 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"); tap.expect_eq (distance (l, p), 1.f, "ray-plane intersect");