X-Git-Url: http://git.tdb.fi/?p=libs%2Fmath.git;a=blobdiff_plain;f=source%2Fgeometry%2Fray.h;h=99f447bcd62edc2a640039d1ad7ad1eea54bb8c2;hp=4825cfe005d3c6cc762dae62800f38899f8c8500;hb=24f239e418599c13a9d0bdc4942c188ccf0a8437;hpb=c135ff2480f4e2aaf05b0206631bb0e1b5d73fad diff --git a/source/geometry/ray.h b/source/geometry/ray.h index 4825cfe..99f447b 100644 --- a/source/geometry/ray.h +++ b/source/geometry/ray.h @@ -1,6 +1,7 @@ #ifndef MSP_GEOMETRY_RAY_H_ #define MSP_GEOMETRY_RAY_H_ +#include #include namespace Msp { @@ -12,27 +13,49 @@ 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; } 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<0) + throw std::invalid_argument("Ray::Ray"); +} + +template +inline bool Ray::check_limits(T x) const +{ + return x>=0 && (!limit || x<=limit); +} + } // namespace Geometry } // namespace Msp