HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
range1d.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the Apache License, Version 2.0 (the "Apache License")
5 // with the following modification; you may not use this file except in
6 // compliance with the Apache License and the following modification to it:
7 // Section 6. Trademarks. is deleted and replaced with:
8 //
9 // 6. Trademarks. This License does not grant permission to use the trade
10 // names, trademarks, service marks, or product names of the Licensor
11 // and its affiliates, except as required to comply with Section 4(c) of
12 // the License and to reproduce the content of the NOTICE file.
13 //
14 // You may obtain a copy of the Apache License at
15 //
16 // http://www.apache.org/licenses/LICENSE-2.0
17 //
18 // Unless required by applicable law or agreed to in writing, software
19 // distributed under the Apache License with the above modification is
20 // distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
21 // KIND, either express or implied. See the Apache License for the specific
22 // language governing permissions and limitations under the Apache License.
23 //
24 ////////////////////////////////////////////////////////////////////////
25 // This file is generated by a script. Do not edit directly. Edit the
26 // range.template.h file to make changes.
27 
28 #ifndef GF_RANGE1D_H
29 #define GF_RANGE1D_H
30 
31 /// \file gf/range1d.h
32 /// \ingroup group_gf_BasicGeometry
33 
34 #include "pxr/pxr.h"
35 
36 #include "pxr/base/gf/api.h"
37 #include "pxr/base/gf/traits.h"
38 
39 #include <hboost/functional/hash.hpp>
40 
41 #include <cfloat>
42 #include <cstddef>
43 #include <iosfwd>
44 
46 
47 class GfRange1d;
48 class GfRange1f;
49 
50 template <>
51 struct GfIsGfRange<class GfRange1d> { static const bool value = true; };
52 
53 /// \class GfRange1d
54 /// \ingroup group_gf_BasicGeometry
55 ///
56 /// Basic type: 1-dimensional floating point range.
57 ///
58 /// This class represents a 1-dimensional range (or interval) All
59 /// operations are component-wise and conform to interval mathematics. An
60 /// empty range is one where max < min.
61 /// The default empty is [FLT_MAX,-FLT_MAX]
62 class GfRange1d
63 {
64 public:
65 
66  /// Helper typedef.
67  typedef double MinMaxType;
68 
69  static const size_t dimension = 1;
71 
72  /// Sets the range to an empty interval
73  // TODO check whether this can be deprecated.
74  void inline SetEmpty() {
75  _min = FLT_MAX;
76  _max = -FLT_MAX;
77  }
78 
79  /// The default constructor creates an empty range.
81  SetEmpty();
82  }
83 
84  /// This constructor initializes the minimum and maximum points.
85  GfRange1d(double min, double max)
86  : _min(min), _max(max)
87  {
88  }
89 
90  /// Returns the minimum value of the range.
91  double GetMin() const { return _min; }
92 
93  /// Returns the maximum value of the range.
94  double GetMax() const { return _max; }
95 
96  /// Returns the size of the range.
97  double GetSize() const { return _max - _min; }
98 
99  /// Returns the midpoint of the range, that is, 0.5*(min+max).
100  /// Note: this returns zero in the case of default-constructed ranges,
101  /// or ranges set via SetEmpty().
102  double GetMidpoint() const {
103  return static_cast<ScalarType>(0.5) * _min
104  + static_cast<ScalarType>(0.5) * _max;
105  }
106 
107  /// Sets the minimum value of the range.
108  void SetMin(double min) { _min = min; }
109 
110  /// Sets the maximum value of the range.
111  void SetMax(double max) { _max = max; }
112 
113  /// Returns whether the range is empty (max < min).
114  bool IsEmpty() const {
115  return _min > _max;
116  }
117 
118  /// Modifies the range if necessary to surround the given value.
119  /// \deprecated Use UnionWith() instead.
120  void ExtendBy(double point) { UnionWith(point); }
121 
122  /// Modifies the range if necessary to surround the given range.
123  /// \deprecated Use UnionWith() instead.
124  void ExtendBy(const GfRange1d &range) { UnionWith(range); }
125 
126  /// Returns true if the \p point is located inside the range. As with all
127  /// operations of this type, the range is assumed to include its extrema.
128  bool Contains(double point) const {
129  return (point >= _min && point <= _max);
130  }
131 
132  /// Returns true if the \p range is located entirely inside the range. As
133  /// with all operations of this type, the ranges are assumed to include
134  /// their extrema.
135  bool Contains(const GfRange1d &range) const {
136  return Contains(range._min) && Contains(range._max);
137  }
138 
139  /// Returns true if the \p point is located inside the range. As with all
140  /// operations of this type, the range is assumed to include its extrema.
141  /// \deprecated Use Contains() instead.
142  bool IsInside(double point) const {
143  return Contains(point);
144  }
145 
146  /// Returns true if the \p range is located entirely inside the range. As
147  /// with all operations of this type, the ranges are assumed to include
148  /// their extrema.
149  /// \deprecated Use Contains() instead.
150  bool IsInside(const GfRange1d &range) const {
151  return Contains(range);
152  }
153 
154  /// Returns true if the \p range is located entirely outside the range. As
155  /// with all operations of this type, the ranges are assumed to include
156  /// their extrema.
157  bool IsOutside(const GfRange1d &range) const {
158  return (range._max < _min || range._min > _max);
159  }
160 
161  /// Returns the smallest \c GfRange1d which contains both \p a and \p b.
162  static GfRange1d GetUnion(const GfRange1d &a, const GfRange1d &b) {
163  GfRange1d res = a;
164  _FindMin(res._min,b._min);
165  _FindMax(res._max,b._max);
166  return res;
167  }
168 
169  /// Extend \p this to include \p b.
170  const GfRange1d &UnionWith(const GfRange1d &b) {
171  _FindMin(_min,b._min);
172  _FindMax(_max,b._max);
173  return *this;
174  }
175 
176  /// Extend \p this to include \p b.
177  const GfRange1d &UnionWith(double b) {
178  _FindMin(_min,b);
179  _FindMax(_max,b);
180  return *this;
181  }
182 
183  /// Returns the smallest \c GfRange1d which contains both \p a and \p b
184  /// \deprecated Use GetUnion() instead.
185  static GfRange1d Union(const GfRange1d &a, const GfRange1d &b) {
186  return GetUnion(a, b);
187  }
188 
189  /// Extend \p this to include \p b.
190  /// \deprecated Use UnionWith() instead.
191  const GfRange1d &Union(const GfRange1d &b) {
192  return UnionWith(b);
193  }
194 
195  /// Extend \p this to include \p b.
196  /// \deprecated Use UnionWith() instead.
197  const GfRange1d &Union(double b) {
198  return UnionWith(b);
199  }
200 
201  /// Returns a \c GfRange1d that describes the intersection of \p a and \p b.
202  static GfRange1d GetIntersection(const GfRange1d &a, const GfRange1d &b) {
203  GfRange1d res = a;
204  _FindMax(res._min,b._min);
205  _FindMin(res._max,b._max);
206  return res;
207  }
208 
209  /// Returns a \c GfRange1d that describes the intersection of \p a and \p b.
210  /// \deprecated Use GetIntersection() instead.
211  static GfRange1d Intersection(const GfRange1d &a, const GfRange1d &b) {
212  return GetIntersection(a, b);
213  }
214 
215  /// Modifies this range to hold its intersection with \p b and returns the
216  /// result
218  _FindMax(_min,b._min);
219  _FindMin(_max,b._max);
220  return *this;
221  }
222 
223  /// Modifies this range to hold its intersection with \p b and returns the
224  /// result.
225  /// \deprecated Use IntersectWith() instead.
227  return IntersectWith(b);
228  }
229 
230  /// unary sum.
232  _min += b._min;
233  _max += b._max;
234  return *this;
235  }
236 
237  /// unary difference.
239  _min -= b._max;
240  _max -= b._min;
241  return *this;
242  }
243 
244  /// unary multiply.
246  if (m > 0) {
247  _min *= m;
248  _max *= m;
249  } else {
250  double tmp = _min;
251  _min = _max * m;
252  _max = tmp * m;
253  }
254  return *this;
255  }
256 
257  /// unary division.
259  return *this *= (1.0 / m);
260  }
261 
262  /// binary sum.
263  GfRange1d operator +(const GfRange1d &b) const {
264  return GfRange1d(_min + b._min, _max + b._max);
265  }
266 
267 
268  /// binary difference.
269  GfRange1d operator -(const GfRange1d &b) const {
270  return GfRange1d(_min - b._max, _max - b._min);
271  }
272 
273  /// scalar multiply.
274  friend GfRange1d operator *(double m, const GfRange1d &r) {
275  return (m > 0 ?
276  GfRange1d(r._min*m, r._max*m) :
277  GfRange1d(r._max*m, r._min*m));
278  }
279 
280  /// scalar multiply.
281  friend GfRange1d operator *(const GfRange1d &r, double m) {
282  return (m > 0 ?
283  GfRange1d(r._min*m, r._max*m) :
284  GfRange1d(r._max*m, r._min*m));
285  }
286 
287  /// scalar divide.
288  friend GfRange1d operator /(const GfRange1d &r, double m) {
289  return r * (1.0 / m);
290  }
291 
292  /// hash.
293  friend inline size_t hash_value(const GfRange1d &r) {
294  size_t h = 0;
295  hboost::hash_combine(h, r._min);
296  hboost::hash_combine(h, r._max);
297  return h;
298  }
299 
300  /// The min and max points must match exactly for equality.
301  bool operator ==(const GfRange1d &b) const {
302  return (_min == b._min && _max == b._max);
303  }
304 
305  bool operator !=(const GfRange1d &b) const {
306  return !(*this == b);
307  }
308 
309  /// Compare this range to a GfRange1f.
310  ///
311  /// The values must match exactly and it does exactly what you might
312  /// expect when comparing float and double values.
313  GF_API inline bool operator ==(const GfRange1f& other) const;
314  GF_API inline bool operator !=(const GfRange1f& other) const;
315 
316  /// Compute the squared distance from a point to the range.
317  GF_API
318  double GetDistanceSquared(double p) const;
319 
320 
321  private:
322  /// Minimum and maximum points.
323  double _min, _max;
324 
325  /// Extends minimum point if necessary to contain given point.
326  static void _FindMin(double &dest, double point) {
327  if (point < dest) dest = point;
328  }
329 
330  /// Extends maximum point if necessary to contain given point.
331  static void _FindMax(double &dest, double point) {
332  if (point > dest) dest = point;
333  }
334 };
335 
336 /// Output a GfRange1d.
337 /// \ingroup group_gf_DebuggingOutput
338 GF_API std::ostream& operator<<(std::ostream &, GfRange1d const &);
339 
341 #include "pxr/base/gf/range1f.h"
343 
344 inline bool
345 GfRange1d::operator ==(const GfRange1f& other) const {
346  return _min == double(other.GetMin()) &&
347  _max == double(other.GetMax());
348 }
349 
350 inline bool
351 GfRange1d::operator !=(const GfRange1f& other) const {
352  return !(*this == other);
353 }
354 
355 
357 
358 #endif // GF_RANGE1D_H
double MinMaxType
Helper typedef.
Definition: range1d.h:67
const GfRange1d & UnionWith(const GfRange1d &b)
Extend this to include b.
Definition: range1d.h:170
vint4 max(const vint4 &a, const vint4 &b)
Definition: simd.h:4703
GLenum GLint * range
Definition: glew.h:3500
double GetMin() const
Returns the minimum value of the range.
Definition: range1d.h:91
bool Contains(double point) const
Definition: range1d.h:128
GfRange1d operator+=(const GfRange1d &b)
unary sum.
Definition: range1d.h:231
static const size_t dimension
Definition: range1d.h:69
static GfRange1d Union(const GfRange1d &a, const GfRange1d &b)
Definition: range1d.h:185
friend size_t hash_value(const GfRange1d &r)
hash.
Definition: range1d.h:293
*get result *(waiting if necessary)*A common idiom is to fire a bunch of sub tasks at the and then *wait for them to all complete We provide a helper class
Definition: thread.h:643
GLboolean GLboolean GLboolean GLboolean a
Definition: glew.h:9477
const GfRange1d & Union(double b)
Definition: range1d.h:197
void ExtendBy(double point)
Definition: range1d.h:120
const GLdouble * m
Definition: glew.h:9124
bool operator==(const GfRange1d &b) const
The min and max points must match exactly for equality.
Definition: range1d.h:301
GF_API std::ostream & operator<<(std::ostream &, GfRange1d const &)
bool operator!=(const GfRange1d &b) const
Definition: range1d.h:305
const GfRange1d & IntersectWith(const GfRange1d &b)
Definition: range1d.h:217
const GfRange1d & Intersection(const GfRange1d &b)
Definition: range1d.h:226
double GetMax() const
Returns the maximum value of the range.
Definition: range1d.h:94
friend GfRange1d operator*(double m, const GfRange1d &r)
scalar multiply.
Definition: range1d.h:274
double GetMidpoint() const
Definition: range1d.h:102
GfRange1d operator+(const GfRange1d &b) const
binary sum.
Definition: range1d.h:263
bool IsEmpty() const
Returns whether the range is empty (max < min).
Definition: range1d.h:114
MinMaxType ScalarType
Definition: range1d.h:70
void SetMax(double max)
Sets the maximum value of the range.
Definition: range1d.h:111
void SetEmpty()
Sets the range to an empty interval.
Definition: range1d.h:74
GLfloat GLfloat GLfloat GLfloat h
Definition: glew.h:8011
bool IsInside(const GfRange1d &range) const
Definition: range1d.h:150
GF_API double GetDistanceSquared(double p) const
Compute the squared distance from a point to the range.
float GetMin() const
Returns the minimum value of the range.
Definition: range1f.h:91
static GfRange1d GetUnion(const GfRange1d &a, const GfRange1d &b)
Returns the smallest GfRange1d which contains both a and b.
Definition: range1d.h:162
GLdouble GLdouble GLdouble b
Definition: glew.h:9122
GLfloat GLfloat p
Definition: glew.h:16321
void SetMin(double min)
Sets the minimum value of the range.
Definition: range1d.h:108
bool IsInside(double point) const
Definition: range1d.h:142
GfRange1d()
The default constructor creates an empty range.
Definition: range1d.h:80
double GetSize() const
Returns the size of the range.
Definition: range1d.h:97
bool IsOutside(const GfRange1d &range) const
Definition: range1d.h:157
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1245
GfRange1d operator*=(double m)
unary multiply.
Definition: range1d.h:245
bool Contains(const GfRange1d &range) const
Definition: range1d.h:135
static GfRange1d GetIntersection(const GfRange1d &a, const GfRange1d &b)
Returns a GfRange1d that describes the intersection of a and b.
Definition: range1d.h:202
float GetMax() const
Returns the maximum value of the range.
Definition: range1f.h:94
friend GfRange1d operator/(const GfRange1d &r, double m)
scalar divide.
Definition: range1d.h:288
GLdouble GLdouble GLdouble r
Definition: glew.h:1406
GfRange1d(double min, double max)
This constructor initializes the minimum and maximum points.
Definition: range1d.h:85
GfRange1d operator-(const GfRange1d &b) const
binary difference.
Definition: range1d.h:269
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:83
GfRange1d operator-=(const GfRange1d &b)
unary difference.
Definition: range1d.h:238
vint4 min(const vint4 &a, const vint4 &b)
Definition: simd.h:4694
static GfRange1d Intersection(const GfRange1d &a, const GfRange1d &b)
Definition: range1d.h:211
GLsizei const GLfloat * value
Definition: glew.h:1849
const GfRange1d & UnionWith(double b)
Extend this to include b.
Definition: range1d.h:177
GfRange1d operator/=(double m)
unary division.
Definition: range1d.h:258
void ExtendBy(const GfRange1d &range)
Definition: range1d.h:124
#define GF_API
Definition: api.h:40
GLuint res
Definition: glew.h:11507
const GfRange1d & Union(const GfRange1d &b)
Definition: range1d.h:191