rename line to ray

This commit is contained in:
Danny Robson 2015-03-11 22:31:35 +11:00
parent 98312c2c37
commit 4e3d67185c
4 changed files with 24 additions and 24 deletions

View File

@ -88,8 +88,6 @@ UTIL_FILES = \
json/tree.hpp \ json/tree.hpp \
lerp.cpp \ lerp.cpp \
lerp.hpp \ lerp.hpp \
line.cpp \
line.hpp \
log.cpp \ log.cpp \
log.hpp \ log.hpp \
log.ipp \ log.ipp \
@ -150,6 +148,8 @@ UTIL_FILES = \
range.ipp \ range.ipp \
rational.cpp \ rational.cpp \
rational.hpp \ rational.hpp \
ray.cpp \
ray.hpp \
region.cpp \ region.cpp \
region.hpp \ region.hpp \
si.cpp \ si.cpp \
@ -254,7 +254,7 @@ TEST_BIN = \
test/hton \ test/hton \
test/ip \ test/ip \
test/json_types \ test/json_types \
test/line \ test/ray \
test/maths \ test/maths \
test/maths_matrix \ test/maths_matrix \
test/matrix \ test/matrix \

View File

@ -17,14 +17,14 @@
* Copyright 2015 Danny Robson <danny@nerdcruft.net> * Copyright 2015 Danny Robson <danny@nerdcruft.net>
*/ */
#include "line.hpp" #include "ray.hpp"
#include "debug.hpp" #include "debug.hpp"
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T> template <size_t S, typename T>
util::line<S,T>::line (util::point<S,T> _p, util::ray<S,T>::ray (util::point<S,T> _p,
util::vector<S,T> _d): util::vector<S,T> _d):
p (_p), p (_p),
d (_d) d (_d)
@ -34,13 +34,13 @@ util::line<S,T>::line (util::point<S,T> _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 inf if parallel
/// returns 0 if colinear /// returns 0 if corayar
template <size_t S, typename T> template <size_t S, typename T>
T T
util::line<S,T>::intersect (plane<S,T> q) const util::ray<S,T>::intersect (plane<S,T> q) const
{ {
return dot (q.p - p, q.n) / dot (d, q.n); return dot (q.p - p, q.n) / dot (d, q.n);
} }
@ -53,7 +53,7 @@ util::line<S,T>::intersect (plane<S,T> q) const
/// returns -ve if behind /// returns -ve if behind
template <size_t S, typename T> template <size_t S, typename T>
T T
util::line<S,T>::intersect (AABB<S,T> r) const util::ray<S,T>::intersect (AABB<S,T> r) const
{ {
auto t1 = (r.p0 - p) / d; auto t1 = (r.p0 - p) / d;
auto t2 = (r.p1 - p) / d; auto t2 = (r.p1 - p) / d;
@ -75,10 +75,10 @@ util::line<S,T>::intersect (AABB<S,T> 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 <size_t S, typename T> template <size_t S, typename T>
T T
util::line<S,T>::closest (point<S,T> q) const util::ray<S,T>::closest (point<S,T> q) const
{ {
// project the origin-point difference onto the direction // project the origin-point difference onto the direction
return dot (p - q, d); return dot (p - q, d);
@ -88,12 +88,12 @@ util::line<S,T>::closest (point<S,T> q) const
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template <size_t S, typename T> template <size_t S, typename T>
util::point<S,T> util::point<S,T>
util::line<S,T>::at (T t) const util::ray<S,T>::at (T t) const
{ {
return p + d * t; return p + d * t;
} }
//----------------------------------------------------------------------------- //-----------------------------------------------------------------------------
template struct util::line<2,float>; template struct util::ray<2,float>;
template struct util::line<3,float>; template struct util::ray<3,float>;

View File

@ -17,8 +17,8 @@
* Copyright 2015 Danny Robson <danny@nerdcruft.net> * Copyright 2015 Danny Robson <danny@nerdcruft.net>
*/ */
#ifndef __UTIL_LINE_HPP #ifndef __UTIL_RAY_HPP
#define __UTIL_LINE_HPP #define __UTIL_RAY_HPP
#include "point.hpp" #include "point.hpp"
#include "vector.hpp" #include "vector.hpp"
@ -27,8 +27,8 @@
namespace util { namespace util {
template <size_t S, typename T> template <size_t S, typename T>
struct line { struct ray {
line (util::point<S,T> origin, ray (util::point<S,T> origin,
util::vector<S,T> direction); util::vector<S,T> direction);
T intersect (plane<S,T>) const; T intersect (plane<S,T>) const;
@ -43,8 +43,8 @@ namespace util {
}; };
typedef line<2,float> line2f; typedef ray<2,float> ray2f;
typedef line<3,float> line3f; typedef ray<3,float> ray3f;
} }
#endif #endif

View File

@ -1,4 +1,4 @@
#include "line.hpp" #include "ray.hpp"
#include "plane.hpp" #include "plane.hpp"
#include "debug.hpp" #include "debug.hpp"
#include "aabb.hpp" #include "aabb.hpp"
@ -7,8 +7,8 @@
void void
test_intersect_plane (void) test_intersect_plane (void)
{ {
// trivial case: origin line facing z, plane at unit z facing -z. // trivial case: origin ray facing z, plane at unit z facing -z.
util::line3f l ({0,0,0}, {0,0, 1}); util::ray3f l ({0,0,0}, {0,0, 1});
util::plane3f p ({0,0,1}, {0,0,-1}); util::plane3f p ({0,0,1}, {0,0,-1});
CHECK_EQ (l.intersect (p), 1); CHECK_EQ (l.intersect (p), 1);
@ -24,7 +24,7 @@ test_intersect_aabb (void)
{ 1.f, 1.f } { 1.f, 1.f }
}; };
util::line2f l { util::ray2f l {
{ 0.5f, -0.5f }, { 0.5f, -0.5f },
{ 0.f, 1.f } { 0.f, 1.f }
}; };