GteCapsule.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/GteSegment.h>
11 
12 namespace gte
13 {
14 
15 // A capsule is the set of points that are equidistant from a segment, the
16 // common distance called the radius.
17 
18 template <int N, typename Real>
19 class Capsule
20 {
21 public:
22  // Construction and destruction. The default constructor sets the segment
23  // to have endpoints p0 = (-1,0,...,0) and p1 = (1,0,...,0), and the
24  // radius is 1.
25  Capsule();
26  Capsule(Segment<N, Real> const& inSegment, Real inRadius);
27 
28  // Public member access.
30  Real radius;
31 
32 public:
33  // Comparisons to support sorted containers.
34  bool operator==(Capsule const& capsule) const;
35  bool operator!=(Capsule const& capsule) const;
36  bool operator< (Capsule const& capsule) const;
37  bool operator<=(Capsule const& capsule) const;
38  bool operator> (Capsule const& capsule) const;
39  bool operator>=(Capsule const& capsule) const;
40 };
41 
42 // Template alias for convenience.
43 template <typename Real>
45 
46 
47 template <int N, typename Real>
49  :
50  radius((Real)1)
51 {
52 }
53 
54 template <int N, typename Real>
55 Capsule<N, Real>::Capsule(Segment<N, Real> const& inSegment, Real inRadius)
56  :
57  segment(inSegment),
58  radius(inRadius)
59 {
60 }
61 
62 template <int N, typename Real>
63 bool Capsule<N, Real>::operator==(Capsule const& capsule) const
64 {
65  return segment == capsule.segment && radius == capsule.radius;
66 }
67 
68 template <int N, typename Real>
69 bool Capsule<N, Real>::operator!=(Capsule const& capsule) const
70 {
71  return !operator==(capsule);
72 }
73 
74 template <int N, typename Real>
75 bool Capsule<N, Real>::operator<(Capsule const& capsule) const
76 {
77  if (segment < capsule.segment)
78  {
79  return true;
80  }
81 
82  if (segment > capsule.segment)
83  {
84  return false;
85  }
86 
87  return radius < capsule.radius;
88 }
89 
90 template <int N, typename Real>
91 bool Capsule<N, Real>::operator<=(Capsule const& capsule) const
92 {
93  return operator<(capsule) || operator==(capsule);
94 }
95 
96 template <int N, typename Real>
97 bool Capsule<N, Real>::operator>(Capsule const& capsule) const
98 {
99  return !operator<=(capsule);
100 }
101 
102 template <int N, typename Real>
103 bool Capsule<N, Real>::operator>=(Capsule const& capsule) const
104 {
105  return !operator<(capsule);
106 }
107 
108 
109 }
bool operator>=(Capsule const &capsule) const
Definition: GteCapsule.h:103
bool operator!=(Capsule const &capsule) const
Definition: GteCapsule.h:69
bool operator>(Capsule const &capsule) const
Definition: GteCapsule.h:97
Segment< N, Real > segment
Definition: GteCapsule.h:29
bool operator<(Capsule const &capsule) const
Definition: GteCapsule.h:75
bool operator==(Capsule const &capsule) const
Definition: GteCapsule.h:63
bool operator<=(Capsule const &capsule) const
Definition: GteCapsule.h:91


geometric_tools_engine
Author(s): Yijiang Huang
autogenerated on Thu Jul 18 2019 03:59:59