1 #ifndef MSP_GEOMETRY_RAY_H_
2 #define MSP_GEOMETRY_RAY_H_
5 #include <msp/linal/vector.h>
11 A directed line segment. Can be used to point at things.
13 template<typename T, unsigned D>
17 LinAl::Vector<T, D> start;
18 LinAl::Vector<T, D> direction;
23 Ray(const LinAl::Vector<T, D> &, const LinAl::Vector<T, D> &);
24 Ray(const LinAl::Vector<T, D> &, const LinAl::Vector<T, D> &, T);
26 const LinAl::Vector<T, D> &get_start() const { return start; }
27 const LinAl::Vector<T, D> &get_direction() const { return direction; }
28 T get_limit() const { return limit; }
29 bool check_limits(T) const;
32 template<typename T, unsigned D>
33 inline Ray<T, D>::Ray():
39 template<typename T, unsigned D>
40 inline Ray<T, D>::Ray(const LinAl::Vector<T, D> &s, const LinAl::Vector<T, D> &d):
42 direction(normalize(d)),
46 template<typename T, unsigned D>
47 inline Ray<T, D>::Ray(const LinAl::Vector<T, D> &s, const LinAl::Vector<T, D> &d, T l):
49 direction(normalize(d)),
53 throw std::invalid_argument("Ray::Ray");
56 template<typename T, unsigned D>
57 inline bool Ray<T, D>::check_limits(T x) const
59 return x>=T(0) && (!limit || x<=limit);
62 } // namespace Geometry