HDK
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
range1f.h
Go to the documentation of this file.
1 //
2 // Copyright 2016 Pixar
3 //
4 // Licensed under the terms set forth in the LICENSE.txt file available at
5 // https://openusd.org/license.
6 //
7 ////////////////////////////////////////////////////////////////////////
8 // This file is generated by a script. Do not edit directly. Edit the
9 // range.template.h file to make changes.
10 
11 #ifndef PXR_BASE_GF_RANGE1F_H
12 #define PXR_BASE_GF_RANGE1F_H
13 
14 /// \file gf/range1f.h
15 /// \ingroup group_gf_BasicGeometry
16 
17 #include "pxr/pxr.h"
18 
19 #include "pxr/base/gf/api.h"
20 #include "pxr/base/gf/traits.h"
21 #include "pxr/base/tf/hash.h"
22 
23 #include <cfloat>
24 #include <cstddef>
25 #include <iosfwd>
26 
28 
29 class GfRange1d;
30 class GfRange1f;
31 
32 template <>
33 struct GfIsGfRange<class GfRange1f> { static const bool value = true; };
34 
35 /// \class GfRange1f
36 /// \ingroup group_gf_BasicGeometry
37 ///
38 /// Basic type: 1-dimensional floating point range.
39 ///
40 /// This class represents a 1-dimensional range (or interval) All
41 /// operations are component-wise and conform to interval mathematics. An
42 /// empty range is one where max < min.
43 /// The default empty is [FLT_MAX,-FLT_MAX]
44 class GfRange1f
45 {
46 public:
47 
48  /// Helper typedef.
49  typedef float MinMaxType;
50 
51  static const size_t dimension = 1;
53 
54  /// Sets the range to an empty interval
55  // TODO check whether this can be deprecated.
56  void inline SetEmpty() {
57  _min = FLT_MAX;
58  _max = -FLT_MAX;
59  }
60 
61  /// The default constructor creates an empty range.
63  SetEmpty();
64  }
65 
66  /// This constructor initializes the minimum and maximum points.
67  GfRange1f(float min, float max)
68  : _min(min), _max(max)
69  {
70  }
71 
72 
73  /// Construct from GfRange1d.
74  GF_API
75  explicit GfRange1f(class GfRange1d const &other);
76 
77  /// Returns the minimum value of the range.
78  float GetMin() const { return _min; }
79 
80  /// Returns the maximum value of the range.
81  float GetMax() const { return _max; }
82 
83  /// Returns the size of the range.
84  float GetSize() const { return _max - _min; }
85 
86  /// Returns the midpoint of the range, that is, 0.5*(min+max).
87  /// Note: this returns zero in the case of default-constructed ranges,
88  /// or ranges set via SetEmpty().
89  float GetMidpoint() const {
90  return static_cast<ScalarType>(0.5) * _min
91  + static_cast<ScalarType>(0.5) * _max;
92  }
93 
94  /// Sets the minimum value of the range.
95  void SetMin(float min) { _min = min; }
96 
97  /// Sets the maximum value of the range.
98  void SetMax(float max) { _max = max; }
99 
100  /// Returns whether the range is empty (max < min).
101  bool IsEmpty() const {
102  return _min > _max;
103  }
104 
105  /// Modifies the range if necessary to surround the given value.
106  /// \deprecated Use UnionWith() instead.
107  void ExtendBy(float point) { UnionWith(point); }
108 
109  /// Modifies the range if necessary to surround the given range.
110  /// \deprecated Use UnionWith() instead.
111  void ExtendBy(const GfRange1f &range) { UnionWith(range); }
112 
113  /// Returns true if the \p point is located inside the range. As with all
114  /// operations of this type, the range is assumed to include its extrema.
115  bool Contains(float point) const {
116  return (point >= _min && point <= _max);
117  }
118 
119  /// Returns true if the \p range is located entirely inside the range. As
120  /// with all operations of this type, the ranges are assumed to include
121  /// their extrema.
122  bool Contains(const GfRange1f &range) const {
123  return Contains(range._min) && Contains(range._max);
124  }
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  /// \deprecated Use Contains() instead.
129  bool IsInside(float point) const {
130  return Contains(point);
131  }
132 
133  /// Returns true if the \p range is located entirely inside the range. As
134  /// with all operations of this type, the ranges are assumed to include
135  /// their extrema.
136  /// \deprecated Use Contains() instead.
137  bool IsInside(const GfRange1f &range) const {
138  return Contains(range);
139  }
140 
141  /// Returns true if the \p range is located entirely outside the range. As
142  /// with all operations of this type, the ranges are assumed to include
143  /// their extrema.
144  bool IsOutside(const GfRange1f &range) const {
145  return (range._max < _min || range._min > _max);
146  }
147 
148  /// Returns the smallest \c GfRange1f which contains both \p a and \p b.
149  static GfRange1f GetUnion(const GfRange1f &a, const GfRange1f &b) {
150  GfRange1f res = a;
151  _FindMin(res._min,b._min);
152  _FindMax(res._max,b._max);
153  return res;
154  }
155 
156  /// Extend \p this to include \p b.
157  const GfRange1f &UnionWith(const GfRange1f &b) {
158  _FindMin(_min,b._min);
159  _FindMax(_max,b._max);
160  return *this;
161  }
162 
163  /// Extend \p this to include \p b.
164  const GfRange1f &UnionWith(float b) {
165  _FindMin(_min,b);
166  _FindMax(_max,b);
167  return *this;
168  }
169 
170  /// Returns the smallest \c GfRange1f which contains both \p a and \p b
171  /// \deprecated Use GetUnion() instead.
172  static GfRange1f Union(const GfRange1f &a, const GfRange1f &b) {
173  return GetUnion(a, b);
174  }
175 
176  /// Extend \p this to include \p b.
177  /// \deprecated Use UnionWith() instead.
178  const GfRange1f &Union(const GfRange1f &b) {
179  return UnionWith(b);
180  }
181 
182  /// Extend \p this to include \p b.
183  /// \deprecated Use UnionWith() instead.
184  const GfRange1f &Union(float b) {
185  return UnionWith(b);
186  }
187 
188  /// Returns a \c GfRange1f that describes the intersection of \p a and \p b.
189  static GfRange1f GetIntersection(const GfRange1f &a, const GfRange1f &b) {
190  GfRange1f res = a;
191  _FindMax(res._min,b._min);
192  _FindMin(res._max,b._max);
193  return res;
194  }
195 
196  /// Returns a \c GfRange1f that describes the intersection of \p a and \p b.
197  /// \deprecated Use GetIntersection() instead.
198  static GfRange1f Intersection(const GfRange1f &a, const GfRange1f &b) {
199  return GetIntersection(a, b);
200  }
201 
202  /// Modifies this range to hold its intersection with \p b and returns the
203  /// result
205  _FindMax(_min,b._min);
206  _FindMin(_max,b._max);
207  return *this;
208  }
209 
210  /// Modifies this range to hold its intersection with \p b and returns the
211  /// result.
212  /// \deprecated Use IntersectWith() instead.
214  return IntersectWith(b);
215  }
216 
217  /// unary sum.
219  _min += b._min;
220  _max += b._max;
221  return *this;
222  }
223 
224  /// unary difference.
226  _min -= b._max;
227  _max -= b._min;
228  return *this;
229  }
230 
231  /// unary multiply.
232  GfRange1f &operator *=(double m) {
233  if (m > 0) {
234  _min *= m;
235  _max *= m;
236  } else {
237  float tmp = _min;
238  _min = _max * m;
239  _max = tmp * m;
240  }
241  return *this;
242  }
243 
244  /// unary division.
245  GfRange1f &operator /=(double m) {
246  return *this *= (1.0 / m);
247  }
248 
249  /// binary sum.
250  GfRange1f operator +(const GfRange1f &b) const {
251  return GfRange1f(_min + b._min, _max + b._max);
252  }
253 
254 
255  /// binary difference.
256  GfRange1f operator -(const GfRange1f &b) const {
257  return GfRange1f(_min - b._max, _max - b._min);
258  }
259 
260  /// scalar multiply.
261  friend GfRange1f operator *(double m, const GfRange1f &r) {
262  return (m > 0 ?
263  GfRange1f(r._min*m, r._max*m) :
264  GfRange1f(r._max*m, r._min*m));
265  }
266 
267  /// scalar multiply.
268  friend GfRange1f operator *(const GfRange1f &r, double m) {
269  return (m > 0 ?
270  GfRange1f(r._min*m, r._max*m) :
271  GfRange1f(r._max*m, r._min*m));
272  }
273 
274  /// scalar divide.
275  friend GfRange1f operator /(const GfRange1f &r, double m) {
276  return r * (1.0 / m);
277  }
278 
279  /// hash.
280  friend inline size_t hash_value(const GfRange1f &r) {
281  return TfHash::Combine(r._min, r._max);
282  }
283 
284  /// The min and max points must match exactly for equality.
285  bool operator ==(const GfRange1f &b) const {
286  return (_min == b._min && _max == b._max);
287  }
288 
289  bool operator !=(const GfRange1f &b) const {
290  return !(*this == b);
291  }
292 
293  /// Compare this range to a GfRange1d.
294  ///
295  /// The values must match exactly and it does exactly what you might
296  /// expect when comparing float and double values.
297  GF_API inline bool operator ==(const GfRange1d& other) const;
298  GF_API inline bool operator !=(const GfRange1d& other) const;
299 
300  /// Compute the squared distance from a point to the range.
301  GF_API
302  double GetDistanceSquared(float p) const;
303 
304 
305  private:
306  /// Minimum and maximum points.
307  float _min, _max;
308 
309  /// Extends minimum point if necessary to contain given point.
310  static void _FindMin(float &dest, float point) {
311  if (point < dest) dest = point;
312  }
313 
314  /// Extends maximum point if necessary to contain given point.
315  static void _FindMax(float &dest, float point) {
316  if (point > dest) dest = point;
317  }
318 };
319 
320 /// Output a GfRange1f.
321 /// \ingroup group_gf_DebuggingOutput
322 GF_API std::ostream& operator<<(std::ostream &, GfRange1f const &);
323 
325 #include "pxr/base/gf/range1d.h"
327 
328 inline bool
329 GfRange1f::operator ==(const GfRange1d& other) const {
330  return _min == float(other.GetMin()) &&
331  _max == float(other.GetMax());
332 }
333 
334 inline bool
335 GfRange1f::operator !=(const GfRange1d& other) const {
336  return !(*this == other);
337 }
338 
339 
341 
342 #endif // PXR_BASE_GF_RANGE1F_H
void SetMax(float max)
Sets the maximum value of the range.
Definition: range1f.h:98
double GetMin() const
Returns the minimum value of the range.
Definition: range1d.h:78
void ExtendBy(const GfRange1f &range)
Definition: range1f.h:111
GLenum GLint * range
Definition: glcorearb.h:1925
bool IsInside(float point) const
Definition: range1f.h:129
*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:632
GfRange1f(float min, float max)
This constructor initializes the minimum and maximum points.
Definition: range1f.h:67
GfRange1f & operator-=(const GfRange1f &b)
unary difference.
Definition: range1f.h:225
const GfRange1f & IntersectWith(const GfRange1f &b)
Definition: range1f.h:204
bool Contains(const GfRange1f &range) const
Definition: range1f.h:122
void ExtendBy(float point)
Definition: range1f.h:107
GLsizei const GLfloat * value
Definition: glcorearb.h:824
GfRange1f operator-(const GfRange1f &b) const
binary difference.
Definition: range1f.h:256
bool IsOutside(const GfRange1f &range) const
Definition: range1f.h:144
GLboolean GLboolean GLboolean GLboolean a
Definition: glcorearb.h:1222
const GfRange1f & UnionWith(float b)
Extend this to include b.
Definition: range1f.h:164
static const size_t dimension
Definition: range1f.h:51
ImageBuf OIIO_API min(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
void SetMin(float min)
Sets the minimum value of the range.
Definition: range1f.h:95
static GfRange1f GetUnion(const GfRange1f &a, const GfRange1f &b)
Returns the smallest GfRange1f which contains both a and b.
Definition: range1f.h:149
GfRange1f & operator+=(const GfRange1f &b)
unary sum.
Definition: range1f.h:218
static GfRange1f Intersection(const GfRange1f &a, const GfRange1f &b)
Definition: range1f.h:198
static GfRange1f GetIntersection(const GfRange1f &a, const GfRange1f &b)
Returns a GfRange1f that describes the intersection of a and b.
Definition: range1f.h:189
MinMaxType ScalarType
Definition: range1f.h:52
double GetMax() const
Returns the maximum value of the range.
Definition: range1d.h:81
const GfRange1f & Union(const GfRange1f &b)
Definition: range1f.h:178
GfRange1f operator+(const GfRange1f &b) const
binary sum.
Definition: range1f.h:250
float GetSize() const
Returns the size of the range.
Definition: range1f.h:84
bool operator!=(const GfRange1f &b) const
Definition: range1f.h:289
GLboolean GLboolean GLboolean b
Definition: glcorearb.h:1222
bool IsEmpty() const
Returns whether the range is empty (max < min).
Definition: range1f.h:101
GfRange1f()
The default constructor creates an empty range.
Definition: range1f.h:62
float GetMin() const
Returns the minimum value of the range.
Definition: range1f.h:78
void SetEmpty()
Sets the range to an empty interval.
Definition: range1f.h:56
friend size_t hash_value(const GfRange1f &r)
hash.
Definition: range1f.h:280
float MinMaxType
Helper typedef.
Definition: range1f.h:49
GfRange1f & operator/=(double m)
unary division.
Definition: range1f.h:245
IMATH_NAMESPACE::V2f IMATH_NAMESPACE::Box2i std::string this attribute is obsolete as of OpenEXR v3 float
static size_t Combine(Args &&...args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
float GetMidpoint() const
Definition: range1f.h:89
PXR_NAMESPACE_CLOSE_SCOPE PXR_NAMESPACE_OPEN_SCOPE
Definition: path.h:1425
const GfRange1f & UnionWith(const GfRange1f &b)
Extend this to include b.
Definition: range1f.h:157
friend GfRange1f operator/(const GfRange1f &r, double m)
scalar divide.
Definition: range1f.h:275
float GetMax() const
Returns the maximum value of the range.
Definition: range1f.h:81
GF_API double GetDistanceSquared(float p) const
Compute the squared distance from a point to the range.
const GfRange1f & Intersection(const GfRange1f &b)
Definition: range1f.h:213
ImageBuf OIIO_API max(Image_or_Const A, Image_or_Const B, ROI roi={}, int nthreads=0)
#define PXR_NAMESPACE_CLOSE_SCOPE
Definition: pxr.h:74
GfRange1f & operator*=(double m)
unary multiply.
Definition: range1f.h:232
friend GfRange1f operator*(double m, const GfRange1f &r)
scalar multiply.
Definition: range1f.h:261
bool IsInside(const GfRange1f &range) const
Definition: range1f.h:137
bool Contains(float point) const
Definition: range1f.h:115
GLboolean r
Definition: glcorearb.h:1222
const GfRange1f & Union(float b)
Definition: range1f.h:184
GF_API std::ostream & operator<<(std::ostream &, GfRange1f const &)
static GfRange1f Union(const GfRange1f &a, const GfRange1f &b)
Definition: range1f.h:172
bool operator==(const GfRange1f &b) const
The min and max points must match exactly for equality.
Definition: range1f.h:285
#define GF_API
Definition: api.h:23