Trax3 3.1.0
trax track library
Loading...
Searching...
No Matches
Interval.h
1// trax track library
2// AD 2014
3//
4// "hard-boiled eggs and nuts"
5//
6// Oliver Norvell Hardy
7//
8//
9// Copyright (c) 2025 Trend Redaktions- und Verlagsgesellschaft mbH
10// Copyright (c) 2019 Marc-Michael Horstmann
11//
12// Permission is hereby granted to any person obtaining a copy of this software
13// and associated source code (the "Software"), to use, view, and study the
14// Software for personal or internal business purposes, subject to the following
15// conditions:
16//
17// 1. Redistribution, modification, sublicensing, or commercial use of the
18// Software is NOT permitted without prior written consent from the copyright
19// holder.
20//
21// 2. The Software is provided "AS IS", without warranty of any kind, express
22// or implied.
23//
24// 3. All copies of the Software must retain this license notice.
25//
26// For further information, please contact: horstmann.marc@trendverlag.de
27
28#pragma once
29
30#include "Helpers.h"
31
32#include <algorithm>
33
34namespace common{
35
36
40 template<typename Valtype>
41 struct Interval
42 {
43 //TODO: rename m_Near m_Min and m_Far m_Max
44 Valtype m_Near;
45 Valtype m_Far;
46
52 constexpr Interval() noexcept = default;
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>
57 explicit constexpr Interval( const Interval<Valtype2>& interval ) noexcept;
59
60
64 Interval& Init() noexcept;
65
66 Interval& Init( Valtype nearval, Valtype length ) noexcept;
68
69
71 constexpr auto Sign() const noexcept ->decltype(Valtype{}/Valtype{});
72
73
75 constexpr bool Normal() const noexcept;
76
77
79 Interval& Normalize() noexcept;
80
81
83 Interval& Flip() noexcept;
84
85
87 constexpr Valtype Near() const noexcept;
88
89
91 constexpr Valtype Far() const noexcept;
92
93
95 Interval& Near( Valtype val ) noexcept;
96
97
99 Interval& Far( Valtype val ) noexcept;
100
101
103 constexpr Valtype Max() const noexcept;
104
105
107 constexpr Valtype Min() const noexcept;
108
109
111 constexpr Valtype Length() const noexcept;
112
113
116 Interval& Length( Valtype length ) noexcept;
117
118
120 constexpr Valtype Center() const noexcept;
121
122
124 Interval& Union( const Interval& i1, const Interval& i2 ) noexcept;
125
126
128 Interval& Union( const Interval& interval ) noexcept;
129
130
135 Interval& Intersection( const Interval& intersected, const Interval& with ) noexcept;
136
137
142 Interval& Intersection( const Interval& interval ) noexcept;
143
144
147 constexpr bool Includes( Valtype val ) const noexcept;
148
149
151 constexpr bool Includes( const Interval& interval ) const noexcept;
152
153
156 constexpr bool Touches( Valtype val, Valtype epsilon = Valtype{0} ) const noexcept;
157
158
161 Valtype Clip( Valtype& val ) const noexcept;
162
163 constexpr const Valtype& Clip( const Valtype& val ) const noexcept;
164
165
168 Valtype Wrap( Valtype& val ) const noexcept;
169
170
175 Interval& Expand( Valtype val ) noexcept;
176
177
179 Interval& Inflate( Valtype dx ) noexcept;
180
181
183 Interval& Deflate( Valtype dx ) noexcept;
184
185
187 Interval& Move( Valtype dx ) noexcept;
188
189
192 Interval& ToParent( Interval& interval ) const noexcept;
193
194
197 Interval& FromParent( Interval& interval ) const noexcept;
198
199
204 constexpr bool Equals( const Interval& interval, Valtype epsilon = std::numeric_limits<Valtype>::epsilon() ) const noexcept;
205
206
208 Interval& Round( int toDigit ) noexcept;
209 };
210
211
214
216 template<typename Valtype>
217 void operator+=( Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept;
218 template<typename Valtype> constexpr
219 Interval<Valtype> operator+( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept;
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
225 Interval<Valtype> operator+( const Interval<Valtype>& i1 ) noexcept;
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
231 Interval<Valtype> operator-( const Interval<Valtype>& i1 ) noexcept;
232
233 template<typename Valtype, typename Valtype2> constexpr
234 auto operator*( const Interval<Valtype>& i1, Valtype2 scalar ) noexcept -> Interval<decltype(Valtype{}*Valtype2{})>;
235
236 template<typename Valtype, typename Valtype2> constexpr
237 auto operator*( Valtype scalar, const Interval<Valtype2>& i1 ) noexcept -> Interval<decltype(Valtype{}*Valtype2{})>;
238
239 template<typename Valtype, typename Valtype2> constexpr
240 Interval<Valtype>& operator*=( Interval<Valtype>& i1, Valtype2 scalar ) noexcept;
241
242 template<typename Valtype, typename Valtype2> constexpr
243 auto operator/( const Interval<Valtype>& i1, Valtype2 scalar ) noexcept -> Interval<decltype(Valtype{}/Valtype2{})>;
244
245 template<typename Valtype, typename Valtype2> constexpr
246 Interval<Valtype>& operator/=( Interval<Valtype>& i1, Valtype2 scalar ) noexcept;
247
248
250 template<typename Valtype> constexpr
251 bool operator<( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept;
253 template<typename Valtype> constexpr
254 bool operator>( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept;
255
256
258 template<typename Valtype> constexpr
259 bool SmallerClosed( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept;
261 template<typename Valtype> constexpr
262 bool SmallerOpen( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept;
264 template<typename Valtype> constexpr
265 bool GreaterClosed( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept;
267 template<typename Valtype> constexpr
268 bool GreaterOpen( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept;
269
270
271 template<typename Valtype> constexpr
272 bool operator== ( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept;
273 template<typename Valtype> constexpr
274 bool operator!= ( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept;
276
277
279 template<typename Valtype> constexpr
280 bool Intersecting( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept;
281
282
284 template<typename Valtype> constexpr
285 bool IntersectingClosed( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept;
286
287
289 template<typename Valtype> constexpr
290 bool IntersectingOpen( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept;
291
292
296 template<typename Valtype> constexpr
297 bool Touching( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept;
298
299
304 template<typename Valtype> constexpr
305 Interval<Valtype> Intersection( const Interval<Valtype>& intersected, const Interval<Valtype>& with ) noexcept;
306
307
313 template<class Valtype, class EvalFuncType>
314 void Sample( const common::Interval<Valtype> range, const EvalFuncType Evaluate );
315
317//inlines:
318template<typename Valtype> inline constexpr
319Interval<Valtype>::Interval( Valtype val ) noexcept
320 : m_Near{val},
321 m_Far{val}
322{}
323
324template<typename Valtype> inline constexpr
325Interval<Valtype>::Interval( Valtype nearval, Valtype farval ) noexcept
326 : m_Near{nearval},
327 m_Far{farval}
328{}
329
330template<typename Valtype> inline constexpr
331Interval<Valtype>::Interval( const std::pair<Valtype,Valtype>& pair ) noexcept
332 : m_Near{pair.first},
333 m_Far{pair.second}
334{}
335
336template<typename Valtype>
337template<typename Valtype2> inline constexpr
339 : m_Near{interval.m_Near},
340 m_Far{interval.m_Far}
341{}
342
343template<typename Valtype> inline
345 m_Near = Valtype{0};
346 m_Far = Valtype{0};
347 return *this;
348}
349
350template<typename Valtype> inline
351Interval<Valtype>& Interval<Valtype>::Init( Valtype nearval, Valtype length ) noexcept{
352 m_Near = nearval;
353 m_Far = nearval + length;
354 return *this;
355}
356
357template<typename Valtype> inline constexpr
358auto Interval<Valtype>::Sign() const noexcept ->decltype(Valtype{}/Valtype{}){
359 return static_cast<decltype(Valtype{}/Valtype{})>(m_Near > m_Far ? -1 : +1);
360}
361
362template<typename Valtype> inline constexpr
363bool Interval<Valtype>::Normal() const noexcept{
364 return m_Near <= m_Far;
365}
366
367template<typename Valtype> inline
369 if( !Normal() )
370 Flip();
371 return *this;
372}
373
374template<typename Valtype> inline
376 std::swap( m_Near, m_Far );
377 return *this;
378}
379
380template<typename Valtype> inline constexpr
381Valtype Interval<Valtype>::Near() const noexcept{
382 return m_Near;
383}
384
385template<typename Valtype> inline constexpr
386Valtype Interval<Valtype>::Far() const noexcept{
387 return m_Far;
388}
389
390template<typename Valtype> inline
392 m_Near = val;
393 return *this;
394}
395
396template<typename Valtype> inline
398 m_Far = val;
399 return *this;
400}
401
402template<typename Valtype> inline constexpr
403Valtype Interval<Valtype>::Max() const noexcept{
404 return Normal() ? Far() : Near();
405}
406
407template<typename Valtype> inline constexpr
408Valtype Interval<Valtype>::Min() const noexcept{
409 return Normal() ? Near() : Far();
410}
411
412template<typename Valtype> inline constexpr
413Valtype Interval<Valtype>::Length() const noexcept{
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();
418 }
419
420 return m_Far - m_Near;
421}
422
423template<typename Valtype> inline
425 m_Near = -length/2;
426 m_Far = length/2;
427 return *this;
428}
429
430template<typename Valtype> inline constexpr
431Valtype Interval<Valtype>::Center() const noexcept{
432 assert( Normal() );
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();
438 }
439
440#if __cplusplus >= 201703L //C++17
441 if constexpr( std::numeric_limits<Valtype>::is_integer )
442 return (m_Far + m_Near) >> 1;
443 else
444#endif
445 return (m_Far + m_Near) / 2;
446}
447
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;
452 return *this;
453}
454
455template<typename Valtype> inline
457 Union( *this, interval );
458 return *this;
459}
460
461template<typename Valtype> inline
463 *this = common::Intersection( i1, i2 );
464 return *this;
465}
466
467template<typename Valtype> inline
469 *this = common::Intersection( *this, interval );
470 return *this;
471}
472
473template<typename Valtype> inline constexpr
474bool Interval<Valtype>::Includes( Valtype val ) const noexcept{
475 return Normal() ? m_Near <= val && val < m_Far : m_Far < val && val <= m_Near;
476}
477
478template<typename Valtype> inline constexpr
479bool Interval<Valtype>::Includes( const Interval& interval ) const noexcept{
480 return Includes( interval.m_Near ) &&
481 (Includes( interval.m_Far ) || m_Far == interval.m_Far);
482}
483
484template<typename Valtype> inline constexpr
485bool Interval<Valtype>::Touches( Valtype val, Valtype epsilon_ ) const noexcept{
486 if( Normal() )
487 return m_Near-epsilon_ <= val && val <= m_Far+epsilon_;
488 else
489 return m_Far-epsilon_ <= val && val <= m_Near+epsilon_;
490}
491
492template<typename Valtype> inline
493Valtype Interval<Valtype>::Clip( Valtype& val ) const noexcept{
494 return common::Clip( val, m_Near, m_Far );
495}
496
497template<typename Valtype> inline
498constexpr const Valtype& Interval<Valtype>::Clip( const Valtype& val ) const noexcept{
499 return Normal() ? common::Clamp( val, m_Near, m_Far ) : common::Clamp( val, m_Far, m_Near );
500}
501
502template<typename Valtype> inline
503Valtype Interval<Valtype>::Wrap( Valtype& val ) const noexcept{
504 val = common::Wrap( val, m_Near, m_Far );
505 return val;
506}
507
508template<typename Valtype> inline
510 if( Normal() ){
511 if( m_Near > val )
512 m_Near = val;
513 if( m_Far < val )
514 m_Far = val;
515 }
516 else{
517 if( m_Near < val )
518 m_Near = val;
519 if( m_Far > val )
520 m_Far = val;
521 }
522
523 return *this;
524}
525
526template<typename Valtype> inline
528 if( Normal() ){
529 m_Near-= dx;
530 m_Far += dx;
531 }
532 else{
533 m_Near+= dx;
534 m_Far -= dx;
535 }
536
537 return *this;
538}
539
540template<typename Valtype> inline
542 return Inflate( -dx );
543}
544
545template<typename Valtype> inline
547 m_Near+= dx;
548 m_Far += dx;
549 return *this;
550}
551
552template<typename Valtype> inline
554 if( Normal() )
555 interval = Near() + interval;
556 else
557 interval = Near() - interval;
558
559 return interval;
560}
561
562template<typename Valtype> inline
564 if( Normal() )
565 interval = interval - Near();
566 else
567 interval = Near() - interval;
568
569 return interval;
570}
571
572template<typename Valtype> inline
573constexpr bool Interval<Valtype>::Equals( const Interval<Valtype>& interval, Valtype epsilon_ ) const noexcept{
574 return common::Equals( m_Near, interval.m_Near, epsilon_ ) &&
575 common::Equals( m_Far, interval.m_Far, epsilon_ );
576}
577
578template<typename Valtype> inline
580 m_Near = common::Round( m_Near, toDigit );
581 m_Far = common::Round( m_Far, toDigit );
582 return *this;
583}
584
585template<typename Valtype> inline
586void operator+=( Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept{
587 i1.Union( i2 );
588}
589
590template<typename Valtype> inline constexpr
592 Interval<Valtype> retval;
593 retval.Union( i1, i2 );
594 return retval;
595}
596
597template<typename Valtype> inline constexpr
598Interval<Valtype> operator+( const Interval<Valtype>& i1, Valtype l ) noexcept{
599 return { i1.m_Near + l, i1.m_Far + l };
600}
601
602template<typename Valtype> inline constexpr
603Interval<Valtype> operator+( Valtype l, const Interval<Valtype>& i1 ) noexcept{
604 return i1 + l;
605}
606
607template<typename Valtype> inline constexpr
609 return { +i1.m_Near, +i1.m_Far };
610}
611
612template<typename Valtype> inline constexpr
613Interval<Valtype> operator-( const Interval<Valtype>& i1, Valtype l ) noexcept{
614 return { i1.m_Near - l, i1.m_Far - l };
615}
616
617template<typename Valtype> inline constexpr
618Interval<Valtype> operator-(Valtype l,const Interval<Valtype>& i1) noexcept{
619 return -(i1 - l);
620}
621
622template<typename Valtype> inline constexpr
624 return { -i1.m_Near, -i1.m_Far };
625}
626
627template<typename Valtype, typename Valtype2>
628inline constexpr auto operator*( const Interval<Valtype>& i1, Valtype2 scalar ) noexcept -> Interval<decltype(Valtype{}*Valtype2{})>{
629 return { i1.m_Near * scalar, i1.m_Far * scalar };
630}
631
632template<typename Valtype,typename Valtype2>
633inline constexpr auto operator*(Valtype scalar,const Interval<Valtype2>& i1) noexcept -> Interval<decltype(Valtype{}* Valtype2{})>{
634 return i1 * scalar;
635}
636
637template<typename Valtype, typename Valtype2> inline constexpr
638Interval<Valtype>& operator*=( Interval<Valtype>& i1, Valtype2 scalar ) noexcept{
639 i1.m_Near *= scalar;
640 i1.m_Far *= scalar;
641 return i1;
642}
643
644template<typename Valtype,typename Valtype2>
645inline constexpr auto operator/(const Interval<Valtype>& i1,Valtype2 scalar) noexcept -> Interval<decltype(Valtype{}/ Valtype2{})>{
646 return { i1.m_Near / scalar, i1.m_Far / scalar };
647}
648
649template<typename Valtype,typename Valtype2>
650inline constexpr Interval<Valtype>& operator/=( Interval<Valtype>& i1, Valtype2 scalar ) noexcept{
651 i1.m_Near /= scalar;
652 i1.m_Far /= scalar;
653 return i1;
654}
655
656template<typename Valtype> inline constexpr
657bool operator<( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept{
658 return i1.Near() < i2.Near() &&
659 i1.Near() <= i2.Far() &&
660 i1.Far() <= i2.Near() &&
661 i1.Far() <= i2.Far();
662}
663
664template<typename Valtype> inline constexpr
665bool operator>( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept{
666 return i2 < i1;
667}
668
669template<typename Valtype>
670inline constexpr bool SmallerClosed( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept{
671 return i1.Near() < i2.Near() &&
672 i1.Near() < i2.Far() &&
673 i1.Far() < i2.Near() &&
674 i1.Far() < i2.Far();
675}
676
677template<typename Valtype>
678inline constexpr bool SmallerOpen( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept{
679 return i1.Near() <= i2.Near() &&
680 i1.Near() <= i2.Far() &&
681 i1.Far() <= i2.Near() &&
682 i1.Far() <= i2.Far();
683}
684
685template<typename Valtype>
686inline constexpr bool GreaterClosed( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept{
687 return SmallerClosed( i2, i1 );
688}
689
690template<typename Valtype>
691inline constexpr bool GreaterOpen( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept{
692 return SmallerOpen( i2, i1 );
693}
694
695template<typename Valtype> constexpr
696bool operator==( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept{
697 return i1.m_Near == i2.m_Near && i1.m_Far == i2.m_Far;
698}
699
700template<typename Valtype> constexpr
701bool operator!= ( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept{
702 return i1.m_Near != i2.m_Near || i1.m_Far != i2.m_Far;
703}
704
705template<typename Valtype> inline constexpr
706bool Intersecting( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept{
707 return !(i1 < i2 || i1 > i2);
708}
709
710template<typename Valtype>
711inline constexpr bool IntersectingClosed( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept{
712 return !(SmallerClosed( i1, i2 ) || GreaterClosed( i1, i2 ));
713}
714
715template<typename Valtype>
716inline constexpr bool IntersectingOpen( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept{
717 return !(SmallerOpen( i1, i2 ) || GreaterOpen( i1, i2 ));
718}
719
720template<typename Valtype>
721inline constexpr bool Touching( const Interval<Valtype>& i1, const Interval<Valtype>& i2 ) noexcept{
722 return Intersecting(i1,i2) ||
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());
727}
728
729template<typename Valtype> constexpr
731 if( !Intersecting( i1, i2 ) )
732 return {Valtype{0},Valtype{0}};
733
734 if( i1.Normal() ){
735 if( i2.Normal() )
736 return {(std::max)(i1.Near(),i2.Near()), (std::min)(i1.Far(),i2.Far())};
737 else
738 return {(std::max)(i1.Near(),i2.Far()), (std::min)(i1.Far(),i2.Near())};
739 }
740 else{
741 if( i2.Normal() )
742 return {(std::min)(i1.Near(),i2.Far()), (std::max)(i1.Far(),i2.Near())};
743 else
744 return {(std::min)(i1.Near(),i2.Near()), (std::max)(i1.Far(),i2.Far())};
745 }
746}
747
748template<class Valtype, class EvalFuncType>
749void Sample( const common::Interval<Valtype> range, const EvalFuncType Evaluate ){
750 Valtype s = range.Near();
751 if( range.Normal() )
752 {
753 do{
754 s += Evaluate( s );
755 }
756 while( s < range.Far() - std::numeric_limits<Valtype>::epsilon() );
757 }
758 else
759 {
760 do{
761 s -= Evaluate( s );
762 }
763 while( s > range.Far() + std::numeric_limits<Valtype>::epsilon() );
764 }
765
766 Evaluate( range.Far() );
767}
768
769}
770
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
STL namespace.
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{})