Loading...
Searching...
No Matches
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#include "pxr/base/tf/hash.h"
41
42#include <cfloat>
43#include <cstddef>
44#include <iosfwd>
45
46PXR_NAMESPACE_OPEN_SCOPE
47
48class GfRange2d;
49class GfRange2f;
50
51template <>
52struct GfIsGfRange<class GfRange2f> { static const bool value = true; };
53
64{
65public:
66
69
70 static const size_t dimension = GfVec2f::dimension;
71 typedef GfVec2f::ScalarType ScalarType;
72
74 // TODO check whether this can be deprecated.
75 void inline SetEmpty() {
76 _min[0] = _min[1] = FLT_MAX;
77 _max[0] = _max[1] = -FLT_MAX;
78 }
79
82 SetEmpty();
83 }
84
86 GfRange2f(const GfVec2f &min, const GfVec2f &max)
87 : _min(min), _max(max)
88 {
89 }
90
91
93 GF_API
94 explicit GfRange2f(class GfRange2d const &other);
95
97 const GfVec2f &GetMin() const { return _min; }
98
100 const GfVec2f &GetMax() const { return _max; }
101
103 GfVec2f GetSize() const { return _max - _min; }
104
109 return static_cast<ScalarType>(0.5) * _min
110 + static_cast<ScalarType>(0.5) * _max;
111 }
112
114 void SetMin(const GfVec2f &min) { _min = min; }
115
117 void SetMax(const GfVec2f &max) { _max = max; }
118
120 bool IsEmpty() const {
121 return _min[0] > _max[0] || _min[1] > _max[1];
122 }
123
126 void ExtendBy(const GfVec2f &point) { UnionWith(point); }
127
130 void ExtendBy(const GfRange2f &range) { UnionWith(range); }
131
134 bool Contains(const GfVec2f &point) const {
135 return (point[0] >= _min[0] && point[0] <= _max[0]
136 && point[1] >= _min[1] && point[1] <= _max[1]);
137 }
138
142 bool Contains(const GfRange2f &range) const {
143 return Contains(range._min) && Contains(range._max);
144 }
145
149 bool IsInside(const GfVec2f &point) const {
150 return Contains(point);
151 }
152
157 bool IsInside(const GfRange2f &range) const {
158 return Contains(range);
159 }
160
164 bool IsOutside(const GfRange2f &range) const {
165 return ((range._max[0] < _min[0] || range._min[0] > _max[0])
166 || (range._max[1] < _min[1] || range._min[1] > _max[1]));
167 }
168
170 static GfRange2f GetUnion(const GfRange2f &a, const GfRange2f &b) {
171 GfRange2f res = a;
172 _FindMin(res._min,b._min);
173 _FindMax(res._max,b._max);
174 return res;
175 }
176
178 const GfRange2f &UnionWith(const GfRange2f &b) {
179 _FindMin(_min,b._min);
180 _FindMax(_max,b._max);
181 return *this;
182 }
183
185 const GfRange2f &UnionWith(const GfVec2f &b) {
186 _FindMin(_min,b);
187 _FindMax(_max,b);
188 return *this;
189 }
190
193 static GfRange2f Union(const GfRange2f &a, const GfRange2f &b) {
194 return GetUnion(a, b);
195 }
196
199 const GfRange2f &Union(const GfRange2f &b) {
200 return UnionWith(b);
201 }
202
205 const GfRange2f &Union(const GfVec2f &b) {
206 return UnionWith(b);
207 }
208
210 static GfRange2f GetIntersection(const GfRange2f &a, const GfRange2f &b) {
211 GfRange2f res = a;
212 _FindMax(res._min,b._min);
213 _FindMin(res._max,b._max);
214 return res;
215 }
216
219 static GfRange2f Intersection(const GfRange2f &a, const GfRange2f &b) {
220 return GetIntersection(a, b);
221 }
222
226 _FindMax(_min,b._min);
227 _FindMin(_max,b._max);
228 return *this;
229 }
230
235 return IntersectWith(b);
236 }
237
240 _min += b._min;
241 _max += b._max;
242 return *this;
243 }
244
247 _min -= b._max;
248 _max -= b._min;
249 return *this;
250 }
251
254 if (m > 0) {
255 _min *= m;
256 _max *= m;
257 } else {
258 GfVec2f tmp = _min;
259 _min = _max * m;
260 _max = tmp * m;
261 }
262 return *this;
263 }
264
267 return *this *= (1.0 / m);
268 }
269
272 return GfRange2f(_min + b._min, _max + b._max);
273 }
274
275
278 return GfRange2f(_min - b._max, _max - b._min);
279 }
280
282 friend GfRange2f operator *(double m, const GfRange2f &r) {
283 return (m > 0 ?
284 GfRange2f(r._min*m, r._max*m) :
285 GfRange2f(r._max*m, r._min*m));
286 }
287
289 friend GfRange2f operator *(const GfRange2f &r, double m) {
290 return (m > 0 ?
291 GfRange2f(r._min*m, r._max*m) :
292 GfRange2f(r._max*m, r._min*m));
293 }
294
296 friend GfRange2f operator /(const GfRange2f &r, double m) {
297 return r * (1.0 / m);
298 }
299
301 friend inline size_t hash_value(const GfRange2f &r) {
302 return TfHash::Combine(r._min, r._max);
303 }
304
306 bool operator ==(const GfRange2f &b) const {
307 return (_min == b._min && _max == b._max);
308 }
309
310 bool operator !=(const GfRange2f &b) const {
311 return !(*this == b);
312 }
313
318 GF_API inline bool operator ==(const GfRange2d& other) const;
319 GF_API inline bool operator !=(const GfRange2d& other) const;
320
322 GF_API
323 double GetDistanceSquared(const GfVec2f &p) const;
324
327 GF_API
328 GfVec2f GetCorner(size_t i) const;
329
332 GF_API
333 GfRange2f GetQuadrant(size_t i) const;
334
336 GF_API
337 static const GfRange2f UnitSquare;
338
339 private:
341 GfVec2f _min, _max;
342
344 static void _FindMin(GfVec2f &dest, const GfVec2f &point) {
345 if (point[0] < dest[0]) dest[0] = point[0];
346 if (point[1] < dest[1]) dest[1] = point[1];
347 }
348
350 static void _FindMax(GfVec2f &dest, const GfVec2f &point) {
351 if (point[0] > dest[0]) dest[0] = point[0];
352 if (point[1] > dest[1]) dest[1] = point[1];
353 }
354};
355
358GF_API std::ostream& operator<<(std::ostream &, GfRange2f const &);
359
360PXR_NAMESPACE_CLOSE_SCOPE
361#include "pxr/base/gf/range2d.h"
362PXR_NAMESPACE_OPEN_SCOPE
363
364inline bool
366 return _min == GfVec2f(other.GetMin()) &&
367 _max == GfVec2f(other.GetMax());
368}
369
370inline bool
371GfRange2f::operator !=(const GfRange2d& other) const {
372 return !(*this == other);
373}
374
375
376PXR_NAMESPACE_CLOSE_SCOPE
377
378#endif // PXR_BASE_GF_RANGE2F_H
Basic type: 2-dimensional floating point range.
Definition: range2d.h:64
const GfVec2d & GetMax() const
Returns the maximum value of the range.
Definition: range2d.h:100
const GfVec2d & GetMin() const
Returns the minimum value of the range.
Definition: range2d.h:97
Basic type: 2-dimensional floating point range.
Definition: range2f.h:64
static GfRange2f GetUnion(const GfRange2f &a, const GfRange2f &b)
Returns the smallest GfRange2f which contains both a and b.
Definition: range2f.h:170
GfRange2f & operator-=(const GfRange2f &b)
unary difference.
Definition: range2f.h:246
void ExtendBy(const GfVec2f &point)
Modifies the range if necessary to surround the given value.
Definition: range2f.h:126
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:117
GfRange2f & operator+=(const GfRange2f &b)
unary sum.
Definition: range2f.h:239
static GfRange2f Intersection(const GfRange2f &a, const GfRange2f &b)
Returns a GfRange2f that describes the intersection of a and b.
Definition: range2f.h:219
const GfRange2f & Intersection(const GfRange2f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range2f.h:234
GfRange2f & operator/=(double m)
unary division.
Definition: range2f.h:266
void ExtendBy(const GfRange2f &range)
Modifies the range if necessary to surround the given range.
Definition: range2f.h:130
bool IsOutside(const GfRange2f &range) const
Returns true if the range is located entirely outside the range.
Definition: range2f.h:164
const GfRange2f & Union(const GfVec2f &b)
Extend this to include b.
Definition: range2f.h:205
void SetMin(const GfVec2f &min)
Sets the minimum value of the range.
Definition: range2f.h:114
const GfRange2f & UnionWith(const GfVec2f &b)
Extend this to include b.
Definition: range2f.h:185
GfRange2f operator+(const GfRange2f &b) const
binary sum.
Definition: range2f.h:271
const GfVec2f & GetMin() const
Returns the minimum value of the range.
Definition: range2f.h:97
GfVec2f GetMidpoint() const
Returns the midpoint of the range, that is, 0.5*(min+max).
Definition: range2f.h:108
friend size_t hash_value(const GfRange2f &r)
hash.
Definition: range2f.h:301
const GfVec2f & GetMax() const
Returns the maximum value of the range.
Definition: range2f.h:100
static GfRange2f GetIntersection(const GfRange2f &a, const GfRange2f &b)
Returns a GfRange2f that describes the intersection of a and b.
Definition: range2f.h:210
static GfRange2f Union(const GfRange2f &a, const GfRange2f &b)
Returns the smallest GfRange2f which contains both a and b.
Definition: range2f.h:193
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:120
bool operator==(const GfRange2f &b) const
The min and max points must match exactly for equality.
Definition: range2f.h:306
GfRange2f operator-(const GfRange2f &b) const
binary difference.
Definition: range2f.h:277
bool IsInside(const GfVec2f &point) const
Returns true if the point is located inside the range.
Definition: range2f.h:149
bool IsInside(const GfRange2f &range) const
Returns true if the range is located entirely inside the range.
Definition: range2f.h:157
GfVec2f MinMaxType
Helper typedef.
Definition: range2f.h:68
const GfRange2f & Union(const GfRange2f &b)
Extend this to include b.
Definition: range2f.h:199
GfRange2f(const GfVec2f &min, const GfVec2f &max)
This constructor initializes the minimum and maximum points.
Definition: range2f.h:86
void SetEmpty()
Sets the range to an empty interval.
Definition: range2f.h:75
bool Contains(const GfRange2f &range) const
Returns true if the range is located entirely inside the range.
Definition: range2f.h:142
static GF_API const GfRange2f UnitSquare
The unit square.
Definition: range2f.h:337
const GfRange2f & IntersectWith(const GfRange2f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range2f.h:225
friend GfRange2f operator*(double m, const GfRange2f &r)
scalar multiply.
Definition: range2f.h:282
friend GfRange2f operator/(const GfRange2f &r, double m)
scalar divide.
Definition: range2f.h:296
GfRange2f()
The default constructor creates an empty range.
Definition: range2f.h:81
const GfRange2f & UnionWith(const GfRange2f &b)
Extend this to include b.
Definition: range2f.h:178
GfRange2f & operator*=(double m)
unary multiply.
Definition: range2f.h:253
GfVec2f GetSize() const
Returns the size of the range.
Definition: range2f.h:103
bool Contains(const GfVec2f &point) const
Returns true if the point is located inside the range.
Definition: range2f.h:134
Basic type for a vector of 2 float components.
Definition: vec2f.h:63
float ScalarType
Scalar element type and dimension.
Definition: vec2f.h:66
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Definition: hash.h:492
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:57