18 #ifndef ION_MATH_RANGEUTILS_H_
19 #define ION_MATH_RANGEUTILS_H_
36 template <
int Dimension,
typename T>
47 template <
int Dimension,
typename T>
55 for (
int i = 0; i < Dimension; ++i) {
59 if (result_min[i] > result_max[i])
68 template <
int Dimension,
typename T>
75 for (
int i = 0; i < Dimension; ++i) {
84 template <
int Dimension,
typename T>
95 for (
int i = 0; i < Dimension; ++i) {
96 if (
Abs(r0_min[i] - r1_min[i]) >
Abs(threshold) ||
97 Abs(r0_max[i] - r1_max[i]) >
Abs(threshold))
106 template <
int Dimension,
typename T>
111 if (!r.
IsEmpty() && scale_factor >
static_cast<T>(0)) {
112 const typename RangeType::Endpoint center = r.
GetCenter();
113 scaled.Set(center + scale_factor * (r.
GetMinPoint() - center),
114 center + scale_factor * (r.
GetMaxPoint() - center));
122 template <
int Dimension,
typename T>
128 const typename RangeType::Endpoint center = r.
GetCenter();
129 typename RangeType::Endpoint min_pt = r.
GetMinPoint();
130 typename RangeType::Endpoint max_pt = r.
GetMaxPoint();
131 for (
int i = 0; i < Dimension; ++i) {
132 if (scale_factors[i] <= static_cast<T>(0))
134 min_pt[i] = center[i] + scale_factors[i] * (min_pt[i] - center[i]);
135 max_pt[i] = center[i] + scale_factors[i] * (max_pt[i] - center[i]);
137 scaled.
Set(min_pt, max_pt);
148 template <
int Dimension,
typename T1,
typename T2>
154 typename RangeType::Endpoint min_pt = r.
GetMinPoint();
155 typename RangeType::Endpoint max_pt = r.
GetMaxPoint();
156 for (
int i = 0; i < Dimension; ++i) {
157 if (modulation[i] <= static_cast<T2>(0))
159 min_pt[i] =
static_cast<T1
>(
static_cast<T2
>(min_pt[i]) * modulation[i]);
160 max_pt[i] =
static_cast<T1
>(
static_cast<T2
>(max_pt[i]) * modulation[i]);
162 modulated.Set(min_pt, max_pt);
170 #endif // ION_MATH_RANGEUTILS_H_
const Endpoint & GetMinPoint() const
Returns the minimum or maximum endpoint.
const Size GetSize() const
Returns the size of the range, or the zero vector if the Range is empty.
The Range class defines an N-dimensional interval defined by minimum and maximum N-dimensional endpoi...
T NVolume(const Range< Dimension, T > &r)
Returns the NVolume of a Range, which is the product of its sizes in all dimensions.
const Endpoint GetCenter() const
Returns the point at the center of the range, or the origin if the range is empty.
const Range< Dimension, T > ScaleRange(const Range< Dimension, T > &r, T scale_factor)
Returns a Range that is the input Range scaled uniformly about its center by the given factor...
void Set(T e0)
Sets the vector values.
const Range< Dimension, T1 > ModulateRange(const Range< Dimension, T1 > &r, const Vector< Dimension, T2 > modulation)
Modulate a Range by a Vector.
const Range< Dimension, T > RangeUnion(const Range< Dimension, T > &r0, const Range< Dimension, T > &r1)
Returns the union of two Range instances.
bool IsEmpty() const
Returns true if the Range is empty, meaning that the minimum value is strictly greater than the maxim...
bool RangesAlmostEqual(const Range< Dimension, T > &r0, const Range< Dimension, T > &r1, const T threshold)
Returns true if all dimensions of the two ranges are equal within the threshold.
const Range< Dimension, T > RangeIntersection(const Range< Dimension, T > &r0, const Range< Dimension, T > &r1)
Returns the intersection of two Range instances.
const Endpoint & GetMaxPoint() const
void ExtendByRange(const Range &r)
Extends the Range if necessary to contain the given Range.
const T Abs(const T &val)
Returns the absolute value of a number in a type-safe way.
const Range< Dimension, T > ScaleRangeNonUniformly(const Range< Dimension, T > &r, const Vector< Dimension, T > scale_factors)
Returns a Range that is the input Range scaled nonuniformly about its center by the given per-dimensi...