16 #ifndef SURGSIM_MATH_INTERVALARITHMETIC_INL_H 17 #define SURGSIM_MATH_INTERVALARITHMETIC_INL_H 32 SURGSIM_ASSERT(min <= max) <<
"Incorrect order of interval bounds";
65 minMax(a1, a2, &min, &max);
73 minMax(a1, a2, a3, &min, &max);
81 minMax(a1, a2, a3, a4, &min, &max);
94 return (m_min <= val && m_max >= val);
269 return (*
this) = (*this) * i.
inverse();
277 T minSquare, maxSquare;
278 minMax(lowerBoundSquared, upperBoundSquared, &minSquare, &maxSquare);
279 return Interval<T>((m_min < 0 && m_max > 0) ? 0 : minSquare, maxSquare);
307 template <
class T,
int N>
310 for (
int i = 0; i < N; i++)
316 template <
class T,
int N>
319 for (
int i = 0; i < N; i++)
321 m_interval[i] = x[i];
325 template <
class T,
int N>
328 for (
int i = 0; i < N; i++)
334 template <
class T,
int N>
337 for (
int j = 0; j < N; j++)
339 m_interval[j] = i.m_interval[j];
343 template <
class T,
int N>
346 for (
int i = 0; i < N; ++i)
352 template <
class T,
int N>
355 for (
int i = 0; i < N; i++)
362 template <
class T,
int N>
367 for (
int j = 0; j < N; j++)
369 m_interval[j] = i.m_interval[j];
376 template <
class T,
int N>
380 for (
int i = 0; i < N; ++i)
390 template <
class T,
int N>
393 for (
int i = 0; i < N; i++)
403 template <
class T,
int N>
406 for (
int i = 0; i < N; i++)
416 template <
class T,
int N>
422 template <
class T,
int N>
425 for (
int i = 0; i < N; i++)
427 m_interval[i].addThickness(thickness);
432 template <
class T,
int N>
436 for (
int i = 0; i < N; i++)
443 template <
class T,
int N>
446 for (
int i = 0; i < N; i++)
453 template <
class T,
int N>
457 for (
int i = 0; i < N; i++)
464 template <
class T,
int N>
467 for (
int i = 0; i < N; i++)
474 template <
class T,
int N>
478 for (
int i = 0; i < N; i++)
485 template <
class T,
int N>
488 for (
int i = 0; i < N; i++)
495 template <
class T,
int N>
499 for (
int i = 0; i < N; i++)
506 template <
class T,
int N>
510 for (
int i = 0; i < N; i++)
517 template <
class T,
int N>
520 for (
int i = 0; i < N; i++)
527 template <
class T,
int N>
530 Interval<T> ret(static_cast<T>(0), static_cast<T>(0));
531 for (
int i = 0; i < N; i++)
533 ret += m_interval[i] * interval.
m_interval[i];
538 template <
class T,
int N>
542 for (
int i = 1; i < N; ++i)
544 result += m_interval[i].
square();
549 template <
class T,
int N>
557 template <
class T,
int N>
560 return m_interval[i];
574 m_interval[0] = x[0];
575 m_interval[1] = x[1];
576 m_interval[2] = x[2];
598 m_interval[0] = i.m_interval[0];
599 m_interval[1] = i.m_interval[1];
600 m_interval[2] = i.m_interval[2];
623 m_interval[0] = i.m_interval[0];
624 m_interval[1] = i.m_interval[1];
625 m_interval[2] = i.m_interval[2];
634 && m_interval[2].overlapsWith(interval.
m_interval[2]));
641 m_interval[2].isApprox(i.
m_interval[2], epsilon));
659 m_interval[0].addThickness(thickness);
660 m_interval[1].addThickness(thickness);
661 m_interval[2].addThickness(thickness);
716 return IntervalND<T, 3>(m_interval[0].inverse(), m_interval[1].inverse(), m_interval[2].inverse());
752 return m_interval[0].square() + m_interval[1].square() + m_interval[2].square();
766 return m_interval[i];
770 template <
typename T>
776 template <
typename T>
838 template <
typename T>
839 std::ostream& operator<< (std::ostream& o, const Interval<T>& interval)
841 o <<
"[" << interval.getMin() <<
"," << interval.getMax() <<
"]";
846 template <
typename T,
int N>
847 std::ostream& operator<< (std::ostream& o, const IntervalND<T, N>& interval)
849 o <<
"(" << interval.getAxis(0);
850 for (
int i = 1; i < N; ++i)
852 o <<
";" << interval.getAxis(i);
899 #endif // SURGSIM_MATH_INTERVALARITHMETIC_INL_H Interval< T > & operator=(const Interval< T > &i)
Assignment operator.
Definition: IntervalArithmetic-inl.h:46
IntervalND< T, N > & operator/=(const IntervalND< T, N > &interval)
Definition: IntervalArithmetic-inl.h:518
void IntervalArithmetic_dotProduct(const IntervalND< T, 3 > &a, const IntervalND< T, 3 > &b, Interval< T > *res)
Definition: IntervalArithmetic-inl.h:889
Definition: CompoundShapeToGraphics.cpp:29
Interval< T > & operator-=(const Interval< T > &i)
Definition: IntervalArithmetic-inl.h:204
T getMin() const
Definition: IntervalArithmetic-inl.h:283
bool isApprox(const Interval< T > &i, const T &epsilon) const
Definition: IntervalArithmetic-inl.h:104
IntervalND< T, N > operator/(const IntervalND< T, N > &interval) const
Definition: IntervalArithmetic-inl.h:507
IntervalND<T,3> defines the concept of a group of mathematical intervals specialized to 3 intervals a...
Definition: IntervalArithmetic.h:307
bool isApprox(const IntervalND< T, N > &interval, const T &epsilon) const
Definition: IntervalArithmetic-inl.h:391
Interval< T > upperHalf() const
Definition: IntervalArithmetic-inl.h:301
#define SURGSIM_ASSERT(condition)
Assert that condition is true.
Definition: Assert.h:77
bool operator!=(const IntervalND< T, N > &interval) const
Definition: IntervalArithmetic-inl.h:417
T getMax() const
Definition: IntervalArithmetic-inl.h:289
Interval< T > operator*(const Interval< T > &i) const
Definition: IntervalArithmetic-inl.h:220
Interval< T > & operator+=(const Interval< T > &i)
Definition: IntervalArithmetic-inl.h:170
friend void IntervalArithmetic_addsub(const Interval< P > &a, const Interval< P > &b, Interval< P > *res)
Add the difference of two intervals to an existing value.
IntervalND< T, N > operator*(const IntervalND< T, N > &interval) const
Definition: IntervalArithmetic-inl.h:475
Interval< T > inverse() const
Definition: IntervalArithmetic-inl.h:253
IntervalND()
Constructor.
Definition: IntervalArithmetic-inl.h:308
IntervalND defines the concept of a group of mathematical intervals and provides operations on them i...
Definition: IntervalArithmetic.h:199
Interval< T > dotProduct(const IntervalND< T, N > &interval) const
Definition: IntervalArithmetic-inl.h:528
Interval< T > & addThickness(const T &thickness)
Widens the current interval by thickness on both sides.
Definition: IntervalArithmetic-inl.h:122
Interval< T > magnitudeSquared() const
Definition: IntervalArithmetic-inl.h:539
void minMax(const T &a1, const T &a2, T *minVal, T *maxVal)
Calculate the minimum and maximum of two values.
Definition: MinMax-inl.h:27
friend void IntervalArithmetic_addmul(const Interval< P > &a, const Interval< P > &b, Interval< P > *res)
Add the product of two intervals to an existing value.
friend void IntervalArithmetic_sub(const Interval< P > &a, const Interval< P > &b, Interval< P > *res)
Calculate the difference of two intervals.
IntervalND< T, N > & operator-=(const IntervalND< T, N > &interval)
Definition: IntervalArithmetic-inl.h:465
std::array< Interval< T >, N > m_interval
The N dimensional group of intervals.
Definition: IntervalArithmetic.h:297
void IntervalArithmetic_crossProduct(const IntervalND< T, 3 > &a, const IntervalND< T, 3 > &b, IntervalND< T, 3 > *res)
Definition: IntervalArithmetic-inl.h:876
Interval< T > & operator*=(const Interval< T > &i)
Definition: IntervalArithmetic-inl.h:239
friend void IntervalArithmetic_add(const Interval< P > &a, const Interval< P > &b, Interval< P > *res)
Calculate the sum of two intervals.
IntervalND< T, N > & operator=(const IntervalND< T, N > &interval)
Assignment operator.
Definition: IntervalArithmetic-inl.h:353
Interval< T > & operator/=(const Interval< T > &i)
Definition: IntervalArithmetic-inl.h:267
bool overlapsWith(const IntervalND< T, N > &interval) const
Definition: IntervalArithmetic-inl.h:377
Interval< T > operator-() const
Definition: IntervalArithmetic-inl.h:186
IntervalND< T, N > & operator+=(const IntervalND< T, N > &interval)
Definition: IntervalArithmetic-inl.h:444
T m_max
Definition: IntervalArithmetic.h:187
IntervalND< T, N > operator-(const IntervalND< T, N > &interval) const
Definition: IntervalArithmetic-inl.h:454
T m_min
The lower (m_min) and upper (m_max) limits of the interval.
Definition: IntervalArithmetic.h:187
bool operator==(const IntervalND< T, N > &interval) const
Definition: IntervalArithmetic-inl.h:404
bool operator!=(const Interval< T > &i) const
Definition: IntervalArithmetic-inl.h:116
friend void IntervalArithmetic_submul(const Interval< P > &a, const Interval< P > &b, Interval< P > *res)
Subtract the product of two intervals from an existing value.
std::array< Interval< T >, 3 > m_interval
The 3 dimensional group of intervals.
Definition: IntervalArithmetic.h:424
friend void IntervalArithmetic_mul(const Interval< P > &a, const Interval< P > &b, Interval< P > *res)
Calculate the product of two intervals.
Interval< T > operator+(const Interval< T > &i) const
Definition: IntervalArithmetic-inl.h:158
const Interval< T > & getAxis(size_t i) const
Definition: IntervalArithmetic-inl.h:558
Interval< T > & extendToInclude(const T &x)
Widens the current interval on one end to include x.
Definition: IntervalArithmetic-inl.h:130
bool operator==(const Interval< T > &i) const
Definition: IntervalArithmetic-inl.h:110
bool overlapsWith(const Interval< T > &i) const
Definition: IntervalArithmetic-inl.h:86
Interval defines the concept of a mathematical interval and provides operations on it including arith...
Definition: IntervalArithmetic.h:34
IntervalND< T, N > inverse() const
Definition: IntervalArithmetic-inl.h:496
Interval< T > magnitude() const
Definition: IntervalArithmetic-inl.h:550
friend void IntervalArithmetic_addadd(const Interval< P > &a, const Interval< P > &b, Interval< P > *res)
Calculate the sum of three intervals res + a + b.
Interval()
Constructor.
Definition: IntervalArithmetic-inl.h:27
bool contains(const T &val) const
Definition: IntervalArithmetic-inl.h:92
Interval< T > operator/(const Interval< T > &i) const
Definition: IntervalArithmetic-inl.h:261
IntervalND< T, N > operator+(const IntervalND< T, N > &interval) const
Definition: IntervalArithmetic-inl.h:433
IntervalND< T, N > & addThickness(const T &thickness)
Widens every interval in the current interval group by thickness on both sides.
Definition: IntervalArithmetic-inl.h:423
Interval< T > square() const
Definition: IntervalArithmetic-inl.h:273
bool containsZero() const
Definition: IntervalArithmetic-inl.h:98
static Interval< T > minToMax(const T &a1, const T &a2)
Generate an interval from min to max based on the inputs.
Definition: IntervalArithmetic-inl.h:62
IntervalND< T, N > & operator*=(const IntervalND< T, N > &interval)
Definition: IntervalArithmetic-inl.h:486
Interval< T > lowerHalf() const
Definition: IntervalArithmetic-inl.h:295