GteAlignedBox.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 box is aligned with the standard coordinate axes, which allows us to
13 // represent it using minimum and maximum values along each axis. Some
14 // algorithms prefer the centered representation that is used for oriented
15 // boxes. The center is C and the extents are the half-lengths in each
16 // coordinate-axis direction.
17 
18 namespace gte
19 {
20 
21 template <int N, typename Real>
23 {
24 public:
25  // Construction and destruction. The default constructor sets the
26  // minimum values to -1 and the maximum values to +1.
27  AlignedBox();
28 
29  // Please ensure that inMin[i] <= inMax[i] for all i.
30  AlignedBox(Vector<N, Real> const& inMin, Vector<N, Real> const& inMax);
31 
32  // Compute the centered representation. NOTE: If you set the minimum
33  // and maximum values, compute C and extents, and then recompute the
34  // minimum and maximum values, the numerical round-off errors can lead to
35  // results different from what you started with.
36  void GetCenteredForm(Vector<N, Real>& center, Vector<N, Real>& extent)
37  const;
38 
39  // Public member access. It is required that min[i] <= max[i].
41 
42 public:
43  // Comparisons to support sorted containers.
44  bool operator==(AlignedBox const& box) const;
45  bool operator!=(AlignedBox const& box) const;
46  bool operator< (AlignedBox const& box) const;
47  bool operator<=(AlignedBox const& box) const;
48  bool operator> (AlignedBox const& box) const;
49  bool operator>=(AlignedBox const& box) const;
50 };
51 
52 // Template aliases for convenience.
53 template <typename Real>
55 
56 template <typename Real>
58 
59 
60 template <int N, typename Real>
62 {
63  for (int i = 0; i < N; ++i)
64  {
65  min[i] = (Real)-1;
66  max[i] = (Real)+1;
67  }
68 }
69 
70 template <int N, typename Real>
72  Vector<N, Real> const& inMax)
73 {
74  for (int i = 0; i < N; ++i)
75  {
76  min[i] = inMin[i];
77  max[i] = inMax[i];
78  }
79 }
80 
81 template <int N, typename Real>
83  Vector<N, Real>& extent) const
84 {
85  center = (max + min) * (Real)0.5;
86  extent = (max - min) * (Real)0.5;
87 }
88 
89 template <int N, typename Real>
91 {
92  return min == box.min && max == box.max;
93 }
94 
95 template <int N, typename Real>
97 {
98  return !operator==(box);
99 }
100 
101 template <int N, typename Real>
103 {
104  if (min < box.min)
105  {
106  return true;
107  }
108 
109  if (min > box.min)
110  {
111  return false;
112  }
113 
114  return max < box.max;
115 }
116 
117 template <int N, typename Real>
119 {
120  return operator<(box) || operator==(box);
121 }
122 
123 template <int N, typename Real>
125 {
126  return !operator<=(box);
127 }
128 
129 template <int N, typename Real>
131 {
132  return !operator<(box);
133 }
134 
135 
136 }
void GetCenteredForm(Vector< N, Real > &center, Vector< N, Real > &extent) const
Definition: GteAlignedBox.h:82
Vector< N, Real > max
Definition: GteAlignedBox.h:40
Vector< N, Real > min
Definition: GteAlignedBox.h:40
bool operator!=(AlignedBox const &box) const
Definition: GteAlignedBox.h:96
bool operator>(AlignedBox const &box) const
bool operator<=(AlignedBox const &box) const
bool operator==(AlignedBox const &box) const
Definition: GteAlignedBox.h:90
bool operator>=(AlignedBox const &box) const
bool operator<(AlignedBox const &box) const


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