40 template<
typename Valtype>
53 explicit constexpr
Interval( Valtype val ) noexcept;
54 constexpr
Interval( Valtype nearval, Valtype farval ) noexcept;
55 explicit constexpr
Interval( const
std::pair<Valtype,Valtype>& pair ) noexcept;
56 template<typename Valtype2>
66 Interval& Init( Valtype nearval, Valtype length ) noexcept;
71 constexpr auto
Sign() const noexcept ->decltype(Valtype{}/Valtype{});
75 constexpr bool Normal() const noexcept;
87 constexpr Valtype
Near() const noexcept;
91 constexpr Valtype
Far() const noexcept;
103 constexpr Valtype
Max() const noexcept;
107 constexpr Valtype
Min() const noexcept;
111 constexpr Valtype
Length() const noexcept;
120 constexpr Valtype
Center() const noexcept;
147 constexpr
bool Includes( Valtype val ) const noexcept;
156 constexpr
bool Touches( Valtype val, Valtype epsilon = Valtype{0} )
const noexcept;
161 Valtype
Clip( Valtype& val )
const noexcept;
163 constexpr const Valtype&
Clip(
const Valtype& val )
const noexcept;
168 Valtype
Wrap( Valtype& val )
const noexcept;
204 constexpr bool Equals(
const Interval& interval, Valtype epsilon = std::numeric_limits<Valtype>::epsilon() ) const noexcept;
216 template<typename Valtype>
217 void operator+=(
Interval<Valtype>& i1, const
Interval<Valtype>& i2 ) noexcept;
218 template<typename Valtype> constexpr
220 template<typename Valtype> constexpr
221 Interval<Valtype> operator+( const
Interval<Valtype>& i1, Valtype l ) noexcept;
222 template<typename Valtype> constexpr
223 Interval<Valtype> operator+( Valtype l, const
Interval<Valtype>& i1 ) noexcept;
224 template<typename Valtype> constexpr
226 template<typename Valtype> constexpr
227 Interval<Valtype> operator-( const
Interval<Valtype>& i1, Valtype l ) noexcept;
228 template<typename Valtype> constexpr
229 Interval<Valtype> operator-( Valtype l, const
Interval<Valtype>& i1 ) noexcept;
230 template<typename Valtype> constexpr
233 template<typename Valtype, typename Valtype2> constexpr
234 auto operator*( const
Interval<Valtype>& i1, Valtype2 scalar ) noexcept ->
Interval<decltype(Valtype{}*Valtype2{})>;
236 template<
typename Valtype,
typename Valtype2>
constexpr
239 template<
typename Valtype,
typename Valtype2>
constexpr
242 template<
typename Valtype,
typename Valtype2>
constexpr
245 template<
typename Valtype,
typename Valtype2>
constexpr
250 template<
typename Valtype>
constexpr
253 template<
typename Valtype>
constexpr
258 template<
typename Valtype>
constexpr
261 template<
typename Valtype>
constexpr
264 template<
typename Valtype>
constexpr
267 template<
typename Valtype>
constexpr
271 template<
typename Valtype>
constexpr
273 template<
typename Valtype>
constexpr
279 template<
typename Valtype>
constexpr
284 template<
typename Valtype>
constexpr
289 template<
typename Valtype>
constexpr
296 template<
typename Valtype>
constexpr
304 template<
typename Valtype>
constexpr
313 template<
class Valtype,
class EvalFuncType>
314 void Sample(
const common::Interval<Valtype> range,
const EvalFuncType Evaluate );
318template<
typename Valtype>
inline constexpr
324template<
typename Valtype>
inline constexpr
330template<
typename Valtype>
inline constexpr
336template<
typename Valtype>
337template<
typename Valtype2>
inline constexpr
343template<
typename Valtype>
inline
350template<
typename Valtype>
inline
353 m_Far = nearval + length;
357template<
typename Valtype>
inline constexpr
359 return static_cast<decltype(Valtype{}/Valtype{})
>(
m_Near >
m_Far ? -1 : +1);
362template<
typename Valtype>
inline constexpr
367template<
typename Valtype>
inline
374template<
typename Valtype>
inline
380template<
typename Valtype>
inline constexpr
385template<
typename Valtype>
inline constexpr
390template<
typename Valtype>
inline
396template<
typename Valtype>
inline
402template<
typename Valtype>
inline constexpr
407template<
typename Valtype>
inline constexpr
412template<
typename Valtype>
inline constexpr
414 if( std::numeric_limits<Valtype>::has_infinity ){
415 if(
m_Far == std::numeric_limits<Valtype>::infinity() ||
416 m_Near == -std::numeric_limits<Valtype>::infinity() )
417 return std::numeric_limits<Valtype>::infinity();
423template<
typename Valtype>
inline
430template<
typename Valtype>
inline constexpr
433 if( std::numeric_limits<Valtype>::has_infinity ){
434 if(
m_Far == std::numeric_limits<Valtype>::infinity() )
435 return m_Near == -std::numeric_limits<Valtype>::infinity() ? Valtype{0} : std::numeric_limits<Valtype>::infinity();
436 if(
m_Near == -std::numeric_limits<Valtype>::infinity() )
437 return -std::numeric_limits<Valtype>::infinity();
440#if __cplusplus >= 201703L
441 if constexpr( std::numeric_limits<Valtype>::is_integer )
448template<
typename Valtype>
inline
450 m_Near = i1.m_Near< i2.m_Near? i1.m_Near: i2.m_Near;
451 m_Far = i1.m_Far > i2.m_Far ? i1.m_Far : i2.m_Far;
455template<
typename Valtype>
inline
457 Union( *
this, interval );
461template<
typename Valtype>
inline
467template<
typename Valtype>
inline
473template<
typename Valtype>
inline constexpr
478template<
typename Valtype>
inline constexpr
484template<
typename Valtype>
inline constexpr
487 return m_Near-epsilon_ <= val && val <=
m_Far+epsilon_;
489 return m_Far-epsilon_ <= val && val <=
m_Near+epsilon_;
492template<
typename Valtype>
inline
497template<
typename Valtype>
inline
502template<
typename Valtype>
inline
508template<
typename Valtype>
inline
526template<
typename Valtype>
inline
540template<
typename Valtype>
inline
545template<
typename Valtype>
inline
552template<
typename Valtype>
inline
555 interval =
Near() + interval;
557 interval =
Near() - interval;
562template<
typename Valtype>
inline
565 interval = interval -
Near();
567 interval =
Near() - interval;
572template<
typename Valtype>
inline
578template<
typename Valtype>
inline
585template<
typename Valtype>
inline
590template<
typename Valtype>
inline constexpr
593 retval.
Union( i1, i2 );
597template<
typename Valtype>
inline constexpr
599 return { i1.m_Near + l, i1.m_Far + l };
602template<
typename Valtype>
inline constexpr
607template<
typename Valtype>
inline constexpr
609 return { +i1.m_Near, +i1.m_Far };
612template<
typename Valtype>
inline constexpr
614 return { i1.m_Near - l, i1.m_Far - l };
617template<
typename Valtype>
inline constexpr
622template<
typename Valtype>
inline constexpr
624 return { -i1.m_Near, -i1.m_Far };
627template<
typename Valtype,
typename Valtype2>
629 return { i1.m_Near * scalar, i1.m_Far * scalar };
632template<
typename Valtype,
typename Valtype2>
637template<
typename Valtype,
typename Valtype2>
inline constexpr
644template<
typename Valtype,
typename Valtype2>
646 return { i1.m_Near / scalar, i1.m_Far / scalar };
649template<
typename Valtype,
typename Valtype2>
656template<
typename Valtype>
inline constexpr
658 return i1.Near() < i2.Near() &&
659 i1.Near() <= i2.Far() &&
660 i1.Far() <= i2.Near() &&
661 i1.Far() <= i2.Far();
664template<
typename Valtype>
inline constexpr
669template<
typename Valtype>
671 return i1.Near() < i2.Near() &&
672 i1.Near() < i2.Far() &&
673 i1.Far() < i2.Near() &&
677template<
typename Valtype>
679 return i1.Near() <= i2.Near() &&
680 i1.Near() <= i2.Far() &&
681 i1.Far() <= i2.Near() &&
682 i1.Far() <= i2.Far();
685template<
typename Valtype>
690template<
typename Valtype>
695template<
typename Valtype>
constexpr
697 return i1.m_Near == i2.m_Near && i1.m_Far == i2.m_Far;
700template<
typename Valtype>
constexpr
702 return i1.m_Near != i2.m_Near || i1.m_Far != i2.m_Far;
705template<
typename Valtype>
inline constexpr
707 return !(i1 < i2 || i1 > i2);
710template<
typename Valtype>
715template<
typename Valtype>
720template<
typename Valtype>
723 abs(i1.Near() - i2.Near()) * Valtype{1} <= std::numeric_limits<Valtype>::epsilon() * abs(i1.Near()) ||
724 abs(i1.Near() - i2.Far()) * Valtype{1} <= std::numeric_limits<Valtype>::epsilon() * abs(i1.Near()) ||
725 abs(i1.Far() - i2.Near()) * Valtype{1} <= std::numeric_limits<Valtype>::epsilon() * abs(i1.Far()) ||
726 abs(i1.Far() - i2.Far()) * Valtype{1} <= std::numeric_limits<Valtype>::epsilon() * abs(i1.Far());
729template<
typename Valtype>
constexpr
732 return {Valtype{0},Valtype{0}};
736 return {(std::max)(i1.Near(),i2.Near()), (std::min)(i1.Far(),i2.Far())};
738 return {(std::max)(i1.Near(),i2.Far()), (std::min)(i1.Far(),i2.Near())};
742 return {(std::min)(i1.Near(),i2.Far()), (std::max)(i1.Far(),i2.Near())};
744 return {(std::min)(i1.Near(),i2.Near()), (std::max)(i1.Far(),i2.Far())};
748template<
class Valtype,
class EvalFuncType>
750 Valtype s = range.
Near();
756 while( s < range.
Far() - std::numeric_limits<Valtype>::epsilon() );
763 while( s > range.
Far() + std::numeric_limits<Valtype>::epsilon() );
766 Evaluate( range.
Far() );
Namespace of common utility classes and methods.
Definition Helpers.h:43
constexpr bool IntersectingClosed(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Definition Interval.h:711
constexpr auto operator*(const Interval< Valtype > &i1, Valtype2 scalar) noexcept -> Interval< decltype(Valtype{} *Valtype2{})>
Interval operator.
Definition Interval.h:628
constexpr Interval< Valtype > Intersection(const Interval< Valtype > &intersected, const Interval< Valtype > &with) noexcept
Definition Interval.h:730
constexpr bool operator!=(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Interval operator.
Definition Interval.h:701
T1 Wrap(const T1 &val, const T2 &min, const T2 &max) noexcept
Wraps a val to a specified range as if max would be actually min.
Definition Helpers.h:118
constexpr bool SmallerOpen(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Definition Interval.h:678
constexpr bool operator>(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Definition Interval.h:665
constexpr bool Intersecting(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Definition Interval.h:706
constexpr auto operator/(const Interval< Valtype > &i1, Valtype2 scalar) noexcept -> Interval< decltype(Valtype{}/Valtype2{})>
Interval operator.
Definition Interval.h:645
void Sample(const common::Interval< Valtype > range, const EvalFuncType Evaluate)
Samples an evaluating function inside an interval.
Definition Interval.h:749
T Round(T value, int toDigit) noexcept
Rounding of floating point number to a certain digit aftzer the point.
Definition Helpers.h:140
constexpr const T & Clamp(const T &v, const T &lo, const T &hi) noexcept
Clips a val to a specified range.
Definition Helpers.h:105
void operator+=(Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Interval operator.
Definition Interval.h:586
constexpr bool operator==(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Interval operator.
Definition Interval.h:696
constexpr bool GreaterOpen(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Definition Interval.h:691
constexpr bool GreaterClosed(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Definition Interval.h:686
constexpr bool Equals(T a, T b, T epsilon) noexcept
Tests equality in the sense |a-b| < epsilon.
Definition Helpers.h:66
constexpr bool operator<(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Definition Interval.h:657
T1 Clip(T1 &val, const T2 &min, const T2 &max) noexcept
Clips a val to a specified range.
Definition Helpers.h:88
constexpr Interval< Valtype > & operator*=(Interval< Valtype > &i1, Valtype2 scalar) noexcept
Interval operator.
Definition Interval.h:638
constexpr bool Touching(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Definition Interval.h:721
constexpr Interval< Valtype > & operator/=(Interval< Valtype > &i1, Valtype2 scalar) noexcept
Interval operator.
Definition Interval.h:650
constexpr bool IntersectingOpen(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Definition Interval.h:716
constexpr bool SmallerClosed(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Definition Interval.h:670
constexpr Interval< Valtype > operator+(const Interval< Valtype > &i1, const Interval< Valtype > &i2) noexcept
Interval operator.
Definition Interval.h:591
constexpr Interval< Valtype > operator-(const Interval< Valtype > &i1, Valtype l) noexcept
Interval operator.
Definition Interval.h:613
An interval describes the area between two numbers. It is understood to contain the near one and exlu...
Definition Interval.h:42
constexpr Angle Near() const noexcept
constexpr Angle Length() const noexcept
constexpr bool Touches(Angle val, Angle epsilon=Angle{0}) const noexcept
constexpr bool Equals(const Interval &interval, Valtype epsilon=std::numeric_limits< Valtype >::epsilon()) const noexcept
Comparison.
Definition Interval.h:573
Interval & ToParent(Interval &interval) const noexcept
Understands interval as relative to this and transforms it to parent.
Definition Interval.h:553
Interval & FromParent(Interval &interval) const noexcept
Understands interval as relative to parent and transforms it to this.
Definition Interval.h:563
Interval & Deflate(Valtype dx) noexcept
Shrinks the interval by dx at each end.
Definition Interval.h:541
constexpr Angle Min() const noexcept
constexpr Angle Far() const noexcept
Interval & Inflate(Valtype dx) noexcept
Extends the inteval by dx at each end.
Definition Interval.h:527
Interval & Expand(Valtype val) noexcept
Expands the interval so that it touches (being included or laying on border) val.
Definition Interval.h:509
Interval & Flip() noexcept
Valtype Wrap(Valtype &val) const noexcept
Wraps the value to the interval.
Definition Interval.h:503
Interval & Round(int toDigit) noexcept
Interval & Move(Valtype dx) noexcept
Moves the interval by dx.
Definition Interval.h:546
Angle m_Far
Definition Interval.h:45
constexpr Interval() noexcept=default
Does not initialize the members.
constexpr Angle Center() const noexcept
constexpr bool Includes(Angle val) const noexcept
Interval & Union(const Interval &i1, const Interval &i2) noexcept
constexpr Angle Max() const noexcept
Interval & Intersection(const Interval &intersected, const Interval &with) noexcept
Interval & Normalize() noexcept
Angle m_Near
Definition Interval.h:44
constexpr bool Normal() const noexcept
Is m_Near <= m_Far.
Definition Interval.h:363
Valtype Clip(Valtype &val) const noexcept
Clips the value to the interval.
Definition Interval.h:493
constexpr auto Sign() const noexcept -> decltype(Angle{}/Angle{})