Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TArithmeticArrayBase.ipp
Go to the documentation of this file.
1#pragma once
2
4#include "Math/math.h"
5
6#include <Common/assertion.h>
7
8#include <cmath>
9#include <utility>
10
11namespace ph::math
12{
13
14template<typename Derived, typename T, std::size_t N>
16{
17 m.fill(value);
18}
19
20template<typename Derived, typename T, std::size_t N>
24
25template<typename Derived, typename T, std::size_t N>
26inline auto TArithmeticArrayBase<Derived, T, N>::add(const Derived& rhs) const
27-> Derived
29 return Derived(static_cast<const Derived&>(*this)).addLocal(rhs);
30}
31
32template<typename Derived, typename T, std::size_t N>
33inline auto TArithmeticArrayBase<Derived, T, N>::add(const T rhs) const
34-> Derived
35{
36 return Derived(static_cast<const Derived&>(*this)).addLocal(rhs);
37}
38
39template<typename Derived, typename T, std::size_t N>
40inline auto TArithmeticArrayBase<Derived, T, N>::addLocal(const Derived& rhs)
41-> Derived&
43 for(std::size_t i = 0; i < N; ++i)
44 {
45 m[i] += rhs.Self::m[i];
46 }
47 return static_cast<Derived&>(*this);
50template<typename Derived, typename T, std::size_t N>
52-> Derived&
54 for(std::size_t i = 0; i < N; ++i)
55 {
56 m[i] += rhs;
57 }
58 return static_cast<Derived&>(*this);
61template<typename Derived, typename T, std::size_t N>
62inline auto TArithmeticArrayBase<Derived, T, N>::sub(const Derived& rhs) const
63-> Derived
65 return Derived(static_cast<const Derived&>(*this)).subLocal(rhs);
68template<typename Derived, typename T, std::size_t N>
69inline auto TArithmeticArrayBase<Derived, T, N>::sub(const T rhs) const
70-> Derived
71{
72 return Derived(static_cast<const Derived&>(*this)).subLocal(rhs);
74
75template<typename Derived, typename T, std::size_t N>
76inline auto TArithmeticArrayBase<Derived, T, N>::subLocal(const Derived& rhs)
77-> Derived&
79 for(std::size_t i = 0; i < N; ++i)
80 {
81 m[i] -= rhs.Self::m[i];
82 }
83 return static_cast<Derived&>(*this);
86template<typename Derived, typename T, std::size_t N>
88-> Derived&
90 for(std::size_t i = 0; i < N; ++i)
91 {
92 m[i] -= rhs;
93 }
94 return static_cast<Derived&>(*this);
97template<typename Derived, typename T, std::size_t N>
98inline auto TArithmeticArrayBase<Derived, T, N>::mul(const Derived& rhs) const
99-> Derived
101 return Derived(static_cast<const Derived&>(*this)).mulLocal(rhs);
104template<typename Derived, typename T, std::size_t N>
105inline auto TArithmeticArrayBase<Derived, T, N>::mul(const T rhs) const
106-> Derived
108 return Derived(static_cast<const Derived&>(*this)).mulLocal(rhs);
111template<typename Derived, typename T, std::size_t N>
113-> Derived&
115 for(std::size_t i = 0; i < N; ++i)
116 {
117 m[i] *= rhs.Self::m[i];
119 return static_cast<Derived&>(*this);
122template<typename Derived, typename T, std::size_t N>
124-> Derived&
126 for(std::size_t i = 0; i < N; ++i)
128 m[i] *= rhs;
130 return static_cast<Derived&>(*this);
133template<typename Derived, typename T, std::size_t N>
134inline auto TArithmeticArrayBase<Derived, T, N>::div(const Derived& rhs) const
135-> Derived
136{
137 return Derived(static_cast<const Derived&>(*this)).divLocal(rhs);
140template<typename Derived, typename T, std::size_t N>
141inline auto TArithmeticArrayBase<Derived, T, N>::div(const T rhs) const
142-> Derived
144 return Derived(static_cast<const Derived&>(*this)).divLocal(rhs);
145}
147template<typename Derived, typename T, std::size_t N>
149-> Derived&
151 for(std::size_t i = 0; i < N; ++i)
153 m[i] /= rhs.Self::m[i];
155 return static_cast<Derived&>(*this);
158template<typename Derived, typename T, std::size_t N>
160-> Derived&
162 for(std::size_t i = 0; i < N; ++i)
164 m[i] /= rhs;
165 }
166 return static_cast<Derived&>(*this);
167}
169template<typename Derived, typename T, std::size_t N>
170template<typename U>
171inline auto TArithmeticArrayBase<Derived, T, N>::pow(const U exponent) const
172-> Derived
174 return Derived(static_cast<const Derived&>(*this)).powLocal(exponent);
175}
177template<typename Derived, typename T, std::size_t N>
178template<typename U>
180-> Derived&
182 for(std::size_t i = 0; i < N; ++i)
183 {
184 m[i] = static_cast<T>(std::pow(m[i], exponent));
186 return static_cast<Derived&>(*this);
189template<typename Derived, typename T, std::size_t N>
190inline auto TArithmeticArrayBase<Derived, T, N>::pow(const Derived& exponent) const
191-> Derived
192{
193 return Derived(static_cast<const Derived&>(*this)).powLocal(exponent);
196template<typename Derived, typename T, std::size_t N>
197inline auto TArithmeticArrayBase<Derived, T, N>::powLocal(const Derived& exponent)
198-> Derived&
200 for(std::size_t i = 0; i < N; ++i)
201 {
202 m[i] = static_cast<T>(std::pow(m[i], exponent.Self::m[i]));
203 }
204 return static_cast<Derived&>(*this);
207template<typename Derived, typename T, std::size_t N>
208template<typename U>
209inline auto TArithmeticArrayBase<Derived, T, N>::exp(const U exponent) const
210-> Derived
212 return Derived(static_cast<const Derived&>(*this)).expLocal(exponent);
215template<typename Derived, typename T, std::size_t N>
216template<typename U>
218-> Derived&
219{
220 for(std::size_t i = 0; i < N; ++i)
221 {
222 m[i] = static_cast<T>(std::exp(exponent));
223 }
224 return static_cast<Derived&>(*this);
225}
226
227template<typename Derived, typename T, std::size_t N>
228inline auto TArithmeticArrayBase<Derived, T, N>::exp(const Derived& exponent) const
229-> Derived
230{
231 return Derived(static_cast<const Derived&>(*this)).expLocal(exponent);
232}
233
234template<typename Derived, typename T, std::size_t N>
235inline auto TArithmeticArrayBase<Derived, T, N>::expLocal(const Derived& exponent)
236-> Derived&
237{
238 for(std::size_t i = 0; i < N; ++i)
239 {
240 m[i] = static_cast<T>(std::exp(exponent.Self::m[i]));
241 }
242 return static_cast<Derived&>(*this);
243}
244
245template<typename Derived, typename T, std::size_t N>
247-> Derived
248{
249 return Derived(static_cast<const Derived&>(*this)).sqrtLocal();
250}
251
252template<typename Derived, typename T, std::size_t N>
254-> Derived&
255{
256 for(std::size_t i = 0; i < N; ++i)
257 {
258 m[i] = static_cast<T>(std::sqrt(m[i]));
259 }
260 return static_cast<Derived&>(*this);
261}
262
263template<typename Derived, typename T, std::size_t N>
264inline auto TArithmeticArrayBase<Derived, T, N>::clamp(const T lowerBound, const T upperBound) const
265-> Derived
266{
267 return Derived(static_cast<const Derived&>(*this)).clampLocal(lowerBound, upperBound);
268}
269
270template<typename Derived, typename T, std::size_t N>
271inline auto TArithmeticArrayBase<Derived, T, N>::clampLocal(const T lowerBound, const T upperBound)
272-> Derived&
273{
274 for(std::size_t i = 0; i < N; ++i)
275 {
276 m[i] = ::ph::math::clamp(m[i], lowerBound, upperBound);
277 }
278 return static_cast<Derived&>(*this);
279}
280
281template<typename Derived, typename T, std::size_t N>
282inline auto TArithmeticArrayBase<Derived, T, N>::clamp(const Derived& lowerBound, const Derived& upperBound) const
283-> Derived
284{
285 return Derived(static_cast<const Derived&>(*this)).clampLocal(lowerBound, upperBound);
286}
287
288template<typename Derived, typename T, std::size_t N>
289inline auto TArithmeticArrayBase<Derived, T, N>::clampLocal(const Derived& lowerBound, const Derived& upperBound)
290-> Derived&
291{
292 for(std::size_t i = 0; i < N; ++i)
293 {
294 m[i] = ::ph::math::clamp(m[i], lowerBound[i], upperBound[i]);
295 }
296 return static_cast<Derived&>(*this);
297}
298
299template<typename Derived, typename T, std::size_t N>
300inline auto TArithmeticArrayBase<Derived, T, N>::safeClamp(const T lowerBound, const T upperBound) const
301-> Derived
302{
303 return Derived(static_cast<const Derived&>(*this)).safeClampLocal(lowerBound, upperBound);
304}
305
306template<typename Derived, typename T, std::size_t N>
307inline auto TArithmeticArrayBase<Derived, T, N>::safeClampLocal(const T lowerBound, const T upperBound)
308-> Derived&
309{
310 for(std::size_t i = 0; i < N; ++i)
311 {
312 m[i] = ::ph::math::safe_clamp(m[i], lowerBound, upperBound);
313 }
314 return static_cast<Derived&>(*this);
315}
316
317template<typename Derived, typename T, std::size_t N>
318inline auto TArithmeticArrayBase<Derived, T, N>::safeClamp(const Derived& lowerBound, const Derived& upperBound) const
319-> Derived
320{
321 return Derived(static_cast<const Derived&>(*this)).safeClampLocal(lowerBound, upperBound);
322}
323
324template<typename Derived, typename T, std::size_t N>
325inline auto TArithmeticArrayBase<Derived, T, N>::safeClampLocal(const Derived& lowerBound, const Derived& upperBound)
326-> Derived&
327{
328 for(std::size_t i = 0; i < N; ++i)
329 {
330 m[i] = ::ph::math::safe_clamp(m[i], lowerBound[i], upperBound[i]);
331 }
332 return static_cast<Derived&>(*this);
333}
334
335template<typename Derived, typename T, std::size_t N>
337{
338 return ::ph::math::summation(m);
339}
340
341template<typename Derived, typename T, std::size_t N>
343{
344 if constexpr(std::is_floating_point_v<T>)
345 {
346 // Optimization for floating-point types: division by multiplication
347 constexpr T rcpN = static_cast<T>(1) / static_cast<T>(N);
348
349 return sum() * rcpN;
350 }
351 else
352 {
353 return sum() / static_cast<T>(N);
354 }
355}
356
357template<typename Derived, typename T, std::size_t N>
359{
360 return ::ph::math::product(m);
361}
362
363template<typename Derived, typename T, std::size_t N>
365{
366 return m[minIndex()];
367}
368
369template<typename Derived, typename T, std::size_t N>
370inline auto TArithmeticArrayBase<Derived, T, N>::min(const Derived& other) const
371-> Derived
372{
373 Derived result(static_cast<const Derived&>(*this));
374 for(std::size_t i = 0; i < N; ++i)
375 {
376 result.Self::m[i] = std::min(m[i], other.Self::m[i]);
377 }
378 return result;
379}
380
381template<typename Derived, typename T, std::size_t N>
383{
384 std::size_t result = 0;
385 for(std::size_t i = 1; i < N; ++i)
386 {
387 if(m[i] < m[result])
388 {
389 result = i;
390 }
391 }
392 return result;
393}
394
395template<typename Derived, typename T, std::size_t N>
397{
398 return m[maxIndex()];
399}
400
401template<typename Derived, typename T, std::size_t N>
402inline auto TArithmeticArrayBase<Derived, T, N>::max(const Derived& other) const
403-> Derived
404{
405 Derived result(static_cast<const Derived&>(*this));
406 for(std::size_t i = 0; i < N; ++i)
407 {
408 result.Self::m[i] = std::max(m[i], other.Self::m[i]);
409 }
410 return result;
411}
412
413template<typename Derived, typename T, std::size_t N>
415{
416 std::size_t result = 0;
417 for(std::size_t i = 1; i < N; ++i)
418 {
419 if(m[i] > m[result])
420 {
421 result = i;
422 }
423 }
424 return result;
425}
426
427template<typename Derived, typename T, std::size_t N>
429-> Derived
430{
431 if constexpr(std::is_floating_point_v<T>)
432 {
433 Derived result(static_cast<const Derived&>(*this));
434 for(std::size_t i = 0; i < N; ++i)
435 {
436 result.Self::m[i] = static_cast<T>(std::ceil(m[i]));
437 }
438 return result;
439 }
440 else
441 {
442 return static_cast<const Derived&>(*this);
443 }
444}
445
446template<typename Derived, typename T, std::size_t N>
448-> Derived
449{
450 if constexpr(std::is_floating_point_v<T>)
451 {
452 Derived result(static_cast<const Derived&>(*this));
453 for(std::size_t i = 0; i < N; ++i)
454 {
455 result.Self::m[i] = static_cast<T>(std::floor(m[i]));
456 }
457 return result;
458 }
459 else
460 {
461 return static_cast<const Derived&>(*this);
462 }
463}
464
465template<typename Derived, typename T, std::size_t N>
467-> Derived
468{
469 return Derived(static_cast<const Derived&>(*this)).absLocal();
470}
471
472template<typename Derived, typename T, std::size_t N>
474-> Derived&
475{
476 for(std::size_t i = 0; i < N; ++i)
477 {
478 m[i] = std::abs(m[i]);
479 }
480 return static_cast<Derived&>(*this);
481}
482
483template<typename Derived, typename T, std::size_t N>
485-> Derived
486{
487 return Derived(static_cast<const Derived&>(*this)).rcpLocal();
488}
489
490template<typename Derived, typename T, std::size_t N>
492-> Derived&
493{
494 for(std::size_t i = 0; i < N; ++i)
495 {
496 m[i] = static_cast<T>(1) / m[i];
497 }
498 return static_cast<Derived&>(*this);
499}
500
501template<typename Derived, typename T, std::size_t N>
503-> Derived
504{
505 return Derived(static_cast<const Derived&>(*this)).complementLocal();
506}
507
508template<typename Derived, typename T, std::size_t N>
510-> Derived&
511{
512 for(std::size_t i = 0; i < N; ++i)
513 {
514 m[i] = static_cast<T>(1) - m[i];
515 }
516 return static_cast<Derived&>(*this);
517}
518
519template<typename Derived, typename T, std::size_t N>
521-> Derived
522requires std::is_signed_v<T>
523{
524 return Derived(static_cast<const Derived&>(*this)).negateLocal();
525}
526
527template<typename Derived, typename T, std::size_t N>
529-> Derived&
530requires std::is_signed_v<T>
531{
532 return mulLocal(static_cast<T>(-1));
533}
534
535template<typename Derived, typename T, std::size_t N>
536template<typename U>
537inline auto TArithmeticArrayBase<Derived, T, N>::lerp(const Derived& rhs, const U factor) const
538-> Derived
539{
540 Derived result(static_cast<const Derived&>(*this));
541 for(std::size_t i = 0; i < N; ++i)
542 {
543 result.m[i] = m[i] * (static_cast<U>(1) - factor) + rhs.m[i] * factor;
544 }
545 return result;
546}
547
548template<typename Derived, typename T, std::size_t N>
550{
551 // While using `lengthSquared() == 0` is branchless, it can suffer from numerical
552 // error and report small (but non-zero) values as 0.
553
554 for(std::size_t i = 0; i < N; ++i)
555 {
556 if(m[i] != static_cast<T>(0))
557 {
558 return false;
559 }
560 }
561 return true;
562}
563
564template<typename Derived, typename T, std::size_t N>
566{
567 if constexpr(std::is_unsigned_v<T>)
568 {
569 return true;
570 }
571 else
572 {
573 for(std::size_t i = 0; i < N; ++i)
574 {
575 if(m[i] < 0)
576 {
577 return false;
578 }
579 }
580 return true;
581 }
582}
583
584template<typename Derived, typename T, std::size_t N>
586{
587 for(std::size_t i = 0; i < N; ++i)
588 {
589 if(!std::isfinite(m[i]))
590 {
591 return false;
592 }
593 }
594 return true;
595}
596
597template<typename Derived, typename T, std::size_t N>
598inline constexpr std::size_t TArithmeticArrayBase<Derived, T, N>::size() const noexcept
599{
600 return NUM_ELEMENTS;
601}
602
603template<typename Derived, typename T, std::size_t N>
605-> Derived&
606{
607 m.fill(value);
608 return static_cast<Derived&>(*this);
609}
610
611template<typename Derived, typename T, std::size_t N>
612inline auto TArithmeticArrayBase<Derived, T, N>::set(const std::size_t index, const T value)
613-> Derived&
614{
615 PH_ASSERT_LT(index, N);
616
617 m[index] = value;
618 return static_cast<Derived&>(*this);
619}
620
621template<typename Derived, typename T, std::size_t N>
622inline auto TArithmeticArrayBase<Derived, T, N>::set(const std::array<T, N>& values)
623-> Derived&
624{
625 m = values;
626 return static_cast<Derived&>(*this);
627}
628
629template<typename Derived, typename T, std::size_t N>
631{
632 PH_ASSERT_LT(index, N);
633
634 return m[index];
635}
636
637template<typename Derived, typename T, std::size_t N>
638inline const T& TArithmeticArrayBase<Derived, T, N>::operator [] (const std::size_t index) const
639{
640 PH_ASSERT_LT(index, N);
641
642 return m[index];
643}
644
645template<typename Derived, typename T, std::size_t N>
646inline bool TArithmeticArrayBase<Derived, T, N>::isEqual(const Derived& other) const
647{
648 return m == other.Self::m;
649}
650
651template<typename Derived, typename T, std::size_t N>
652inline bool TArithmeticArrayBase<Derived, T, N>::isNear(const Derived& other, const T margin) const
653{
654 for(std::size_t i = 0; i < N; ++i)
655 {
656 if(std::abs(m[i] - other.Self::m[i]) > margin)
657 {
658 return false;
659 }
660 }
661 return true;
662}
663
664template<typename Derived, typename T, std::size_t N>
665inline bool TArithmeticArrayBase<Derived, T, N>::operator == (const Derived& other) const
666{
667 return isEqual(other);
668}
669
670template<typename Derived, typename T, std::size_t N>
671inline bool TArithmeticArrayBase<Derived, T, N>::operator != (const Derived& other) const
672{
673 return !isEqual(other);
674}
675
676template<typename Derived, typename T, std::size_t N>
677inline auto TArithmeticArrayBase<Derived, T, N>::operator + (const Derived& rhs) const
678-> Derived
679{
680 return add(rhs);
681}
682
683template<typename Derived, typename T, std::size_t N>
685-> Derived
686{
687 return add(rhs);
688}
689
690template<typename Derived, typename T, std::size_t N>
691inline auto TArithmeticArrayBase<Derived, T, N>::operator - (const Derived& rhs) const
692-> Derived
693{
694 return sub(rhs);
695}
696
697template<typename Derived, typename T, std::size_t N>
699-> Derived
700{
701 return sub(rhs);
702}
703
704template<typename Derived, typename T, std::size_t N>
705inline auto TArithmeticArrayBase<Derived, T, N>::operator * (const Derived& rhs) const
706-> Derived
707{
708 return mul(rhs);
709}
710
711template<typename Derived, typename T, std::size_t N>
713-> Derived
714{
715 return mul(rhs);
716}
717
718template<typename Derived, typename T, std::size_t N>
719inline auto TArithmeticArrayBase<Derived, T, N>::operator / (const Derived& rhs) const
720-> Derived
721{
722 return div(rhs);
723}
724
725template<typename Derived, typename T, std::size_t N>
727-> Derived
728{
729 return div(rhs);
730}
731
732template<typename Derived, typename T, std::size_t N>
734-> Derived&
735{
736 return addLocal(rhs);
737}
738
739template<typename Derived, typename T, std::size_t N>
741-> Derived&
742{
743 return addLocal(rhs);
744}
745
746template<typename Derived, typename T, std::size_t N>
748-> Derived&
749{
750 return subLocal(rhs);
751}
752
753template<typename Derived, typename T, std::size_t N>
755-> Derived&
756{
757 return subLocal(rhs);
758}
759
760template<typename Derived, typename T, std::size_t N>
762-> Derived&
763{
764 return mulLocal(rhs);
765}
766
767template<typename Derived, typename T, std::size_t N>
769-> Derived&
770{
771 return mulLocal(rhs);
772}
773
774template<typename Derived, typename T, std::size_t N>
776-> Derived&
777{
778 return divLocal(rhs);
779}
780
781template<typename Derived, typename T, std::size_t N>
783-> Derived&
784{
785 return divLocal(rhs);
786}
787
788template<typename Derived, typename T, std::size_t N>
790-> Derived
791requires std::is_signed_v<T>
792{
793 return negate();
794}
795
796template<typename Derived, typename T, std::size_t N>
798-> typename std::array<T, N>::iterator
799{
800 return m.begin();
801}
802
803template<typename Derived, typename T, std::size_t N>
805-> typename std::array<T, N>::const_iterator
806{
807 return m.cbegin();
808}
809
810template<typename Derived, typename T, std::size_t N>
812-> typename std::array<T, N>::iterator
813{
814 return m.end();
815}
816
817template<typename Derived, typename T, std::size_t N>
819-> typename std::array<T, N>::const_iterator
820{
821 return m.cend();
822}
823
824template<typename Derived, typename T, std::size_t N>
826-> std::string
827{
828 PH_ASSERT_NE(N, 0);
829
830 std::string result("[");
831 result += std::to_string(m[0]);
832 for(std::size_t i = 1; i < N; ++i)
833 {
834 result += ", " + std::to_string(m[i]);
835 }
836 result += "]";
837
838 return result;
839}
840
841template<typename Derived, typename T, std::size_t N>
843-> std::vector<T>
844{
845 std::vector<T> vector(N);
846 for(std::size_t i = 0; i < N; ++i)
847 {
848 vector[i] = m[i];
849 }
850
851 return vector;
852}
853
854template<typename Derived, typename T, std::size_t N>
856-> std::array<T, N>
857{
858 return m;
859}
860
861template<typename Derived, typename T, std::size_t N>
864{
865 return m;
866}
867
868template<typename Derived, typename T, std::size_t N>
870-> TSpanView<T, N>
871{
872 return m;
873}
874
875}// end namespace ph::math
auto begin() noexcept -> typename std::array< T, N >::iterator
Definition TArithmeticArrayBase.ipp:797
Derived exp(U exponent) const
Sets the array to .
bool isZero() const
Definition TArithmeticArrayBase.ipp:549
T sum() const
Definition TArithmeticArrayBase.ipp:336
Derived mul(const Derived &rhs) const
Definition TArithmeticArrayBase.ipp:98
bool operator!=(const Derived &other) const
Definition TArithmeticArrayBase.ipp:671
Derived operator*(const Derived &rhs) const
Definition TArithmeticArrayBase.ipp:705
Derived & operator+=(const Derived &rhs)
Definition TArithmeticArrayBase.ipp:733
Derived pow(U exponent) const
Derived sqrt() const
Definition TArithmeticArrayBase.ipp:246
std::vector< T > toVector() const
Definition TArithmeticArrayBase.ipp:842
T avg() const
Definition TArithmeticArrayBase.ipp:342
Derived complement() const
Complements the array's elements. Effectively performing 1 - (*this)[i] for each element.
Definition TArithmeticArrayBase.ipp:502
Derived floor() const
Definition TArithmeticArrayBase.ipp:447
std::array< T, N > toArray() const
Definition TArithmeticArrayBase.ipp:855
T product() const
Definition TArithmeticArrayBase.ipp:358
Derived & sqrtLocal()
Definition TArithmeticArrayBase.ipp:253
Derived & safeClampLocal(T lowerBound, T upperBound)
Definition TArithmeticArrayBase.ipp:307
Derived & expLocal(U exponent)
Derived safeClamp(T lowerBound, T upperBound) const
Clamps current array's elements to specific range. If a floating-point value is non-finite (e....
Definition TArithmeticArrayBase.ipp:300
TSpanView< T, N > toView() const
Definition TArithmeticArrayBase.ipp:869
Derived & divLocal(const Derived &rhs)
Definition TArithmeticArrayBase.ipp:148
Derived & set(T value)
Definition TArithmeticArrayBase.ipp:604
T & operator[](std::size_t index)
Definition TArithmeticArrayBase.ipp:630
auto end() noexcept -> typename std::array< T, N >::iterator
Definition TArithmeticArrayBase.ipp:811
Derived operator+(const Derived &rhs) const
Definition TArithmeticArrayBase.ipp:677
Derived & absLocal()
Definition TArithmeticArrayBase.ipp:473
Derived clamp(T lowerBound, T upperBound) const
Clamps current array's elements to specific range. None of value, lowerBound and upperBound can be Na...
Definition TArithmeticArrayBase.ipp:264
Derived operator/(const Derived &rhs) const
Definition TArithmeticArrayBase.ipp:719
Derived & addLocal(const Derived &rhs)
Definition TArithmeticArrayBase.ipp:40
Derived lerp(const Derived &rhs, U factor) const
Derived & operator-=(const Derived &rhs)
Definition TArithmeticArrayBase.ipp:747
Derived sub(const Derived &rhs) const
Definition TArithmeticArrayBase.ipp:62
Derived div(const Derived &rhs) const
Definition TArithmeticArrayBase.ipp:134
std::string toString() const
Definition TArithmeticArrayBase.ipp:825
Derived operator-() const
Definition TArithmeticArrayBase.ipp:789
Derived & negateLocal()
Definition TArithmeticArrayBase.ipp:528
Derived & rcpLocal()
Definition TArithmeticArrayBase.ipp:491
T min() const
Definition TArithmeticArrayBase.ipp:364
Derived abs() const
Definition TArithmeticArrayBase.ipp:466
bool isFinite() const
Definition TArithmeticArrayBase.ipp:585
std::size_t maxIndex() const
Definition TArithmeticArrayBase.ipp:414
Derived negate() const
Applies a negative sign to the array's elements. These methods is only defined for signed element typ...
Definition TArithmeticArrayBase.ipp:520
Derived & mulLocal(const Derived &rhs)
Definition TArithmeticArrayBase.ipp:112
TSpan< T, N > toSpan()
Definition TArithmeticArrayBase.ipp:862
bool isNear(const Derived &other, T margin) const
Definition TArithmeticArrayBase.ipp:652
std::size_t minIndex() const
Definition TArithmeticArrayBase.ipp:382
TArithmeticArrayBase(T value)
Definition TArithmeticArrayBase.ipp:15
T max() const
Definition TArithmeticArrayBase.ipp:396
bool isNonNegative() const
Definition TArithmeticArrayBase.ipp:565
Derived & clampLocal(T lowerBound, T upperBound)
Definition TArithmeticArrayBase.ipp:271
Derived add(const Derived &rhs) const
Definition TArithmeticArrayBase.ipp:26
Derived & subLocal(const Derived &rhs)
Definition TArithmeticArrayBase.ipp:76
constexpr std::size_t size() const noexcept
Number of elements of the array.
Definition TArithmeticArrayBase.ipp:598
bool isEqual(const Derived &other) const
Definition TArithmeticArrayBase.ipp:646
Derived & powLocal(U exponent)
std::array< T, N > Elements
Definition TArithmeticArrayBase.h:25
bool operator==(const Derived &other) const
Definition TArithmeticArrayBase.ipp:665
Derived ceil() const
Definition TArithmeticArrayBase.ipp:428
Derived & complementLocal()
Definition TArithmeticArrayBase.ipp:509
Derived & operator/=(const Derived &rhs)
Definition TArithmeticArrayBase.ipp:775
Derived rcp() const
Definition TArithmeticArrayBase.ipp:484
Derived & operator*=(const Derived &rhs)
Definition TArithmeticArrayBase.ipp:761
Miscellaneous math utilities.
Math functions and utilities.
Definition TransformInfo.h:10
T safe_clamp(const T value, const T lowerBound, const T upperBound)
Clamps a value to [lowerBound, upperBound], fallback to lowerBound. If a floating-point value is non-...
Definition math.h:98
T clamp(const T value, const T lowerBound, const T upperBound)
Clamps a value to [lowerBound, upperBound]. None of value, lowerBound and upperBound can be NaN,...
Definition math.h:77
std::span< const T, EXTENT > TSpanView
Same as TSpan, except that the objects are const-qualified. Note that for pointer types,...
Definition TSpan.h:19
std::span< T, EXTENT > TSpan
A contiguous sequence of objects of type T. Effectively the same as std::span.
Definition TSpan.h:12
Definition TAABB2D.h:96