GteLine.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 line is represented by P+t*D, where P is an origin point, D is a
13 // unit-length direction vector, and t is any real number. The user must
14 // ensure that D is unit length.
15 
16 namespace gte
17 {
18 
19 template <int N, typename Real>
20 class Line
21 {
22 public:
23  // Construction and destruction. The default constructor sets the origin
24  // to (0,...,0) and the line direction to (1,0,...,0).
25  Line();
26  Line(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==(Line const& line) const;
34  bool operator!=(Line const& line) const;
35  bool operator< (Line const& line) const;
36  bool operator<=(Line const& line) const;
37  bool operator> (Line const& line) const;
38  bool operator>=(Line const& line) 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 Line<N, Real>::operator==(Line const& line) const
67 {
68  return origin == line.origin && direction == line.direction;
69 }
70 
71 template <int N, typename Real>
72 bool Line<N, Real>::operator!=(Line const& line) const
73 {
74  return !operator==(line);
75 }
76 
77 template <int N, typename Real>
78 bool Line<N, Real>::operator<(Line const& line) const
79 {
80  if (origin < line.origin)
81  {
82  return true;
83  }
84 
85  if (origin > line.origin)
86  {
87  return false;
88  }
89 
90  return direction < line.direction;
91 }
92 
93 template <int N, typename Real>
94 bool Line<N, Real>::operator<=(Line const& line) const
95 {
96  return operator<(line) || operator==(line);
97 }
98 
99 template <int N, typename Real>
100 bool Line<N, Real>::operator>(Line const& line) const
101 {
102  return !operator<=(line);
103 }
104 
105 template <int N, typename Real>
106 bool Line<N, Real>::operator>=(Line const& line) const
107 {
108  return !operator<(line);
109 }
110 
111 
112 }
bool operator==(Line const &line) const
Definition: GteLine.h:66
bool operator<=(Line const &line) const
Definition: GteLine.h:94
bool operator<(Line const &line) const
Definition: GteLine.h:78
Vector< N, Real > direction
Definition: GteLine.h:29
bool operator!=(Line const &line) const
Definition: GteLine.h:72
bool operator>=(Line const &line) const
Definition: GteLine.h:106
bool operator>(Line const &line) const
Definition: GteLine.h:100
Line()
Definition: GteLine.h:50
Vector< N, Real > origin
Definition: GteLine.h:29


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