diff --git a/Makefile.am b/Makefile.am index a430e5e4..c06d01a0 100644 --- a/Makefile.am +++ b/Makefile.am @@ -88,8 +88,6 @@ UTIL_FILES = \ json/tree.hpp \ lerp.cpp \ lerp.hpp \ - line.cpp \ - line.hpp \ log.cpp \ log.hpp \ log.ipp \ @@ -150,6 +148,8 @@ UTIL_FILES = \ range.ipp \ rational.cpp \ rational.hpp \ + ray.cpp \ + ray.hpp \ region.cpp \ region.hpp \ si.cpp \ @@ -254,7 +254,7 @@ TEST_BIN = \ test/hton \ test/ip \ test/json_types \ - test/line \ + test/ray \ test/maths \ test/maths_matrix \ test/matrix \ diff --git a/line.cpp b/ray.cpp similarity index 82% rename from line.cpp rename to ray.cpp index 857b8934..b3f9661e 100644 --- a/line.cpp +++ b/ray.cpp @@ -17,14 +17,14 @@ * Copyright 2015 Danny Robson */ -#include "line.hpp" +#include "ray.hpp" #include "debug.hpp" //----------------------------------------------------------------------------- template -util::line::line (util::point _p, +util::ray::ray (util::point _p, util::vector _d): p (_p), d (_d) @@ -34,13 +34,13 @@ util::line::line (util::point _p, ///---------------------------------------------------------------------------- -/// returns the distance along the line in a line-plane intersection +/// returns the distance along the ray in a ray-plane intersection /// /// returns inf if parallel -/// returns 0 if colinear +/// returns 0 if corayar template T -util::line::intersect (plane q) const +util::ray::intersect (plane q) const { return dot (q.p - p, q.n) / dot (d, q.n); } @@ -53,7 +53,7 @@ util::line::intersect (plane q) const /// returns -ve if behind template T -util::line::intersect (AABB r) const +util::ray::intersect (AABB r) const { auto t1 = (r.p0 - p) / d; auto t2 = (r.p1 - p) / d; @@ -75,10 +75,10 @@ util::line::intersect (AABB r) const ///---------------------------------------------------------------------------- -/// returns the closest parameter along the line to a given point +/// returns the closest parameter along the ray to a given point template T -util::line::closest (point q) const +util::ray::closest (point q) const { // project the origin-point difference onto the direction return dot (p - q, d); @@ -88,12 +88,12 @@ util::line::closest (point q) const //----------------------------------------------------------------------------- template util::point -util::line::at (T t) const +util::ray::at (T t) const { return p + d * t; } //----------------------------------------------------------------------------- -template struct util::line<2,float>; -template struct util::line<3,float>; +template struct util::ray<2,float>; +template struct util::ray<3,float>; diff --git a/line.hpp b/ray.hpp similarity index 86% rename from line.hpp rename to ray.hpp index 99f45bff..e8ac7632 100644 --- a/line.hpp +++ b/ray.hpp @@ -17,8 +17,8 @@ * Copyright 2015 Danny Robson */ -#ifndef __UTIL_LINE_HPP -#define __UTIL_LINE_HPP +#ifndef __UTIL_RAY_HPP +#define __UTIL_RAY_HPP #include "point.hpp" #include "vector.hpp" @@ -27,8 +27,8 @@ namespace util { template - struct line { - line (util::point origin, + struct ray { + ray (util::point origin, util::vector direction); T intersect (plane) const; @@ -43,8 +43,8 @@ namespace util { }; - typedef line<2,float> line2f; - typedef line<3,float> line3f; + typedef ray<2,float> ray2f; + typedef ray<3,float> ray3f; } #endif diff --git a/test/line.cpp b/test/ray.cpp similarity index 77% rename from test/line.cpp rename to test/ray.cpp index 76b497f5..f17e8516 100644 --- a/test/line.cpp +++ b/test/ray.cpp @@ -1,4 +1,4 @@ -#include "line.hpp" +#include "ray.hpp" #include "plane.hpp" #include "debug.hpp" #include "aabb.hpp" @@ -7,8 +7,8 @@ void test_intersect_plane (void) { - // trivial case: origin line facing z, plane at unit z facing -z. - util::line3f l ({0,0,0}, {0,0, 1}); + // trivial case: origin ray facing z, plane at unit z facing -z. + util::ray3f l ({0,0,0}, {0,0, 1}); util::plane3f p ({0,0,1}, {0,0,-1}); CHECK_EQ (l.intersect (p), 1); @@ -24,7 +24,7 @@ test_intersect_aabb (void) { 1.f, 1.f } }; - util::line2f l { + util::ray2f l { { 0.5f, -0.5f }, { 0.f, 1.f } };