X-Git-Url: http://git.tdb.fi/?a=blobdiff_plain;f=source%2Fgeometry%2Fray.h;h=d8eb7d8405ec75f799226572c5135d08260b978b;hb=2087c3bb9e6087ccce86360c1c57823aa8a9ff40;hp=4825cfe005d3c6cc762dae62800f38899f8c8500;hpb=6ff13022b53830d35283905d562c2ef3af198cc1;p=libs%2Fmath.git diff --git a/source/geometry/ray.h b/source/geometry/ray.h index 4825cfe..d8eb7d8 100644 --- a/source/geometry/ray.h +++ b/source/geometry/ray.h @@ -1,38 +1,64 @@ #ifndef MSP_GEOMETRY_RAY_H_ #define MSP_GEOMETRY_RAY_H_ +#include #include namespace Msp { namespace Geometry { +/** +A directed line segment. Can be used to point at things. +*/ template class Ray { private: LinAl::Vector start; LinAl::Vector direction; + T limit; public: Ray(); Ray(const LinAl::Vector &, const LinAl::Vector &); + Ray(const LinAl::Vector &, const LinAl::Vector &, T); const LinAl::Vector &get_start() const { return start; } const LinAl::Vector &get_direction() const { return direction; } + T get_limit() const { return limit; } + bool check_limits(T) const; }; template -Ray::Ray() +inline Ray::Ray(): + limit(0) { - direction[0] = 1; + direction[0] = T(1); } template -Ray::Ray(const LinAl::Vector &s, const LinAl::Vector &d): +inline Ray::Ray(const LinAl::Vector &s, const LinAl::Vector &d): start(s), - direction(normalize(d)) + direction(normalize(d)), + limit(0) { } +template +inline Ray::Ray(const LinAl::Vector &s, const LinAl::Vector &d, T l): + start(s), + direction(normalize(d)), + limit(l) +{ + if(l +inline bool Ray::check_limits(T x) const +{ + return x>=T(0) && (!limit || x<=limit); +} + } // namespace Geometry } // namespace Msp