28 #ifndef PXR_BASE_GF_RANGE2F_H 29 #define PXR_BASE_GF_RANGE2F_H 36 #include "pxr/base/gf/api.h" 39 #include "pxr/base/gf/traits.h" 41 #include <boost/functional/hash.hpp> 47 PXR_NAMESPACE_OPEN_SCOPE
71 static const size_t dimension = GfVec2f::dimension;
77 _min[0] = _min[1] = FLT_MAX;
78 _max[0] = _max[1] = -FLT_MAX;
88 : _min(min), _max(max)
105 return static_cast<ScalarType>(0.5) * _min
106 + static_cast<ScalarType>(0.5) * _max;
117 return _min[0] > _max[0] || _min[1] > _max[1];
131 return (point[0] >= _min[0] && point[0] <= _max[0]
132 && point[1] >= _min[1] && point[1] <= _max[1]);
161 return ((range._max[0] < _min[0] || range._min[0] > _max[0])
162 || (range._max[1] < _min[1] || range._min[1] > _max[1]));
168 _FindMin(res._min,b._min);
169 _FindMax(res._max,b._max);
175 _FindMin(_min,b._min);
176 _FindMax(_max,b._max);
208 _FindMax(res._min,b._min);
209 _FindMin(res._max,b._max);
222 _FindMax(_min,b._min);
223 _FindMin(_max,b._max);
263 return *
this *= (1.0 / m);
268 return GfRange2f(_min + b._min, _max + b._max);
274 return GfRange2f(_min - b._max, _max - b._min);
293 return r * (1.0 / m);
299 boost::hash_combine(h, r._min);
300 boost::hash_combine(h, r._max);
306 return (_min == b._min && _max == b._max);
309 bool operator !=(
const GfRange2f &b)
const {
310 return !(*
this == b);
318 GF_API
inline bool operator !=(
const GfRange2d& other)
const;
344 if (point[0] < dest[0]) dest[0] = point[0];
345 if (point[1] < dest[1]) dest[1] = point[1];
350 if (point[0] > dest[0]) dest[0] = point[0];
351 if (point[1] > dest[1]) dest[1] = point[1];
359 PXR_NAMESPACE_CLOSE_SCOPE
361 PXR_NAMESPACE_OPEN_SCOPE
370 GfRange2f::operator !=(
const GfRange2d& other)
const {
371 return !(*
this == other);
375 PXR_NAMESPACE_CLOSE_SCOPE
377 #endif // PXR_BASE_GF_RANGE2F_H void SetMax(const GfVec2f &max)
Sets the maximum value of the range.
bool IsEmpty() const
Returns whether the range is empty (max < min).
bool IsInside(const GfRange2f &range) const
Returns true if the range is located entirely inside the range.
GF_API GfRange2f GetQuadrant(size_t i) const
Returns the ith quadrant of the range, in the following order: SW, SE, NW, NE.
void SetEmpty()
Sets the range to an empty interval.
bool operator==(const GfRange2f &b) const
The min and max points must match exactly for equality.
GfRange2f operator+(const GfRange2f &b) const
binary sum.
friend GfRange2f operator *(const GfRange2f &r, double m)
scalar multiply.
const GfRange2f & UnionWith(const GfRange2f &b)
Extend this to include b.
const GfVec2d & GetMax() const
Returns the maximum value of the range.
bool Contains(const GfVec2f &point) const
Returns true if the point is located inside the range.
GfRange2f operator -(const GfRange2f &b) const
binary difference.
A metafunction with a static const bool member 'value' that is true for GfRange types and false for a...
GfRange2f & operator+=(const GfRange2f &b)
unary sum.
friend GfRange2f operator *(double m, const GfRange2f &r)
scalar multiply.
GF_API std::ostream & operator<<(std::ostream &, GfRange2f const &)
Output a GfRange2f.
const GfRange2f & Union(const GfVec2f &b)
Extend this to include b.
static GfRange2f Union(const GfRange2f &a, const GfRange2f &b)
Returns the smallest GfRange2f which contains both a and b.
float ScalarType
Scalar element type and dimension.
static GfRange2f GetUnion(const GfRange2f &a, const GfRange2f &b)
Returns the smallest GfRange2f which contains both a and b.
GfVec2f GetMidpoint() const
Returns the midpoint of the range, that is, 0.5*(min+max).
GfRange2f & operator -=(const GfRange2f &b)
unary difference.
bool IsInside(const GfVec2f &point) const
Returns true if the point is located inside the range.
GfRange2f()
The default constructor creates an empty range.
const GfVec2f & GetMin() const
Returns the minimum value of the range.
friend size_t hash_value(const GfRange2f &r)
hash.
static GfRange2f Intersection(const GfRange2f &a, const GfRange2f &b)
Returns a GfRange2f that describes the intersection of a and b.
Basic type: 2-dimensional floating point range.
const GfVec2d & GetMin() const
Returns the minimum value of the range.
GF_API GfVec2f GetCorner(size_t i) const
Returns the ith corner of the range, in the following order: SW, SE, NW, NE.
const GfRange2f & Union(const GfRange2f &b)
Extend this to include b.
GfRange2f(const GfVec2f &min, const GfVec2f &max)
This constructor initializes the minimum and maximum points.
GF_API double GetDistanceSquared(const GfVec2f &p) const
Compute the squared distance from a point to the range.
const GfRange2f & IntersectWith(const GfRange2f &b)
Modifies this range to hold its intersection with b and returns the result.
const GfRange2f & Intersection(const GfRange2f &b)
Modifies this range to hold its intersection with b and returns the result.
const GfRange2f & UnionWith(const GfVec2f &b)
Extend this to include b.
Basic type for a vector of 2 float components.
GfRange2f & operator *=(double m)
unary multiply.
void SetMin(const GfVec2f &min)
Sets the minimum value of the range.
bool IsOutside(const GfRange2f &range) const
Returns true if the range is located entirely outside the range.
static GF_API const GfRange2f UnitSquare
The unit square.
GfVec2f MinMaxType
Helper typedef.
bool Contains(const GfRange2f &range) const
Returns true if the range is located entirely inside the range.
const GfVec2f & GetMax() const
Returns the maximum value of the range.
static GfRange2f GetIntersection(const GfRange2f &a, const GfRange2f &b)
Returns a GfRange2f that describes the intersection of a and b.
friend GfRange2f operator/(const GfRange2f &r, double m)
scalar divide.
void ExtendBy(const GfVec2f &point)
Modifies the range if necessary to surround the given value.
void ExtendBy(const GfRange2f &range)
Modifies the range if necessary to surround the given range.
Basic type: 2-dimensional floating point range.
GfRange2f & operator/=(double m)
unary division.
GfVec2f GetSize() const
Returns the size of the range.