24 #ifndef PXR_BASE_GF_INTERVAL_H
25 #define PXR_BASE_GF_INTERVAL_H
32 #include "pxr/base/gf/api.h"
34 #include <boost/functional/hash.hpp>
40 PXR_NAMESPACE_OPEN_SCOPE
70 bool minClosed=
true,
bool maxClosed=
true) :
79 return _min == rhs._min && _max == rhs._max;
84 return !(*
this == rhs);
91 return _min < rhs._min;
95 return _max < rhs._max;
103 size_t Hash()
const {
return hash_value(*
this); }
105 friend inline size_t hash_value(
GfInterval const &i) {
107 boost::hash_combine(h, i._min);
108 boost::hash_combine(h, i._max);
113 double GetMin()
const {
return _min.value; }
116 double GetMax()
const {
return _max.value; }
120 _min = _Bound(v, _min.closed);
125 _min = _Bound(v, minClosed);
130 _max = _Bound(v, _max.closed);
135 _max = _Bound(v, maxClosed);
152 return (_max.value != -std::numeric_limits<double>::infinity()
153 && _max.value != std::numeric_limits<double>::infinity());
158 return (_min.value != -std::numeric_limits<double>::infinity()
159 && _min.value != std::numeric_limits<double>::infinity());
169 return (_min.value > _max.value) ||
170 ((_min.value == _max.value)
171 && (! _min.closed || !_max.closed));
177 return GfMax( 0.0, _max.value - _min.value );
181 double Size()
const {
return GetSize(); }
186 return ((d > _min.value) || (d == _min.value && _min.closed))
187 && ((d < _max.value) || (d == _max.value && _max.closed));
191 bool In(
double d)
const {
return Contains(d); }
197 return (*
this & i) == i;
217 if (_min.value < rhs._min.value)
219 else if (_min.value == rhs._min.value)
220 _min.closed &= rhs._min.closed;
223 if (_max.value > rhs._max.value)
225 else if (_max.value == rhs._max.value)
226 _max.closed &= rhs._max.closed;
239 if (_min.value > rhs._min.value)
241 else if (_min.value == rhs._min.value)
242 _min.closed |= rhs._min.closed;
245 if (_max.value < rhs._max.value)
247 else if (_max.value == rhs._max.value)
248 _max.closed |= rhs._max.closed;
256 _min.value += rhs._min.value;
257 _max.value += rhs._max.value;
258 _min.closed &= rhs._min.closed;
259 _max.closed &= rhs._max.closed;
266 return *
this += -rhs;
271 return GfInterval(-_max.value, -_min.value, _max.closed, _min.closed);
276 const _Bound a = _min * rhs._min;
277 const _Bound b = _min * rhs._max;
278 const _Bound c = _max * rhs._min;
279 const _Bound d = _max * rhs._max;
280 _max = _Max( _Max(a,b), _Max(c,d) );
281 _min = _Min( _Min(a,b), _Min(c,d) );
294 return !(rhs < *
this);
300 return !(*
this < rhs);
347 return GfInterval( -std::numeric_limits<double>::infinity(),
348 std::numeric_limits<double>::infinity(),
361 _Bound(
double val,
bool isClosed) :
367 if (value == -std::numeric_limits<double>::infinity() ||
368 value == std::numeric_limits<double>::infinity()) {
374 return value == rhs.value && closed == rhs.closed;
378 return !(*
this == rhs);
381 bool operator<(
const _Bound &rhs)
const {
382 return value < rhs.value || (value == rhs.value && closed && !rhs.closed);
385 _Bound & operator=(
const _Bound &rhs) {
390 _Bound
operator*(
const _Bound &rhs)
const {
391 return _Bound( value * rhs.value, closed & rhs.closed );
393 friend inline size_t hash_value(
const _Bound &b) {
395 boost::hash_combine(h, b.value);
396 boost::hash_combine(h, b.closed);
402 inline static const _Bound &
403 _Min(
const _Bound &a,
const _Bound &b ) {
404 return (a.value < b.value
405 || ((a.value == b.value) && a.closed && !b.closed)) ?
410 inline static const _Bound &
411 _Max(
const _Bound &a,
const _Bound &b ) {
412 return (a.value < b.value
413 || ((a.value == b.value) && !a.closed && b.closed)) ?
425 PXR_NAMESPACE_CLOSE_SCOPE
427 #endif // PXR_BASE_GF_INTERVAL_H
GfInterval operator*(const GfInterval &rhs) const
Multiplication operator.
GfInterval & operator*=(const GfInterval &rhs)
Interval multiplication.
GfInterval()
Construct an empty open interval, (0,0).
bool operator<(const GfInterval &rhs) const
Less-than operator.
Assorted mathematical utility functions.
GfInterval & operator+=(const GfInterval &rhs)
Interval addition.
GfInterval(double val)
Construct a closed interval representing the single point, as [val,val].
bool IsMaxOpen() const
Maximum boundary condition.
GfInterval operator-(const GfInterval &rhs) const
Subtraction operator.
bool Contains(double d) const
Return true iff the value d is contained in the interval.
void SetMin(double v)
Set minimum value.
GfInterval operator-() const
Interval unary minus.
void SetMin(double v, bool minClosed)
Set minimum value and boundary condition.
bool Contains(const GfInterval &i) const
Return true iff the interval i is entirely contained in the interval.
bool IsFinite() const
Returns true if both the maximum and minimum value are finite.
bool Intersects(const GfInterval &i) const
Return true iff the given interval i intersects this interval.
bool operator>(const GfInterval &rhs)
Greater than operator.
double GetMin() const
Minimum value.
void SetMax(double v, bool maxClosed)
Set maximum value and boundary condition.
T GfMax(T a1, T a2)
Returns the largest of the given values.
A basic mathematical interval class.
bool IsMinFinite() const
Returns true if the minimum value is finite.
GfInterval & operator&=(const GfInterval &rhs)
Boolean intersection.
static GfInterval GetFullInterval()
Returns the full interval (-inf, inf).
bool IsEmpty() const
Return true iff the interval is empty.
GfInterval(double min, double max, bool minClosed=true, bool maxClosed=true)
Construct an interval with the given arguments.
bool IsMinClosed() const
Minimum boundary condition.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
GfInterval operator|(const GfInterval &rhs) const
Union operator.
bool IsMaxFinite() const
Returns true if the maximum value is finite.
bool operator<=(const GfInterval &rhs)
Less than or equal operator.
GfInterval & operator|=(const GfInterval &rhs)
Returns the interval that bounds the union of this interval and rhs.
GfInterval operator&(const GfInterval &rhs) const
Intersection operator.
bool IsMaxClosed() const
Maximum boundary condition.
size_t Hash() const
Hash value.
void SetMax(double v)
Set maximum value.
GfInterval & operator-=(const GfInterval &rhs)
Interval subtraction.
double GetMax() const
Maximum value.
bool IsMinOpen() const
Minimum boundary condition.
bool operator!=(const GfInterval &rhs) const
Inequality operator.
GfInterval operator+(const GfInterval &rhs) const
Addition operator.
bool operator==(const GfInterval &rhs) const
Equality operator.
double GetSize() const
Width of the interval.
bool operator>=(const GfInterval &rhs)
Greater than or equal operator.