GteRay.h
Go to the documentation of this file.
1 // David Eberly, Geometric Tools, Redmond WA 98052
2 // Copyright (c) 1998-2017
3 // Distributed under the Boost Software License, Version 1.0.
4 // http://www.boost.org/LICENSE_1_0.txt
5 // http://www.geometrictools.com/License/Boost/LICENSE_1_0.txt
6 // File Version: 3.0.0 (2016/06/19)
7 
8 #pragma once
9 
10 #include <Mathematics/GteVector.h>
11 
12 // The ray is represented as P+t*D, where P is the ray origin, D is a
13 // unit-length direction vector, and t >= 0. The user must ensure that D is
14 // unit length.
15 
16 namespace gte
17 {
18 
19 template <int N, typename Real>
20 class Ray
21 {
22 public:
23  // Construction and destruction. The default constructor sets the origin
24  // to (0,...,0) and the ray direction to (1,0,...,0).
25  Ray();
26  Ray(Vector<N, Real> const& inOrigin, Vector<N, Real> const& inDirection);
27 
28  // Public member access. The direction must be unit length.
30 
31 public:
32  // Comparisons to support sorted containers.
33  bool operator==(Ray const& ray) const;
34  bool operator!=(Ray const& ray) const;
35  bool operator< (Ray const& ray) const;
36  bool operator<=(Ray const& ray) const;
37  bool operator> (Ray const& ray) const;
38  bool operator>=(Ray const& ray) const;
39 };
40 
41 // Template aliases for convenience.
42 template <typename Real>
44 
45 template <typename Real>
47 
48 
49 template <int N, typename Real>
51 {
52  origin.MakeZero();
53  direction.MakeUnit(0);
54 }
55 
56 template <int N, typename Real>
58  Vector<N, Real> const& inDirection)
59  :
60  origin(inOrigin),
61  direction(inDirection)
62 {
63 }
64 
65 template <int N, typename Real>
66 bool Ray<N, Real>::operator==(Ray const& ray) const
67 {
68  return origin == ray.origin && direction == ray.direction;
69 }
70 
71 template <int N, typename Real>
72 bool Ray<N, Real>::operator!=(Ray const& ray) const
73 {
74  return !operator==(ray);
75 }
76 
77 template <int N, typename Real>
78 bool Ray<N, Real>::operator<(Ray const& ray) const
79 {
80  if (origin < ray.origin)
81  {
82  return true;
83  }
84 
85  if (origin > ray.origin)
86  {
87  return false;
88  }
89 
90  return direction < ray.direction;
91 }
92 
93 template <int N, typename Real>
94 bool Ray<N, Real>::operator<=(Ray const& ray) const
95 {
96  return operator<(ray) || operator==(ray);
97 }
98 
99 template <int N, typename Real>
100 bool Ray<N, Real>::operator>(Ray const& ray) const
101 {
102  return !operator<=(ray);
103 }
104 
105 template <int N, typename Real>
106 bool Ray<N, Real>::operator>=(Ray const& ray) const
107 {
108  return !operator<(ray);
109 }
110 
111 
112 }
Vector< N, Real > direction
Definition: GteRay.h:29
bool operator>(Ray const &ray) const
Definition: GteRay.h:100
bool operator<(Ray const &ray) const
Definition: GteRay.h:78
Ray()
Definition: GteRay.h:50
bool operator==(Ray const &ray) const
Definition: GteRay.h:66
bool operator!=(Ray const &ray) const
Definition: GteRay.h:72
Vector< N, Real > origin
Definition: GteRay.h:29
bool operator>=(Ray const &ray) const
Definition: GteRay.h:106
bool operator<=(Ray const &ray) const
Definition: GteRay.h:94


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 04:00:01