Loading...
Searching...
No Matches
range2d.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_RANGE2D_H
12#define PXR_BASE_GF_RANGE2D_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 GfRange2d> { static const bool value = true; };
36
47{
48public:
49
52
53 static const size_t dimension = GfVec2d::dimension;
54 typedef GfVec2d::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 GfRange2d(const GfVec2d &min, const GfVec2d &max)
70 : _min(min), _max(max)
71 {
72 }
73
74
76 GF_API
77 GfRange2d(class GfRange2f const &other);
78
80 const GfVec2d &GetMin() const { return _min; }
81
83 const GfVec2d &GetMax() const { return _max; }
84
86 GfVec2d 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 GfVec2d &min) { _min = min; }
98
100 void SetMax(const GfVec2d &max) { _max = max; }
101
103 bool IsEmpty() const {
104 return _min[0] > _max[0] || _min[1] > _max[1];
105 }
106
109 void ExtendBy(const GfVec2d &point) { UnionWith(point); }
110
113 void ExtendBy(const GfRange2d &range) { UnionWith(range); }
114
117 bool Contains(const GfVec2d &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 GfRange2d &range) const {
126 return Contains(range._min) && Contains(range._max);
127 }
128
132 bool IsInside(const GfVec2d &point) const {
133 return Contains(point);
134 }
135
140 bool IsInside(const GfRange2d &range) const {
141 return Contains(range);
142 }
143
147 bool IsOutside(const GfRange2d &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 GfRange2d GetUnion(const GfRange2d &a, const GfRange2d &b) {
154 GfRange2d res = a;
155 _FindMin(res._min,b._min);
156 _FindMax(res._max,b._max);
157 return res;
158 }
159
161 const GfRange2d &UnionWith(const GfRange2d &b) {
162 _FindMin(_min,b._min);
163 _FindMax(_max,b._max);
164 return *this;
165 }
166
168 const GfRange2d &UnionWith(const GfVec2d &b) {
169 _FindMin(_min,b);
170 _FindMax(_max,b);
171 return *this;
172 }
173
176 static GfRange2d Union(const GfRange2d &a, const GfRange2d &b) {
177 return GetUnion(a, b);
178 }
179
182 const GfRange2d &Union(const GfRange2d &b) {
183 return UnionWith(b);
184 }
185
188 const GfRange2d &Union(const GfVec2d &b) {
189 return UnionWith(b);
190 }
191
193 static GfRange2d GetIntersection(const GfRange2d &a, const GfRange2d &b) {
194 GfRange2d res = a;
195 _FindMax(res._min,b._min);
196 _FindMin(res._max,b._max);
197 return res;
198 }
199
202 static GfRange2d Intersection(const GfRange2d &a, const GfRange2d &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 GfVec2d 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 GfRange2d(_min + b._min, _max + b._max);
256 }
257
258
261 return GfRange2d(_min - b._max, _max - b._min);
262 }
263
265 friend GfRange2d operator *(double m, const GfRange2d &r) {
266 return (m > 0 ?
267 GfRange2d(r._min*m, r._max*m) :
268 GfRange2d(r._max*m, r._min*m));
269 }
270
272 friend GfRange2d operator *(const GfRange2d &r, double m) {
273 return (m > 0 ?
274 GfRange2d(r._min*m, r._max*m) :
275 GfRange2d(r._max*m, r._min*m));
276 }
277
279 friend GfRange2d operator /(const GfRange2d &r, double m) {
280 return r * (1.0 / m);
281 }
282
284 friend inline size_t hash_value(const GfRange2d &r) {
285 return TfHash::Combine(r._min, r._max);
286 }
287
289 bool operator ==(const GfRange2d &b) const {
290 return (_min == b._min && _max == b._max);
291 }
292
293 bool operator !=(const GfRange2d &b) const {
294 return !(*this == b);
295 }
296
301 GF_API inline bool operator ==(const GfRange2f& other) const;
302 GF_API inline bool operator !=(const GfRange2f& other) const;
303
305 GF_API
306 double GetDistanceSquared(const GfVec2d &p) const;
307
310 GF_API
311 GfVec2d GetCorner(size_t i) const;
312
315 GF_API
316 GfRange2d GetQuadrant(size_t i) const;
317
319 GF_API
320 static const GfRange2d UnitSquare;
321
322 private:
324 GfVec2d _min, _max;
325
327 static void _FindMin(GfVec2d &dest, const GfVec2d &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(GfVec2d &dest, const GfVec2d &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 &, GfRange2d const &);
342
343PXR_NAMESPACE_CLOSE_SCOPE
344#include "pxr/base/gf/range2f.h"
345PXR_NAMESPACE_OPEN_SCOPE
346
347inline bool
349 return _min == GfVec2d(other.GetMin()) &&
350 _max == GfVec2d(other.GetMax());
351}
352
353inline bool
354GfRange2d::operator !=(const GfRange2f& other) const {
355 return !(*this == other);
356}
357
358
359PXR_NAMESPACE_CLOSE_SCOPE
360
361#endif // PXR_BASE_GF_RANGE2D_H
Basic type: 2-dimensional floating point range.
Definition: range2d.h:47
friend size_t hash_value(const GfRange2d &r)
hash.
Definition: range2d.h:284
void ExtendBy(const GfVec2d &point)
Modifies the range if necessary to surround the given value.
Definition: range2d.h:109
const GfRange2d & UnionWith(const GfVec2d &b)
Extend this to include b.
Definition: range2d.h:168
GfRange2d & operator-=(const GfRange2d &b)
unary difference.
Definition: range2d.h:229
const GfVec2d & GetMax() const
Returns the maximum value of the range.
Definition: range2d.h:83
GfRange2d & operator+=(const GfRange2d &b)
unary sum.
Definition: range2d.h:222
GF_API GfRange2d(class GfRange2f const &other)
Implicitly convert from GfRange2f.
GfRange2d & operator/=(double m)
unary division.
Definition: range2d.h:249
const GfVec2d & GetMin() const
Returns the minimum value of the range.
Definition: range2d.h:80
bool IsInside(const GfRange2d &range) const
Returns true if the range is located entirely inside the range.
Definition: range2d.h:140
const GfRange2d & UnionWith(const GfRange2d &b)
Extend this to include b.
Definition: range2d.h:161
bool operator==(const GfRange2d &b) const
The min and max points must match exactly for equality.
Definition: range2d.h:289
const GfRange2d & IntersectWith(const GfRange2d &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range2d.h:208
static GfRange2d GetUnion(const GfRange2d &a, const GfRange2d &b)
Returns the smallest GfRange2d which contains both a and b.
Definition: range2d.h:153
GF_API GfRange2d GetQuadrant(size_t i) const
Returns the ith quadrant of the range, in the following order: SW, SE, NW, NE.
static GF_API const GfRange2d UnitSquare
The unit square.
Definition: range2d.h:320
static GfRange2d GetIntersection(const GfRange2d &a, const GfRange2d &b)
Returns a GfRange2d that describes the intersection of a and b.
Definition: range2d.h:193
bool Contains(const GfRange2d &range) const
Returns true if the range is located entirely inside the range.
Definition: range2d.h:125
friend GfRange2d operator/(const GfRange2d &r, double m)
scalar divide.
Definition: range2d.h:279
GfVec2d GetMidpoint() const
Returns the midpoint of the range, that is, 0.5*(min+max).
Definition: range2d.h:91
bool IsEmpty() const
Returns whether the range is empty (max < min).
Definition: range2d.h:103
const GfRange2d & Union(const GfRange2d &b)
Extend this to include b.
Definition: range2d.h:182
static GfRange2d Union(const GfRange2d &a, const GfRange2d &b)
Returns the smallest GfRange2d which contains both a and b.
Definition: range2d.h:176
static GfRange2d Intersection(const GfRange2d &a, const GfRange2d &b)
Returns a GfRange2d that describes the intersection of a and b.
Definition: range2d.h:202
GfVec2d GetSize() const
Returns the size of the range.
Definition: range2d.h:86
GfVec2d MinMaxType
Helper typedef.
Definition: range2d.h:51
GfRange2d & operator*=(double m)
unary multiply.
Definition: range2d.h:236
void SetEmpty()
Sets the range to an empty interval.
Definition: range2d.h:58
bool IsOutside(const GfRange2d &range) const
Returns true if the range is located entirely outside the range.
Definition: range2d.h:147
friend GfRange2d operator*(double m, const GfRange2d &r)
scalar multiply.
Definition: range2d.h:265
void SetMax(const GfVec2d &max)
Sets the maximum value of the range.
Definition: range2d.h:100
bool Contains(const GfVec2d &point) const
Returns true if the point is located inside the range.
Definition: range2d.h:117
GfRange2d(const GfVec2d &min, const GfVec2d &max)
This constructor initializes the minimum and maximum points.
Definition: range2d.h:69
bool IsInside(const GfVec2d &point) const
Returns true if the point is located inside the range.
Definition: range2d.h:132
const GfRange2d & Union(const GfVec2d &b)
Extend this to include b.
Definition: range2d.h:188
void ExtendBy(const GfRange2d &range)
Modifies the range if necessary to surround the given range.
Definition: range2d.h:113
GfRange2d operator-(const GfRange2d &b) const
binary difference.
Definition: range2d.h:260
void SetMin(const GfVec2d &min)
Sets the minimum value of the range.
Definition: range2d.h:97
GfRange2d()
The default constructor creates an empty range.
Definition: range2d.h:64
GF_API double GetDistanceSquared(const GfVec2d &p) const
Compute the squared distance from a point to the range.
const GfRange2d & Intersection(const GfRange2d &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range2d.h:217
GF_API GfVec2d GetCorner(size_t i) const
Returns the ith corner of the range, in the following order: SW, SE, NW, NE.
GfRange2d operator+(const GfRange2d &b) const
binary sum.
Definition: range2d.h:254
Basic type: 2-dimensional floating point range.
Definition: range2f.h:47
const GfVec2f & GetMin() const
Returns the minimum value of the range.
Definition: range2f.h:80
const GfVec2f & GetMax() const
Returns the maximum value of the range.
Definition: range2f.h:83
Basic type for a vector of 2 double components.
Definition: vec2d.h:46
double ScalarType
Scalar element type and dimension.
Definition: vec2d.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