7#ifndef PXR_BASE_GF_INTERVAL_H
8#define PXR_BASE_GF_INTERVAL_H
15#include "pxr/base/gf/api.h"
22PXR_NAMESPACE_OPEN_SCOPE
52 bool minClosed=
true,
bool maxClosed=
true) :
61 return _min == rhs._min && _max == rhs._max;
66 return !(*
this == rhs);
73 return _min < rhs._min;
77 return _max < rhs._max;
85 size_t Hash()
const {
return hash_value(*
this); }
87 friend inline size_t hash_value(
GfInterval const &i) {
92 double GetMin()
const {
return _min.value; }
95 double GetMax()
const {
return _max.value; }
99 _min = _Bound(v, _min.closed);
104 _min = _Bound(v, minClosed);
109 _max = _Bound(v, _max.closed);
114 _max = _Bound(v, maxClosed);
131 return (_max.value != -std::numeric_limits<double>::infinity()
132 && _max.value != std::numeric_limits<double>::infinity());
137 return (_min.value != -std::numeric_limits<double>::infinity()
138 && _min.value != std::numeric_limits<double>::infinity());
148 return (_min.value > _max.value) ||
149 ((_min.value == _max.value)
150 && (! _min.closed || !_max.closed));
156 return GfMax( 0.0, _max.value - _min.value );
160 double Size()
const {
return GetSize(); }
165 return ((d > _min.value) || (d == _min.value && _min.closed))
166 && ((d < _max.value) || (d == _max.value && _max.closed));
170 bool In(
double d)
const {
return Contains(d); }
176 return (*
this & i) == i;
196 if (_min.value < rhs._min.value)
198 else if (_min.value == rhs._min.value)
199 _min.closed &= rhs._min.closed;
202 if (_max.value > rhs._max.value)
204 else if (_max.value == rhs._max.value)
205 _max.closed &= rhs._max.closed;
218 if (_min.value > rhs._min.value)
220 else if (_min.value == rhs._min.value)
221 _min.closed |= rhs._min.closed;
224 if (_max.value < rhs._max.value)
226 else if (_max.value == rhs._max.value)
227 _max.closed |= rhs._max.closed;
235 _min.value += rhs._min.value;
236 _max.value += rhs._max.value;
237 _min.closed &= rhs._min.closed;
238 _max.closed &= rhs._max.closed;
245 return *
this += -rhs;
250 return GfInterval(-_max.value, -_min.value, _max.closed, _min.closed);
255 const _Bound a = _min * rhs._min;
256 const _Bound b = _min * rhs._max;
257 const _Bound c = _max * rhs._min;
258 const _Bound d = _max * rhs._max;
259 _max = _Max( _Max(a,b), _Max(c,d) );
260 _min = _Min( _Min(a,b), _Min(c,d) );
273 return !(rhs < *
this);
279 return !(*
this < rhs);
326 return GfInterval( -std::numeric_limits<double>::infinity(),
327 std::numeric_limits<double>::infinity(),
340 _Bound(
double val,
bool isClosed) :
346 if (value == -std::numeric_limits<double>::infinity() ||
347 value == std::numeric_limits<double>::infinity()) {
352 bool operator==(
const _Bound &rhs)
const {
353 return value == rhs.value && closed == rhs.closed;
356 bool operator!=(
const _Bound &rhs)
const {
357 return !(*
this == rhs);
360 bool operator<(
const _Bound &rhs)
const {
361 return value < rhs.value || (value == rhs.value && closed && !rhs.closed);
364 _Bound & operator=(
const _Bound &rhs) {
369 _Bound operator*(
const _Bound &rhs)
const {
370 return _Bound( value * rhs.value, closed & rhs.closed );
372 friend inline size_t hash_value(
const _Bound &b) {
378 inline static const _Bound &
379 _Min(
const _Bound &a,
const _Bound &b ) {
380 return (a.value < b.value
381 || ((a.value == b.value) && a.closed && !b.closed)) ?
386 inline static const _Bound &
387 _Max(
const _Bound &a,
const _Bound &b ) {
388 return (a.value < b.value
389 || ((a.value == b.value) && !a.closed && b.closed)) ?
401PXR_NAMESPACE_CLOSE_SCOPE
A basic mathematical interval class.
GfInterval()
Construct an empty open interval, (0,0).
bool operator>=(const GfInterval &rhs)
Greater than or equal operator.
GfInterval(double val)
Construct a closed interval representing the single point, as [val,val].
bool operator<=(const GfInterval &rhs)
Less than or equal operator.
double GetMax() const
Maximum value.
GfInterval & operator+=(const GfInterval &rhs)
Interval addition.
static GfInterval GetFullInterval()
Returns the full interval (-inf, inf).
GfInterval operator|(const GfInterval &rhs) const
Union operator.
bool operator>(const GfInterval &rhs)
Greater than operator.
bool IsFinite() const
Returns true if both the maximum and minimum value are finite.
GfInterval operator-(const GfInterval &rhs) const
Subtraction operator.
bool operator<(const GfInterval &rhs) const
Less-than operator.
GfInterval & operator*=(const GfInterval &rhs)
Interval multiplication.
double GetMin() const
Minimum value.
GfInterval & operator-=(const GfInterval &rhs)
Interval subtraction.
bool IsMaxFinite() const
Returns true if the maximum value is finite.
double GetSize() const
Width of the interval.
void SetMin(double v, bool minClosed)
Set minimum value and boundary condition.
GfInterval operator-() const
Interval unary minus.
bool IsEmpty() const
Return true iff the interval is empty.
void SetMax(double v, bool maxClosed)
Set maximum value and boundary condition.
bool IsMinClosed() const
Minimum boundary condition.
bool IsMaxOpen() const
Maximum boundary condition.
bool operator!=(const GfInterval &rhs) const
Inequality operator.
bool operator==(const GfInterval &rhs) const
Equality operator.
bool IsMinFinite() const
Returns true if the minimum value is finite.
void SetMin(double v)
Set minimum value.
GfInterval operator&(const GfInterval &rhs) const
Intersection operator.
GfInterval(double min, double max, bool minClosed=true, bool maxClosed=true)
Construct an interval with the given arguments.
size_t Hash() const
Hash value.
GfInterval operator*(const GfInterval &rhs) const
Multiplication operator.
GfInterval & operator|=(const GfInterval &rhs)
Returns the interval that bounds the union of this interval and rhs.
GfInterval operator+(const GfInterval &rhs) const
Addition operator.
bool Contains(const GfInterval &i) const
Return true iff the interval i is entirely contained in the interval.
void SetMax(double v)
Set maximum value.
bool Intersects(const GfInterval &i) const
Return true iff the given interval i intersects this interval.
bool Contains(double d) const
Return true iff the value d is contained in the interval.
bool IsMinOpen() const
Minimum boundary condition.
bool IsMaxClosed() const
Maximum boundary condition.
GfInterval & operator&=(const GfInterval &rhs)
Boolean intersection.
static size_t Combine(Args &&... args)
Produce a hash code by combining the hash codes of several objects.
Assorted mathematical utility functions.
T GfMax(T a1, T a2)
Returns the largest of the given values.
GF_API std::ostream & operator<<(std::ostream &, const GfBBox3d &)
Output a GfBBox3d using the format [(range) matrix zeroArea].
size_t hash_value(const half h)
Overload hash_value for half.