All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Groups Pages
range2f.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_RANGE2F_H
29 #define PXR_BASE_GF_RANGE2F_H
30 
33 
34 #include "pxr/pxr.h"
35 
36 #include "pxr/base/gf/api.h"
37 #include "pxr/base/gf/vec2d.h"
38 #include "pxr/base/gf/vec2f.h"
39 #include "pxr/base/gf/traits.h"
40 
41 #include <boost/functional/hash.hpp>
42 
43 #include <cfloat>
44 #include <cstddef>
45 #include <iosfwd>
46 
47 PXR_NAMESPACE_OPEN_SCOPE
48 
49 class GfRange2d;
50 class GfRange2f;
51 
52 template <>
53 struct GfIsGfRange<class GfRange2f> { static const bool value = true; };
54 
64 class GfRange2f
65 {
66 public:
67 
70 
71  static const size_t dimension = GfVec2f::dimension;
72  typedef GfVec2f::ScalarType ScalarType;
73 
75  // TODO check whether this can be deprecated.
76  void inline SetEmpty() {
77  _min[0] = _min[1] = FLT_MAX;
78  _max[0] = _max[1] = -FLT_MAX;
79  }
80 
83  SetEmpty();
84  }
85 
87  GfRange2f(const GfVec2f &min, const GfVec2f &max)
88  : _min(min), _max(max)
89  {
90  }
91 
93  const GfVec2f &GetMin() const { return _min; }
94 
96  const GfVec2f &GetMax() const { return _max; }
97 
99  GfVec2f GetSize() const { return _max - _min; }
100 
105  return static_cast<ScalarType>(0.5) * _min
106  + static_cast<ScalarType>(0.5) * _max;
107  }
108 
110  void SetMin(const GfVec2f &min) { _min = min; }
111 
113  void SetMax(const GfVec2f &max) { _max = max; }
114 
116  bool IsEmpty() const {
117  return _min[0] > _max[0] || _min[1] > _max[1];
118  }
119 
122  void ExtendBy(const GfVec2f &point) { UnionWith(point); }
123 
126  void ExtendBy(const GfRange2f &range) { UnionWith(range); }
127 
130  bool Contains(const GfVec2f &point) const {
131  return (point[0] >= _min[0] && point[0] <= _max[0]
132  && point[1] >= _min[1] && point[1] <= _max[1]);
133  }
134 
138  bool Contains(const GfRange2f &range) const {
139  return Contains(range._min) && Contains(range._max);
140  }
141 
145  bool IsInside(const GfVec2f &point) const {
146  return Contains(point);
147  }
148 
153  bool IsInside(const GfRange2f &range) const {
154  return Contains(range);
155  }
156 
160  bool IsOutside(const GfRange2f &range) const {
161  return ((range._max[0] < _min[0] || range._min[0] > _max[0])
162  || (range._max[1] < _min[1] || range._min[1] > _max[1]));
163  }
164 
166  static GfRange2f GetUnion(const GfRange2f &a, const GfRange2f &b) {
167  GfRange2f res = a;
168  _FindMin(res._min,b._min);
169  _FindMax(res._max,b._max);
170  return res;
171  }
172 
174  const GfRange2f &UnionWith(const GfRange2f &b) {
175  _FindMin(_min,b._min);
176  _FindMax(_max,b._max);
177  return *this;
178  }
179 
181  const GfRange2f &UnionWith(const GfVec2f &b) {
182  _FindMin(_min,b);
183  _FindMax(_max,b);
184  return *this;
185  }
186 
189  static GfRange2f Union(const GfRange2f &a, const GfRange2f &b) {
190  return GetUnion(a, b);
191  }
192 
195  const GfRange2f &Union(const GfRange2f &b) {
196  return UnionWith(b);
197  }
198 
201  const GfRange2f &Union(const GfVec2f &b) {
202  return UnionWith(b);
203  }
204 
206  static GfRange2f GetIntersection(const GfRange2f &a, const GfRange2f &b) {
207  GfRange2f res = a;
208  _FindMax(res._min,b._min);
209  _FindMin(res._max,b._max);
210  return res;
211  }
212 
215  static GfRange2f Intersection(const GfRange2f &a, const GfRange2f &b) {
216  return GetIntersection(a, b);
217  }
218 
221  const GfRange2f &IntersectWith(const GfRange2f &b) {
222  _FindMax(_min,b._min);
223  _FindMin(_max,b._max);
224  return *this;
225  }
226 
230  const GfRange2f &Intersection(const GfRange2f &b) {
231  return IntersectWith(b);
232  }
233 
236  _min += b._min;
237  _max += b._max;
238  return *this;
239  }
240 
243  _min -= b._max;
244  _max -= b._min;
245  return *this;
246  }
247 
249  GfRange2f operator *=(double m) {
250  if (m > 0) {
251  _min *= m;
252  _max *= m;
253  } else {
254  GfVec2f tmp = _min;
255  _min = _max * m;
256  _max = tmp * m;
257  }
258  return *this;
259  }
260 
262  GfRange2f operator /=(double m) {
263  return *this *= (1.0 / m);
264  }
265 
267  GfRange2f operator +(const GfRange2f &b) const {
268  return GfRange2f(_min + b._min, _max + b._max);
269  }
270 
271 
273  GfRange2f operator -(const GfRange2f &b) const {
274  return GfRange2f(_min - b._max, _max - b._min);
275  }
276 
278  friend GfRange2f operator *(double m, const GfRange2f &r) {
279  return (m > 0 ?
280  GfRange2f(r._min*m, r._max*m) :
281  GfRange2f(r._max*m, r._min*m));
282  }
283 
285  friend GfRange2f operator *(const GfRange2f &r, double m) {
286  return (m > 0 ?
287  GfRange2f(r._min*m, r._max*m) :
288  GfRange2f(r._max*m, r._min*m));
289  }
290 
292  friend GfRange2f operator /(const GfRange2f &r, double m) {
293  return r * (1.0 / m);
294  }
295 
297  friend inline size_t hash_value(const GfRange2f &r) {
298  size_t h = 0;
299  boost::hash_combine(h, r._min);
300  boost::hash_combine(h, r._max);
301  return h;
302  }
303 
305  bool operator ==(const GfRange2f &b) const {
306  return (_min == b._min && _max == b._max);
307  }
308 
309  bool operator !=(const GfRange2f &b) const {
310  return !(*this == b);
311  }
312 
317  GF_API inline bool operator ==(const GfRange2d& other) const;
318  GF_API inline bool operator !=(const GfRange2d& other) const;
319 
321  GF_API
322  double GetDistanceSquared(const GfVec2f &p) const;
323 
326  GF_API
327  GfVec2f GetCorner(size_t i) const;
328 
331  GF_API
332  GfRange2f GetQuadrant(size_t i) const;
333 
335  GF_API
336  static const GfRange2f UnitSquare;
337 
338  private:
340  GfVec2f _min, _max;
341 
343  static void _FindMin(GfVec2f &dest, const GfVec2f &point) {
344  if (point[0] < dest[0]) dest[0] = point[0];
345  if (point[1] < dest[1]) dest[1] = point[1];
346  }
347 
349  static void _FindMax(GfVec2f &dest, const GfVec2f &point) {
350  if (point[0] > dest[0]) dest[0] = point[0];
351  if (point[1] > dest[1]) dest[1] = point[1];
352  }
353 };
354 
357 GF_API std::ostream& operator<<(std::ostream &, GfRange2f const &);
358 
359 PXR_NAMESPACE_CLOSE_SCOPE
360 #include "pxr/base/gf/range2d.h"
361 PXR_NAMESPACE_OPEN_SCOPE
362 
363 inline bool
364 GfRange2f::operator ==(const GfRange2d& other) const {
365  return _min == GfVec2f(other.GetMin()) &&
366  _max == GfVec2f(other.GetMax());
367 }
368 
369 inline bool
370 GfRange2f::operator !=(const GfRange2d& other) const {
371  return !(*this == other);
372 }
373 
374 
375 PXR_NAMESPACE_CLOSE_SCOPE
376 
377 #endif // PXR_BASE_GF_RANGE2F_H
void SetMax(const GfVec2f &max)
Sets the maximum value of the range.
Definition: range2f.h:113
const GfVec2f & GetMin() const
Returns the minimum value of the range.
Definition: range2f.h:93
bool Contains(const GfRange2f &range) const
Returns true if the range is located entirely inside the range.
Definition: range2f.h:138
void SetEmpty()
Sets the range to an empty interval.
Definition: range2f.h:76
GfVec2f GetSize() const
Returns the size of the range.
Definition: range2f.h:99
GfRange2f operator/=(double m)
unary division.
Definition: range2f.h:262
const GfVec2d & GetMin() const
Returns the minimum value of the range.
Definition: range2d.h:93
const GfRange2f & UnionWith(const GfRange2f &b)
Extend this to include b.
Definition: range2f.h:174
const GfVec2f & GetMax() const
Returns the maximum value of the range.
Definition: range2f.h:96
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
GfRange2f operator+=(const GfRange2f &b)
unary sum.
Definition: range2f.h:235
bool IsInside(const GfVec2f &point) const
Returns true if the point is located inside the range.
Definition: range2f.h:145
const GfRange2f & Union(const GfVec2f &b)
Extend this to include b.
Definition: range2f.h:201
static GfRange2f Union(const GfRange2f &a, const GfRange2f &b)
Returns the smallest GfRange2f which contains both a and b.
Definition: range2f.h:189
GF_API GfRange2f GetQuadrant(size_t i) const
Returns the ith quadrant of the range, in the following order: SW, SE, NW, NE.
GF_API double GetDistanceSquared(const GfVec2f &p) const
Compute the squared distance from a point to the range.
float ScalarType
Scalar element type and dimension.
Definition: vec2f.h:67
static GfRange2f GetUnion(const GfRange2f &a, const GfRange2f &b)
Returns the smallest GfRange2f which contains both a and b.
Definition: range2f.h:166
GfRange2f()
The default constructor creates an empty range.
Definition: range2f.h:82
GfRange2f operator*=(double m)
unary multiply.
Definition: range2f.h:249
bool Contains(const GfVec2f &point) const
Returns true if the point is located inside the range.
Definition: range2f.h:130
friend size_t hash_value(const GfRange2f &r)
hash.
Definition: range2f.h:297
static GfRange2f Intersection(const GfRange2f &a, const GfRange2f &b)
Returns a GfRange2f that describes the intersection of a and b.
Definition: range2f.h:215
GfRange2f operator-(const GfRange2f &b) const
binary difference.
Definition: range2f.h:273
Basic type: 2-dimensional floating point range.
Definition: range2d.h:64
GfRange2f operator-=(const GfRange2f &b)
unary difference.
Definition: range2f.h:242
friend GfRange2f operator*(double m, const GfRange2f &r)
scalar multiply.
Definition: range2f.h:278
GF_API GfVec2f GetCorner(size_t i) const
Returns the ith corner of the range, in the following order: SW, SE, NW, NE.
bool IsEmpty() const
Returns whether the range is empty (max &lt; min).
Definition: range2f.h:116
const GfRange2f & Union(const GfRange2f &b)
Extend this to include b.
Definition: range2f.h:195
GfRange2f(const GfVec2f &min, const GfVec2f &max)
This constructor initializes the minimum and maximum points.
Definition: range2f.h:87
const GfRange2f & IntersectWith(const GfRange2f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range2f.h:221
const GfRange2f & Intersection(const GfRange2f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range2f.h:230
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
bool IsInside(const GfRange2f &range) const
Returns true if the range is located entirely inside the range.
Definition: range2f.h:153
const GfRange2f & UnionWith(const GfVec2f &b)
Extend this to include b.
Definition: range2f.h:181
bool IsOutside(const GfRange2f &range) const
Returns true if the range is located entirely outside the range.
Definition: range2f.h:160
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
void SetMin(const GfVec2f &min)
Sets the minimum value of the range.
Definition: range2f.h:110
static GF_API const GfRange2f UnitSquare
The unit square.
Definition: range2f.h:336
GfVec2f MinMaxType
Helper typedef.
Definition: range2f.h:69
GfRange2f operator+(const GfRange2f &b) const
binary sum.
Definition: range2f.h:267
bool operator==(const GfRange2f &b) const
The min and max points must match exactly for equality.
Definition: range2f.h:305
static GfRange2f GetIntersection(const GfRange2f &a, const GfRange2f &b)
Returns a GfRange2f that describes the intersection of a and b.
Definition: range2f.h:206
friend GfRange2f operator/(const GfRange2f &r, double m)
scalar divide.
Definition: range2f.h:292
void ExtendBy(const GfVec2f &point)
Modifies the range if necessary to surround the given value.
Definition: range2f.h:122
GfVec2f GetMidpoint() const
Returns the midpoint of the range, that is, 0.5*(min+max).
Definition: range2f.h:104
void ExtendBy(const GfRange2f &range)
Modifies the range if necessary to surround the given range.
Definition: range2f.h:126
Basic type: 2-dimensional floating point range.
Definition: range2f.h:64
const GfVec2d & GetMax() const
Returns the maximum value of the range.
Definition: range2d.h:96