Loading...
Searching...
No Matches
range2f.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//
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_RANGE2F_H
12#define PXR_BASE_GF_RANGE2F_H
13
16
17#include "pxr/pxr.h"
18
19#include "pxr/base/gf/api.h"
20#include "pxr/base/gf/vec2d.h"
21#include "pxr/base/gf/vec2f.h"
22#include "pxr/base/gf/traits.h"
23#include "pxr/base/tf/hash.h"
24
25#include <cfloat>
26#include <cstddef>
27#include <iosfwd>
28
29PXR_NAMESPACE_OPEN_SCOPE
30
31class GfRange2d;
32class GfRange2f;
33
34template <>
35struct GfIsGfRange<class GfRange2f> { static const bool value = true; };
36
47{
48public:
49
52
53 static const size_t dimension = GfVec2f::dimension;
54 typedef GfVec2f::ScalarType ScalarType;
55
57 // TODO check whether this can be deprecated.
58 void inline SetEmpty() {
59 _min[0] = _min[1] = FLT_MAX;
60 _max[0] = _max[1] = -FLT_MAX;
61 }
62
65 SetEmpty();
66 }
67
69 GfRange2f(const GfVec2f &min, const GfVec2f &max)
70 : _min(min), _max(max)
71 {
72 }
73
74
76 GF_API
77 explicit GfRange2f(class GfRange2d const &other);
78
80 const GfVec2f &GetMin() const { return _min; }
81
83 const GfVec2f &GetMax() const { return _max; }
84
86 GfVec2f GetSize() const { return _max - _min; }
87
92 return static_cast<ScalarType>(0.5) * _min
93 + static_cast<ScalarType>(0.5) * _max;
94 }
95
97 void SetMin(const GfVec2f &min) { _min = min; }
98
100 void SetMax(const GfVec2f &max) { _max = max; }
101
103 bool IsEmpty() const {
104 return _min[0] > _max[0] || _min[1] > _max[1];
105 }
106
109 void ExtendBy(const GfVec2f &point) { UnionWith(point); }
110
113 void ExtendBy(const GfRange2f &range) { UnionWith(range); }
114
117 bool Contains(const GfVec2f &point) const {
118 return (point[0] >= _min[0] && point[0] <= _max[0]
119 && point[1] >= _min[1] && point[1] <= _max[1]);
120 }
121
125 bool Contains(const GfRange2f &range) const {
126 return Contains(range._min) && Contains(range._max);
127 }
128
132 bool IsInside(const GfVec2f &point) const {
133 return Contains(point);
134 }
135
140 bool IsInside(const GfRange2f &range) const {
141 return Contains(range);
142 }
143
147 bool IsOutside(const GfRange2f &range) const {
148 return ((range._max[0] < _min[0] || range._min[0] > _max[0])
149 || (range._max[1] < _min[1] || range._min[1] > _max[1]));
150 }
151
153 static GfRange2f GetUnion(const GfRange2f &a, const GfRange2f &b) {
154 GfRange2f res = a;
155 _FindMin(res._min,b._min);
156 _FindMax(res._max,b._max);
157 return res;
158 }
159
161 const GfRange2f &UnionWith(const GfRange2f &b) {
162 _FindMin(_min,b._min);
163 _FindMax(_max,b._max);
164 return *this;
165 }
166
168 const GfRange2f &UnionWith(const GfVec2f &b) {
169 _FindMin(_min,b);
170 _FindMax(_max,b);
171 return *this;
172 }
173
176 static GfRange2f Union(const GfRange2f &a, const GfRange2f &b) {
177 return GetUnion(a, b);
178 }
179
182 const GfRange2f &Union(const GfRange2f &b) {
183 return UnionWith(b);
184 }
185
188 const GfRange2f &Union(const GfVec2f &b) {
189 return UnionWith(b);
190 }
191
193 static GfRange2f GetIntersection(const GfRange2f &a, const GfRange2f &b) {
194 GfRange2f res = a;
195 _FindMax(res._min,b._min);
196 _FindMin(res._max,b._max);
197 return res;
198 }
199
202 static GfRange2f Intersection(const GfRange2f &a, const GfRange2f &b) {
203 return GetIntersection(a, b);
204 }
205
209 _FindMax(_min,b._min);
210 _FindMin(_max,b._max);
211 return *this;
212 }
213
218 return IntersectWith(b);
219 }
220
223 _min += b._min;
224 _max += b._max;
225 return *this;
226 }
227
230 _min -= b._max;
231 _max -= b._min;
232 return *this;
233 }
234
237 if (m > 0) {
238 _min *= m;
239 _max *= m;
240 } else {
241 GfVec2f tmp = _min;
242 _min = _max * m;
243 _max = tmp * m;
244 }
245 return *this;
246 }
247
250 return *this *= (1.0 / m);
251 }
252
255 return GfRange2f(_min + b._min, _max + b._max);
256 }
257
258
261 return GfRange2f(_min - b._max, _max - b._min);
262 }
263
265 friend GfRange2f operator *(double m, const GfRange2f &r) {
266 return (m > 0 ?
267 GfRange2f(r._min*m, r._max*m) :
268 GfRange2f(r._max*m, r._min*m));
269 }
270
272 friend GfRange2f operator *(const GfRange2f &r, double m) {
273 return (m > 0 ?
274 GfRange2f(r._min*m, r._max*m) :
275 GfRange2f(r._max*m, r._min*m));
276 }
277
279 friend GfRange2f operator /(const GfRange2f &r, double m) {
280 return r * (1.0 / m);
281 }
282
284 friend inline size_t hash_value(const GfRange2f &r) {
285 return TfHash::Combine(r._min, r._max);
286 }
287
289 bool operator ==(const GfRange2f &b) const {
290 return (_min == b._min && _max == b._max);
291 }
292
293 bool operator !=(const GfRange2f &b) const {
294 return !(*this == b);
295 }
296
301 GF_API inline bool operator ==(const GfRange2d& other) const;
302 GF_API inline bool operator !=(const GfRange2d& other) const;
303
305 GF_API
306 double GetDistanceSquared(const GfVec2f &p) const;
307
310 GF_API
311 GfVec2f GetCorner(size_t i) const;
312
315 GF_API
316 GfRange2f GetQuadrant(size_t i) const;
317
319 GF_API
320 static const GfRange2f UnitSquare;
321
322 private:
324 GfVec2f _min, _max;
325
327 static void _FindMin(GfVec2f &dest, const GfVec2f &point) {
328 if (point[0] < dest[0]) dest[0] = point[0];
329 if (point[1] < dest[1]) dest[1] = point[1];
330 }
331
333 static void _FindMax(GfVec2f &dest, const GfVec2f &point) {
334 if (point[0] > dest[0]) dest[0] = point[0];
335 if (point[1] > dest[1]) dest[1] = point[1];
336 }
337};
338
341GF_API std::ostream& operator<<(std::ostream &, GfRange2f const &);
342
343PXR_NAMESPACE_CLOSE_SCOPE
344#include "pxr/base/gf/range2d.h"
345PXR_NAMESPACE_OPEN_SCOPE
346
347inline bool
349 return _min == GfVec2f(other.GetMin()) &&
350 _max == GfVec2f(other.GetMax());
351}
352
353inline bool
354GfRange2f::operator !=(const GfRange2d& other) const {
355 return !(*this == other);
356}
357
358
359PXR_NAMESPACE_CLOSE_SCOPE
360
361#endif // PXR_BASE_GF_RANGE2F_H
Basic type: 2-dimensional floating point range.
Definition: range2d.h:47
const GfVec2d & GetMax() const
Returns the maximum value of the range.
Definition: range2d.h:83
const GfVec2d & GetMin() const
Returns the minimum value of the range.
Definition: range2d.h:80
Basic type: 2-dimensional floating point range.
Definition: range2f.h:47
static GfRange2f GetUnion(const GfRange2f &a, const GfRange2f &b)
Returns the smallest GfRange2f which contains both a and b.
Definition: range2f.h:153
GfRange2f & operator-=(const GfRange2f &b)
unary difference.
Definition: range2f.h:229
void ExtendBy(const GfVec2f &point)
Modifies the range if necessary to surround the given value.
Definition: range2f.h:109
GF_API GfRange2f(class GfRange2d const &other)
Construct from GfRange2d.
void SetMax(const GfVec2f &max)
Sets the maximum value of the range.
Definition: range2f.h:100
GfRange2f & operator+=(const GfRange2f &b)
unary sum.
Definition: range2f.h:222
static GfRange2f Intersection(const GfRange2f &a, const GfRange2f &b)
Returns a GfRange2f that describes the intersection of a and b.
Definition: range2f.h:202
const GfRange2f & Intersection(const GfRange2f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range2f.h:217
GfRange2f & operator/=(double m)
unary division.
Definition: range2f.h:249
void ExtendBy(const GfRange2f &range)
Modifies the range if necessary to surround the given range.
Definition: range2f.h:113
bool IsOutside(const GfRange2f &range) const
Returns true if the range is located entirely outside the range.
Definition: range2f.h:147
const GfRange2f & Union(const GfVec2f &b)
Extend this to include b.
Definition: range2f.h:188
void SetMin(const GfVec2f &min)
Sets the minimum value of the range.
Definition: range2f.h:97
const GfRange2f & UnionWith(const GfVec2f &b)
Extend this to include b.
Definition: range2f.h:168
GfRange2f operator+(const GfRange2f &b) const
binary sum.
Definition: range2f.h:254
const GfVec2f & GetMin() const
Returns the minimum value of the range.
Definition: range2f.h:80
GfVec2f GetMidpoint() const
Returns the midpoint of the range, that is, 0.5*(min+max).
Definition: range2f.h:91
friend size_t hash_value(const GfRange2f &r)
hash.
Definition: range2f.h:284
const GfVec2f & GetMax() const
Returns the maximum value of the range.
Definition: range2f.h:83
static GfRange2f GetIntersection(const GfRange2f &a, const GfRange2f &b)
Returns a GfRange2f that describes the intersection of a and b.
Definition: range2f.h:193
static GfRange2f Union(const GfRange2f &a, const GfRange2f &b)
Returns the smallest GfRange2f which contains both a and b.
Definition: range2f.h:176
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 GfVec2f GetCorner(size_t i) const
Returns the ith corner 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.
bool IsEmpty() const
Returns whether the range is empty (max < min).
Definition: range2f.h:103
bool operator==(const GfRange2f &b) const
The min and max points must match exactly for equality.
Definition: range2f.h:289
GfRange2f operator-(const GfRange2f &b) const
binary difference.
Definition: range2f.h:260
bool IsInside(const GfVec2f &point) const
Returns true if the point is located inside the range.
Definition: range2f.h:132
bool IsInside(const GfRange2f &range) const
Returns true if the range is located entirely inside the range.
Definition: range2f.h:140
GfVec2f MinMaxType
Helper typedef.
Definition: range2f.h:51
const GfRange2f & Union(const GfRange2f &b)
Extend this to include b.
Definition: range2f.h:182
GfRange2f(const GfVec2f &min, const GfVec2f &max)
This constructor initializes the minimum and maximum points.
Definition: range2f.h:69
void SetEmpty()
Sets the range to an empty interval.
Definition: range2f.h:58
bool Contains(const GfRange2f &range) const
Returns true if the range is located entirely inside the range.
Definition: range2f.h:125
static GF_API const GfRange2f UnitSquare
The unit square.
Definition: range2f.h:320
const GfRange2f & IntersectWith(const GfRange2f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range2f.h:208
friend GfRange2f operator*(double m, const GfRange2f &r)
scalar multiply.
Definition: range2f.h:265
friend GfRange2f operator/(const GfRange2f &r, double m)
scalar divide.
Definition: range2f.h:279
GfRange2f()
The default constructor creates an empty range.
Definition: range2f.h:64
const GfRange2f & UnionWith(const GfRange2f &b)
Extend this to include b.
Definition: range2f.h:161
GfRange2f & operator*=(double m)
unary multiply.
Definition: range2f.h:236
GfVec2f GetSize() const
Returns the size of the range.
Definition: range2f.h:86
bool Contains(const GfVec2f &point) const
Returns true if the point is located inside the range.
Definition: range2f.h:117
Basic type for a vector of 2 float components.
Definition: vec2f.h:46
float ScalarType
Scalar element type and dimension.
Definition: vec2f.h:49
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:487
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
A metafunction with a static const bool member 'value' that is true for GfRange types and false for a...
Definition: traits.h:40