Virtual Testbed
Ship dynamics simulator for extreme conditions
ray.hh
1 #ifndef VTESTBED_GEOMETRY_RAY_HH
2 #define VTESTBED_GEOMETRY_RAY_HH
3 
4 #include <ostream>
5 
6 #include <vtestbed/geometry/types.hh>
7 
8 namespace vtb {
9 
10  namespace geometry {
11 
12  template <class T, int N>
13  class Ray {
14 
15  public:
16  static constexpr const int dimensions = N;
17  using scalar_type = T;
18  using value_type = Vertex<T,N>;
19  using reference = value_type&;
20  using const_reference = const value_type&;
21 
22  private:
23  value_type _origin{T{}};
24  value_type _direction{T{}};
25 
26  public:
27 
28  Ray() = default;
29  Ray(const Ray&) = default;
30  Ray& operator=(const Ray&) = default;
31  Ray(Ray&&) = default;
32  Ray& operator=(Ray&&) = default;
33  ~Ray() = default;
34 
35  inline explicit
36  Ray(const_reference origin, const_reference direction):
37  _origin(origin),
38  _direction(direction) {}
39 
40  inline const_reference
41  origin() const noexcept {
42  return this->_origin;
43  }
44 
45  inline const_reference
46  direction() const noexcept {
47  return this->_direction;
48  }
49 
50  inline void
51  invert() {
52  this->_direction = -this->_direction;
53  }
54 
55  inline bool
56  contains(const value_type& c, T eps) const {
57  value_type ca = c-origin();
58  return !any(abs(cross(ca,direction())) > eps);
59  }
60 
61  inline friend std::ostream&
62  operator<<(std::ostream& out, const Ray& rhs) {
63  return out << rhs.origin() << ' ' << rhs.direction();
64  }
65 
66  };
67 
68  }
69 
70 }
71 
72 #endif // vim:filetype=cpp
Main namespace.
Definition: convert.hh:9