Loading...
Searching...
No Matches
range1f.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_RANGE1F_H
12#define PXR_BASE_GF_RANGE1F_H
13
16
17#include "pxr/pxr.h"
18
19#include "pxr/base/gf/api.h"
20#include "pxr/base/gf/traits.h"
21#include "pxr/base/tf/hash.h"
22
23#include <cfloat>
24#include <cstddef>
25#include <iosfwd>
26
27PXR_NAMESPACE_OPEN_SCOPE
28
29class GfRange1d;
30class GfRange1f;
31
32template <>
33struct GfIsGfRange<class GfRange1f> { static const bool value = true; };
34
45{
46public:
47
49 typedef float MinMaxType;
50
51 static const size_t dimension = 1;
52 typedef MinMaxType ScalarType;
53
55 // TODO check whether this can be deprecated.
56 void inline SetEmpty() {
57 _min = FLT_MAX;
58 _max = -FLT_MAX;
59 }
60
63 SetEmpty();
64 }
65
67 GfRange1f(float min, float max)
68 : _min(min), _max(max)
69 {
70 }
71
72
74 GF_API
75 explicit GfRange1f(class GfRange1d const &other);
76
78 float GetMin() const { return _min; }
79
81 float GetMax() const { return _max; }
82
84 float GetSize() const { return _max - _min; }
85
89 float GetMidpoint() const {
90 return static_cast<ScalarType>(0.5) * _min
91 + static_cast<ScalarType>(0.5) * _max;
92 }
93
95 void SetMin(float min) { _min = min; }
96
98 void SetMax(float max) { _max = max; }
99
101 bool IsEmpty() const {
102 return _min > _max;
103 }
104
107 void ExtendBy(float point) { UnionWith(point); }
108
111 void ExtendBy(const GfRange1f &range) { UnionWith(range); }
112
115 bool Contains(float point) const {
116 return (point >= _min && point <= _max);
117 }
118
122 bool Contains(const GfRange1f &range) const {
123 return Contains(range._min) && Contains(range._max);
124 }
125
129 bool IsInside(float point) const {
130 return Contains(point);
131 }
132
137 bool IsInside(const GfRange1f &range) const {
138 return Contains(range);
139 }
140
144 bool IsOutside(const GfRange1f &range) const {
145 return (range._max < _min || range._min > _max);
146 }
147
149 static GfRange1f GetUnion(const GfRange1f &a, const GfRange1f &b) {
150 GfRange1f res = a;
151 _FindMin(res._min,b._min);
152 _FindMax(res._max,b._max);
153 return res;
154 }
155
157 const GfRange1f &UnionWith(const GfRange1f &b) {
158 _FindMin(_min,b._min);
159 _FindMax(_max,b._max);
160 return *this;
161 }
162
164 const GfRange1f &UnionWith(float b) {
165 _FindMin(_min,b);
166 _FindMax(_max,b);
167 return *this;
168 }
169
172 static GfRange1f Union(const GfRange1f &a, const GfRange1f &b) {
173 return GetUnion(a, b);
174 }
175
178 const GfRange1f &Union(const GfRange1f &b) {
179 return UnionWith(b);
180 }
181
184 const GfRange1f &Union(float b) {
185 return UnionWith(b);
186 }
187
189 static GfRange1f GetIntersection(const GfRange1f &a, const GfRange1f &b) {
190 GfRange1f res = a;
191 _FindMax(res._min,b._min);
192 _FindMin(res._max,b._max);
193 return res;
194 }
195
198 static GfRange1f Intersection(const GfRange1f &a, const GfRange1f &b) {
199 return GetIntersection(a, b);
200 }
201
205 _FindMax(_min,b._min);
206 _FindMin(_max,b._max);
207 return *this;
208 }
209
214 return IntersectWith(b);
215 }
216
219 _min += b._min;
220 _max += b._max;
221 return *this;
222 }
223
226 _min -= b._max;
227 _max -= b._min;
228 return *this;
229 }
230
233 if (m > 0) {
234 _min *= m;
235 _max *= m;
236 } else {
237 float tmp = _min;
238 _min = _max * m;
239 _max = tmp * m;
240 }
241 return *this;
242 }
243
246 return *this *= (1.0 / m);
247 }
248
251 return GfRange1f(_min + b._min, _max + b._max);
252 }
253
254
257 return GfRange1f(_min - b._max, _max - b._min);
258 }
259
261 friend GfRange1f operator *(double m, const GfRange1f &r) {
262 return (m > 0 ?
263 GfRange1f(r._min*m, r._max*m) :
264 GfRange1f(r._max*m, r._min*m));
265 }
266
268 friend GfRange1f operator *(const GfRange1f &r, double m) {
269 return (m > 0 ?
270 GfRange1f(r._min*m, r._max*m) :
271 GfRange1f(r._max*m, r._min*m));
272 }
273
275 friend GfRange1f operator /(const GfRange1f &r, double m) {
276 return r * (1.0 / m);
277 }
278
280 friend inline size_t hash_value(const GfRange1f &r) {
281 return TfHash::Combine(r._min, r._max);
282 }
283
285 bool operator ==(const GfRange1f &b) const {
286 return (_min == b._min && _max == b._max);
287 }
288
289 bool operator !=(const GfRange1f &b) const {
290 return !(*this == b);
291 }
292
297 GF_API inline bool operator ==(const GfRange1d& other) const;
298 GF_API inline bool operator !=(const GfRange1d& other) const;
299
301 GF_API
302 double GetDistanceSquared(float p) const;
303
304
305 private:
307 float _min, _max;
308
310 static void _FindMin(float &dest, float point) {
311 if (point < dest) dest = point;
312 }
313
315 static void _FindMax(float &dest, float point) {
316 if (point > dest) dest = point;
317 }
318};
319
322GF_API std::ostream& operator<<(std::ostream &, GfRange1f const &);
323
324PXR_NAMESPACE_CLOSE_SCOPE
325#include "pxr/base/gf/range1d.h"
326PXR_NAMESPACE_OPEN_SCOPE
327
328inline bool
330 return _min == float(other.GetMin()) &&
331 _max == float(other.GetMax());
332}
333
334inline bool
335GfRange1f::operator !=(const GfRange1d& other) const {
336 return !(*this == other);
337}
338
339
340PXR_NAMESPACE_CLOSE_SCOPE
341
342#endif // PXR_BASE_GF_RANGE1F_H
Basic type: 1-dimensional floating point range.
Definition: range1d.h:45
double GetMax() const
Returns the maximum value of the range.
Definition: range1d.h:81
double GetMin() const
Returns the minimum value of the range.
Definition: range1d.h:78
Basic type: 1-dimensional floating point range.
Definition: range1f.h:45
friend GfRange1f operator*(double m, const GfRange1f &r)
scalar multiply.
Definition: range1f.h:261
GfRange1f operator-(const GfRange1f &b) const
binary difference.
Definition: range1f.h:256
const GfRange1f & Intersection(const GfRange1f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range1f.h:213
bool IsInside(float point) const
Returns true if the point is located inside the range.
Definition: range1f.h:129
void ExtendBy(const GfRange1f &range)
Modifies the range if necessary to surround the given range.
Definition: range1f.h:111
GfRange1f()
The default constructor creates an empty range.
Definition: range1f.h:62
GfRange1f & operator/=(double m)
unary division.
Definition: range1f.h:245
GF_API double GetDistanceSquared(float p) const
Compute the squared distance from a point to the range.
GfRange1f & operator+=(const GfRange1f &b)
unary sum.
Definition: range1f.h:218
const GfRange1f & Union(const GfRange1f &b)
Extend this to include b.
Definition: range1f.h:178
bool Contains(const GfRange1f &range) const
Returns true if the range is located entirely inside the range.
Definition: range1f.h:122
float GetMidpoint() const
Returns the midpoint of the range, that is, 0.5*(min+max).
Definition: range1f.h:89
bool IsInside(const GfRange1f &range) const
Returns true if the range is located entirely inside the range.
Definition: range1f.h:137
float MinMaxType
Helper typedef.
Definition: range1f.h:49
const GfRange1f & UnionWith(const GfRange1f &b)
Extend this to include b.
Definition: range1f.h:157
void SetMax(float max)
Sets the maximum value of the range.
Definition: range1f.h:98
GfRange1f & operator*=(double m)
unary multiply.
Definition: range1f.h:232
void SetMin(float min)
Sets the minimum value of the range.
Definition: range1f.h:95
static GfRange1f Union(const GfRange1f &a, const GfRange1f &b)
Returns the smallest GfRange1f which contains both a and b.
Definition: range1f.h:172
float GetMax() const
Returns the maximum value of the range.
Definition: range1f.h:81
friend size_t hash_value(const GfRange1f &r)
hash.
Definition: range1f.h:280
bool Contains(float point) const
Returns true if the point is located inside the range.
Definition: range1f.h:115
bool IsEmpty() const
Returns whether the range is empty (max < min).
Definition: range1f.h:101
float GetMin() const
Returns the minimum value of the range.
Definition: range1f.h:78
GfRange1f & operator-=(const GfRange1f &b)
unary difference.
Definition: range1f.h:225
bool IsOutside(const GfRange1f &range) const
Returns true if the range is located entirely outside the range.
Definition: range1f.h:144
void SetEmpty()
Sets the range to an empty interval.
Definition: range1f.h:56
GF_API GfRange1f(class GfRange1d const &other)
Construct from GfRange1d.
bool operator==(const GfRange1f &b) const
The min and max points must match exactly for equality.
Definition: range1f.h:285
static GfRange1f GetIntersection(const GfRange1f &a, const GfRange1f &b)
Returns a GfRange1f that describes the intersection of a and b.
Definition: range1f.h:189
GfRange1f(float min, float max)
This constructor initializes the minimum and maximum points.
Definition: range1f.h:67
const GfRange1f & Union(float b)
Extend this to include b.
Definition: range1f.h:184
GfRange1f operator+(const GfRange1f &b) const
binary sum.
Definition: range1f.h:250
const GfRange1f & IntersectWith(const GfRange1f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range1f.h:204
const GfRange1f & UnionWith(float b)
Extend this to include b.
Definition: range1f.h:164
float GetSize() const
Returns the size of the range.
Definition: range1f.h:84
static GfRange1f GetUnion(const GfRange1f &a, const GfRange1f &b)
Returns the smallest GfRange1f which contains both a and b.
Definition: range1f.h:149
friend GfRange1f operator/(const GfRange1f &r, double m)
scalar divide.
Definition: range1f.h:275
static GfRange1f Intersection(const GfRange1f &a, const GfRange1f &b)
Returns a GfRange1f that describes the intersection of a and b.
Definition: range1f.h:198
void ExtendBy(float point)
Modifies the range if necessary to surround the given value.
Definition: range1f.h:107
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