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 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 //
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 PXR_BASE_GF_RANGE1F_H
29 #define PXR_BASE_GF_RANGE1F_H
30 
33 
34 #include "pxr/pxr.h"
35 
36 #include "pxr/base/gf/api.h"
37 #include "pxr/base/gf/traits.h"
38 
39 #include <boost/functional/hash.hpp>
40 
41 #include <cfloat>
42 #include <cstddef>
43 #include <iosfwd>
44 
45 PXR_NAMESPACE_OPEN_SCOPE
46 
47 class GfRange1d;
48 class GfRange1f;
49 
50 template <>
51 struct GfIsGfRange<class GfRange1f> { static const bool value = true; };
52 
62 class GfRange1f
63 {
64 public:
65 
67  typedef float MinMaxType;
68 
69  static const size_t dimension = 1;
70  typedef MinMaxType ScalarType;
71 
73  // TODO check whether this can be deprecated.
74  void inline SetEmpty() {
75  _min = FLT_MAX;
76  _max = -FLT_MAX;
77  }
78 
81  SetEmpty();
82  }
83 
85  GfRange1f(float min, float max)
86  : _min(min), _max(max)
87  {
88  }
89 
91  float GetMin() const { return _min; }
92 
94  float GetMax() const { return _max; }
95 
97  float GetSize() const { return _max - _min; }
98 
102  float GetMidpoint() const {
103  return static_cast<ScalarType>(0.5) * _min
104  + static_cast<ScalarType>(0.5) * _max;
105  }
106 
108  void SetMin(float min) { _min = min; }
109 
111  void SetMax(float max) { _max = max; }
112 
114  bool IsEmpty() const {
115  return _min > _max;
116  }
117 
120  void ExtendBy(float point) { UnionWith(point); }
121 
124  void ExtendBy(const GfRange1f &range) { UnionWith(range); }
125 
128  bool Contains(float point) const {
129  return (point >= _min && point <= _max);
130  }
131 
135  bool Contains(const GfRange1f &range) const {
136  return Contains(range._min) && Contains(range._max);
137  }
138 
142  bool IsInside(float point) const {
143  return Contains(point);
144  }
145 
150  bool IsInside(const GfRange1f &range) const {
151  return Contains(range);
152  }
153 
157  bool IsOutside(const GfRange1f &range) const {
158  return (range._max < _min || range._min > _max);
159  }
160 
162  static GfRange1f GetUnion(const GfRange1f &a, const GfRange1f &b) {
163  GfRange1f res = a;
164  _FindMin(res._min,b._min);
165  _FindMax(res._max,b._max);
166  return res;
167  }
168 
170  const GfRange1f &UnionWith(const GfRange1f &b) {
171  _FindMin(_min,b._min);
172  _FindMax(_max,b._max);
173  return *this;
174  }
175 
177  const GfRange1f &UnionWith(float b) {
178  _FindMin(_min,b);
179  _FindMax(_max,b);
180  return *this;
181  }
182 
185  static GfRange1f Union(const GfRange1f &a, const GfRange1f &b) {
186  return GetUnion(a, b);
187  }
188 
191  const GfRange1f &Union(const GfRange1f &b) {
192  return UnionWith(b);
193  }
194 
197  const GfRange1f &Union(float b) {
198  return UnionWith(b);
199  }
200 
202  static GfRange1f GetIntersection(const GfRange1f &a, const GfRange1f &b) {
203  GfRange1f res = a;
204  _FindMax(res._min,b._min);
205  _FindMin(res._max,b._max);
206  return res;
207  }
208 
211  static GfRange1f Intersection(const GfRange1f &a, const GfRange1f &b) {
212  return GetIntersection(a, b);
213  }
214 
217  const GfRange1f &IntersectWith(const GfRange1f &b) {
218  _FindMax(_min,b._min);
219  _FindMin(_max,b._max);
220  return *this;
221  }
222 
226  const GfRange1f &Intersection(const GfRange1f &b) {
227  return IntersectWith(b);
228  }
229 
232  _min += b._min;
233  _max += b._max;
234  return *this;
235  }
236 
239  _min -= b._max;
240  _max -= b._min;
241  return *this;
242  }
243 
245  GfRange1f operator *=(double m) {
246  if (m > 0) {
247  _min *= m;
248  _max *= m;
249  } else {
250  float tmp = _min;
251  _min = _max * m;
252  _max = tmp * m;
253  }
254  return *this;
255  }
256 
258  GfRange1f operator /=(double m) {
259  return *this *= (1.0 / m);
260  }
261 
263  GfRange1f operator +(const GfRange1f &b) const {
264  return GfRange1f(_min + b._min, _max + b._max);
265  }
266 
267 
269  GfRange1f operator -(const GfRange1f &b) const {
270  return GfRange1f(_min - b._max, _max - b._min);
271  }
272 
274  friend GfRange1f operator *(double m, const GfRange1f &r) {
275  return (m > 0 ?
276  GfRange1f(r._min*m, r._max*m) :
277  GfRange1f(r._max*m, r._min*m));
278  }
279 
281  friend GfRange1f operator *(const GfRange1f &r, double m) {
282  return (m > 0 ?
283  GfRange1f(r._min*m, r._max*m) :
284  GfRange1f(r._max*m, r._min*m));
285  }
286 
288  friend GfRange1f operator /(const GfRange1f &r, double m) {
289  return r * (1.0 / m);
290  }
291 
293  friend inline size_t hash_value(const GfRange1f &r) {
294  size_t h = 0;
295  boost::hash_combine(h, r._min);
296  boost::hash_combine(h, r._max);
297  return h;
298  }
299 
301  bool operator ==(const GfRange1f &b) const {
302  return (_min == b._min && _max == b._max);
303  }
304 
305  bool operator !=(const GfRange1f &b) const {
306  return !(*this == b);
307  }
308 
313  GF_API inline bool operator ==(const GfRange1d& other) const;
314  GF_API inline bool operator !=(const GfRange1d& other) const;
315 
317  GF_API
318  double GetDistanceSquared(float p) const;
319 
320 
321  private:
323  float _min, _max;
324 
326  static void _FindMin(float &dest, float point) {
327  if (point < dest) dest = point;
328  }
329 
331  static void _FindMax(float &dest, float point) {
332  if (point > dest) dest = point;
333  }
334 };
335 
338 GF_API std::ostream& operator<<(std::ostream &, GfRange1f const &);
339 
340 PXR_NAMESPACE_CLOSE_SCOPE
341 #include "pxr/base/gf/range1d.h"
342 PXR_NAMESPACE_OPEN_SCOPE
343 
344 inline bool
345 GfRange1f::operator ==(const GfRange1d& other) const {
346  return _min == float(other.GetMin()) &&
347  _max == float(other.GetMax());
348 }
349 
350 inline bool
351 GfRange1f::operator !=(const GfRange1d& other) const {
352  return !(*this == other);
353 }
354 
355 
356 PXR_NAMESPACE_CLOSE_SCOPE
357 
358 #endif // PXR_BASE_GF_RANGE1F_H
bool Contains(float point) const
Returns true if the point is located inside the range.
Definition: range1f.h:128
Basic type: 1-dimensional floating point range.
Definition: range1d.h:62
const GfRange1f & Union(const GfRange1f &b)
Extend this to include b.
Definition: range1f.h:191
const GfRange1f & Intersection(const GfRange1f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range1f.h:226
GfRange1f operator+=(const GfRange1f &b)
unary sum.
Definition: range1f.h:231
float GetMidpoint() const
Returns the midpoint of the range, that is, 0.5*(min+max).
Definition: range1f.h:102
A metafunction with a static const bool member &#39;value&#39; that is true for GfRange types and false for a...
Definition: traits.h:52
void SetMax(float max)
Sets the maximum value of the range.
Definition: range1f.h:111
bool Contains(const GfRange1f &range) const
Returns true if the range is located entirely inside the range.
Definition: range1f.h:135
GfRange1f operator*=(double m)
unary multiply.
Definition: range1f.h:245
const GfRange1f & UnionWith(float b)
Extend this to include b.
Definition: range1f.h:177
GF_API double GetDistanceSquared(float p) const
Compute the squared distance from a point to the range.
void ExtendBy(const GfRange1f &range)
Modifies the range if necessary to surround the given range.
Definition: range1f.h:124
double GetMin() const
Returns the minimum value of the range.
Definition: range1d.h:91
static GfRange1f GetIntersection(const GfRange1f &a, const GfRange1f &b)
Returns a GfRange1f that describes the intersection of a and b.
Definition: range1f.h:202
static GfRange1f GetUnion(const GfRange1f &a, const GfRange1f &b)
Returns the smallest GfRange1f which contains both a and b.
Definition: range1f.h:162
const GfRange1f & UnionWith(const GfRange1f &b)
Extend this to include b.
Definition: range1f.h:170
GfRange1f operator+(const GfRange1f &b) const
binary sum.
Definition: range1f.h:263
GfRange1f()
The default constructor creates an empty range.
Definition: range1f.h:80
GfRange1f operator/=(double m)
unary division.
Definition: range1f.h:258
void SetEmpty()
Sets the range to an empty interval.
Definition: range1f.h:74
float MinMaxType
Helper typedef.
Definition: range1f.h:67
float GetMax() const
Returns the maximum value of the range.
Definition: range1f.h:94
bool IsInside(float point) const
Returns true if the point is located inside the range.
Definition: range1f.h:142
Basic type: 1-dimensional floating point range.
Definition: range1f.h:62
void ExtendBy(float point)
Modifies the range if necessary to surround the given value.
Definition: range1f.h:120
GfRange1f operator-=(const GfRange1f &b)
unary difference.
Definition: range1f.h:238
float GetSize() const
Returns the size of the range.
Definition: range1f.h:97
bool IsInside(const GfRange1f &range) const
Returns true if the range is located entirely inside the range.
Definition: range1f.h:150
float GetMin() const
Returns the minimum value of the range.
Definition: range1f.h:91
friend size_t hash_value(const GfRange1f &r)
hash.
Definition: range1f.h:293
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
static GfRange1f Intersection(const GfRange1f &a, const GfRange1f &b)
Returns a GfRange1f that describes the intersection of a and b.
Definition: range1f.h:211
bool IsOutside(const GfRange1f &range) const
Returns true if the range is located entirely outside the range.
Definition: range1f.h:157
GfRange1f operator-(const GfRange1f &b) const
binary difference.
Definition: range1f.h:269
double GetMax() const
Returns the maximum value of the range.
Definition: range1d.h:94
friend GfRange1f operator/(const GfRange1f &r, double m)
scalar divide.
Definition: range1f.h:288
GfRange1f(float min, float max)
This constructor initializes the minimum and maximum points.
Definition: range1f.h:85
friend GfRange1f operator*(double m, const GfRange1f &r)
scalar multiply.
Definition: range1f.h:274
const GfRange1f & Union(float b)
Extend this to include b.
Definition: range1f.h:197
const GfRange1f & IntersectWith(const GfRange1f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range1f.h:217
void SetMin(float min)
Sets the minimum value of the range.
Definition: range1f.h:108
bool operator==(const GfRange1f &b) const
The min and max points must match exactly for equality.
Definition: range1f.h:301
bool IsEmpty() const
Returns whether the range is empty (max &lt; min).
Definition: range1f.h:114
static GfRange1f Union(const GfRange1f &a, const GfRange1f &b)
Returns the smallest GfRange1f which contains both a and b.
Definition: range1f.h:185