Loading...
Searching...
No Matches
range1f.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_RANGE1F_H
29#define PXR_BASE_GF_RANGE1F_H
30
33
34#include "pxr/pxr.h"
35
36#include "pxr/base/gf/api.h"
37#include "pxr/base/gf/traits.h"
38#include "pxr/base/tf/hash.h"
39
40#include <cfloat>
41#include <cstddef>
42#include <iosfwd>
43
44PXR_NAMESPACE_OPEN_SCOPE
45
46class GfRange1d;
47class GfRange1f;
48
49template <>
50struct GfIsGfRange<class GfRange1f> { static const bool value = true; };
51
62{
63public:
64
66 typedef float MinMaxType;
67
68 static const size_t dimension = 1;
69 typedef MinMaxType ScalarType;
70
72 // TODO check whether this can be deprecated.
73 void inline SetEmpty() {
74 _min = FLT_MAX;
75 _max = -FLT_MAX;
76 }
77
80 SetEmpty();
81 }
82
84 GfRange1f(float min, float max)
85 : _min(min), _max(max)
86 {
87 }
88
89
91 GF_API
92 explicit GfRange1f(class GfRange1d const &other);
93
95 float GetMin() const { return _min; }
96
98 float GetMax() const { return _max; }
99
101 float GetSize() const { return _max - _min; }
102
106 float GetMidpoint() const {
107 return static_cast<ScalarType>(0.5) * _min
108 + static_cast<ScalarType>(0.5) * _max;
109 }
110
112 void SetMin(float min) { _min = min; }
113
115 void SetMax(float max) { _max = max; }
116
118 bool IsEmpty() const {
119 return _min > _max;
120 }
121
124 void ExtendBy(float point) { UnionWith(point); }
125
128 void ExtendBy(const GfRange1f &range) { UnionWith(range); }
129
132 bool Contains(float point) const {
133 return (point >= _min && point <= _max);
134 }
135
139 bool Contains(const GfRange1f &range) const {
140 return Contains(range._min) && Contains(range._max);
141 }
142
146 bool IsInside(float point) const {
147 return Contains(point);
148 }
149
154 bool IsInside(const GfRange1f &range) const {
155 return Contains(range);
156 }
157
161 bool IsOutside(const GfRange1f &range) const {
162 return (range._max < _min || range._min > _max);
163 }
164
166 static GfRange1f GetUnion(const GfRange1f &a, const GfRange1f &b) {
167 GfRange1f res = a;
168 _FindMin(res._min,b._min);
169 _FindMax(res._max,b._max);
170 return res;
171 }
172
174 const GfRange1f &UnionWith(const GfRange1f &b) {
175 _FindMin(_min,b._min);
176 _FindMax(_max,b._max);
177 return *this;
178 }
179
181 const GfRange1f &UnionWith(float b) {
182 _FindMin(_min,b);
183 _FindMax(_max,b);
184 return *this;
185 }
186
189 static GfRange1f Union(const GfRange1f &a, const GfRange1f &b) {
190 return GetUnion(a, b);
191 }
192
195 const GfRange1f &Union(const GfRange1f &b) {
196 return UnionWith(b);
197 }
198
201 const GfRange1f &Union(float b) {
202 return UnionWith(b);
203 }
204
206 static GfRange1f GetIntersection(const GfRange1f &a, const GfRange1f &b) {
207 GfRange1f res = a;
208 _FindMax(res._min,b._min);
209 _FindMin(res._max,b._max);
210 return res;
211 }
212
215 static GfRange1f Intersection(const GfRange1f &a, const GfRange1f &b) {
216 return GetIntersection(a, b);
217 }
218
222 _FindMax(_min,b._min);
223 _FindMin(_max,b._max);
224 return *this;
225 }
226
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
250 if (m > 0) {
251 _min *= m;
252 _max *= m;
253 } else {
254 float tmp = _min;
255 _min = _max * m;
256 _max = tmp * m;
257 }
258 return *this;
259 }
260
263 return *this *= (1.0 / m);
264 }
265
268 return GfRange1f(_min + b._min, _max + b._max);
269 }
270
271
274 return GfRange1f(_min - b._max, _max - b._min);
275 }
276
278 friend GfRange1f operator *(double m, const GfRange1f &r) {
279 return (m > 0 ?
280 GfRange1f(r._min*m, r._max*m) :
281 GfRange1f(r._max*m, r._min*m));
282 }
283
285 friend GfRange1f operator *(const GfRange1f &r, double m) {
286 return (m > 0 ?
287 GfRange1f(r._min*m, r._max*m) :
288 GfRange1f(r._max*m, r._min*m));
289 }
290
292 friend GfRange1f operator /(const GfRange1f &r, double m) {
293 return r * (1.0 / m);
294 }
295
297 friend inline size_t hash_value(const GfRange1f &r) {
298 return TfHash::Combine(r._min, r._max);
299 }
300
302 bool operator ==(const GfRange1f &b) const {
303 return (_min == b._min && _max == b._max);
304 }
305
306 bool operator !=(const GfRange1f &b) const {
307 return !(*this == b);
308 }
309
314 GF_API inline bool operator ==(const GfRange1d& other) const;
315 GF_API inline bool operator !=(const GfRange1d& other) const;
316
318 GF_API
319 double GetDistanceSquared(float p) const;
320
321
322 private:
324 float _min, _max;
325
327 static void _FindMin(float &dest, float point) {
328 if (point < dest) dest = point;
329 }
330
332 static void _FindMax(float &dest, float point) {
333 if (point > dest) dest = point;
334 }
335};
336
339GF_API std::ostream& operator<<(std::ostream &, GfRange1f const &);
340
341PXR_NAMESPACE_CLOSE_SCOPE
342#include "pxr/base/gf/range1d.h"
343PXR_NAMESPACE_OPEN_SCOPE
344
345inline bool
347 return _min == float(other.GetMin()) &&
348 _max == float(other.GetMax());
349}
350
351inline bool
352GfRange1f::operator !=(const GfRange1d& other) const {
353 return !(*this == other);
354}
355
356
357PXR_NAMESPACE_CLOSE_SCOPE
358
359#endif // PXR_BASE_GF_RANGE1F_H
Basic type: 1-dimensional floating point range.
Definition: range1d.h:62
double GetMax() const
Returns the maximum value of the range.
Definition: range1d.h:98
double GetMin() const
Returns the minimum value of the range.
Definition: range1d.h:95
Basic type: 1-dimensional floating point range.
Definition: range1f.h:62
friend GfRange1f operator*(double m, const GfRange1f &r)
scalar multiply.
Definition: range1f.h:278
GfRange1f operator-(const GfRange1f &b) const
binary difference.
Definition: range1f.h:273
const GfRange1f & Intersection(const GfRange1f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range1f.h:230
bool IsInside(float point) const
Returns true if the point is located inside the range.
Definition: range1f.h:146
void ExtendBy(const GfRange1f &range)
Modifies the range if necessary to surround the given range.
Definition: range1f.h:128
GfRange1f()
The default constructor creates an empty range.
Definition: range1f.h:79
GfRange1f & operator/=(double m)
unary division.
Definition: range1f.h:262
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:235
const GfRange1f & Union(const GfRange1f &b)
Extend this to include b.
Definition: range1f.h:195
bool Contains(const GfRange1f &range) const
Returns true if the range is located entirely inside the range.
Definition: range1f.h:139
float GetMidpoint() const
Returns the midpoint of the range, that is, 0.5*(min+max).
Definition: range1f.h:106
bool IsInside(const GfRange1f &range) const
Returns true if the range is located entirely inside the range.
Definition: range1f.h:154
float MinMaxType
Helper typedef.
Definition: range1f.h:66
const GfRange1f & UnionWith(const GfRange1f &b)
Extend this to include b.
Definition: range1f.h:174
void SetMax(float max)
Sets the maximum value of the range.
Definition: range1f.h:115
GfRange1f & operator*=(double m)
unary multiply.
Definition: range1f.h:249
void SetMin(float min)
Sets the minimum value of the range.
Definition: range1f.h:112
static GfRange1f Union(const GfRange1f &a, const GfRange1f &b)
Returns the smallest GfRange1f which contains both a and b.
Definition: range1f.h:189
float GetMax() const
Returns the maximum value of the range.
Definition: range1f.h:98
friend size_t hash_value(const GfRange1f &r)
hash.
Definition: range1f.h:297
bool Contains(float point) const
Returns true if the point is located inside the range.
Definition: range1f.h:132
bool IsEmpty() const
Returns whether the range is empty (max < min).
Definition: range1f.h:118
float GetMin() const
Returns the minimum value of the range.
Definition: range1f.h:95
GfRange1f & operator-=(const GfRange1f &b)
unary difference.
Definition: range1f.h:242
bool IsOutside(const GfRange1f &range) const
Returns true if the range is located entirely outside the range.
Definition: range1f.h:161
void SetEmpty()
Sets the range to an empty interval.
Definition: range1f.h:73
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:302
static GfRange1f GetIntersection(const GfRange1f &a, const GfRange1f &b)
Returns a GfRange1f that describes the intersection of a and b.
Definition: range1f.h:206
GfRange1f(float min, float max)
This constructor initializes the minimum and maximum points.
Definition: range1f.h:84
const GfRange1f & Union(float b)
Extend this to include b.
Definition: range1f.h:201
GfRange1f operator+(const GfRange1f &b) const
binary sum.
Definition: range1f.h:267
const GfRange1f & IntersectWith(const GfRange1f &b)
Modifies this range to hold its intersection with b and returns the result.
Definition: range1f.h:221
const GfRange1f & UnionWith(float b)
Extend this to include b.
Definition: range1f.h:181
float GetSize() const
Returns the size of the range.
Definition: range1f.h:101
static GfRange1f GetUnion(const GfRange1f &a, const GfRange1f &b)
Returns the smallest GfRange1f which contains both a and b.
Definition: range1f.h:166
friend GfRange1f operator/(const GfRange1f &r, double m)
scalar divide.
Definition: range1f.h:292
static GfRange1f Intersection(const GfRange1f &a, const GfRange1f &b)
Returns a GfRange1f that describes the intersection of a and b.
Definition: range1f.h:215
void ExtendBy(float point)
Modifies the range if necessary to surround the given value.
Definition: range1f.h:124
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