Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TVectorNBase.h
Go to the documentation of this file.
1#pragma once
2
4#include "Math/math_fwd.h"
5#include "Utility/utility.h"
6
7#include <cstddef>
8
9namespace ph::math
10{
11
12template<typename Derived, typename T, std::size_t N>
13class TVectorNBase : public TArithmeticArrayBase<Derived, T, N>
14{
15private:
17 using Self = TVectorNBase;
18
19protected:
20 using Base::m;
21
22// Hide special members as this class is not intended to be used polymorphically.
23// It is derived class's choice to expose them (by defining them in public) or not.
24protected:
26
27public:
28 using Base::Base;
29
30 T dot(const Derived& rhs) const;
31 T dot(T rhs) const;
32 T absDot(const Derived& rhs) const;
33 T absDot(T rhs) const;
34
35 T length() const;
36 T lengthSquared() const;
37
42 Derived normalize() const;
43 Derived& normalizeLocal();
45
46 Derived safeNormalize(const Derived& fallback = Derived{}) const;
47
48 std::size_t minDimension() const;
49 std::size_t maxDimension() const;
50
52 using Base::size;
53
54 using Base::add;
55 using Base::addLocal;
56
57 using Base::sub;
58 using Base::subLocal;
59
60 using Base::mul;
61 using Base::mulLocal;
62
63 using Base::div;
64 using Base::divLocal;
65
66 using Base::pow;
67 using Base::powLocal;
68
69 using Base::exp;
70 using Base::expLocal;
71
72 using Base::sqrt;
73 using Base::sqrtLocal;
74
75 using Base::clamp;
76 using Base::clampLocal;
77 using Base::safeClamp;
79
80 using Base::abs;
81 using Base::absLocal;
82
83 using Base::rcp;
84 using Base::rcpLocal;
85
86 using Base::complement;
88
89 using Base::negate;
91
92 using Base::sum;
93 using Base::avg;
94 using Base::product;
95 using Base::min;
96 using Base::minIndex;
97 using Base::max;
98 using Base::maxIndex;
99 using Base::ceil;
100 using Base::floor;
101 using Base::lerp;
102 using Base::isZero;
104 using Base::isFinite;
105 using Base::set;
106 using Base::begin;
107 using Base::end;
108 using Base::isEqual;
109 using Base::isNear;
110 using Base::toString;
111 using Base::toVector;
112 using Base::toArray;
113 using Base::toSpan;
114 using Base::toView;
115
116 using Base::operator [];
117 using Base::operator ==;
118 using Base::operator !=;
119
120 using Base::operator +;
121 using Base::operator +=;
122 using Base::operator -;
123 using Base::operator -=;
124 using Base::operator *;
125 using Base::operator *=;
126 using Base::operator /;
127 using Base::operator /=;
128
129public:
133 friend Derived operator + (const T rhs, const Derived& lhs)
134 {
135 return lhs.add(rhs);
136 }
137
138 friend Derived operator - (const T rhs, const Derived& lhs)
139 {
140 return Derived{rhs}.sub(lhs);
141 }
142
143 friend Derived operator * (const T rhs, const Derived& lhs)
144 {
145 return lhs.mul(rhs);
146 }
147
148 friend Derived operator / (const T rhs, const Derived& lhs)
149 {
150 return lhs.rcp().mul(rhs);
151 }
153};
154
155}// end namespace ph::math
156
Definition TArithmeticArrayBase.h:20
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
Derived pow(U exponent) const
std::array< T, N > m
Definition TArithmeticArrayBase.h:217
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
auto end() noexcept -> typename std::array< T, N >::iterator
Definition TArithmeticArrayBase.ipp:811
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 & addLocal(const Derived &rhs)
Definition TArithmeticArrayBase.ipp:40
Derived lerp(const Derived &rhs, U factor) const
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 & 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
T max() const
Definition TArithmeticArrayBase.ipp:396
bool isNonNegative() const
Definition TArithmeticArrayBase.ipp:565
static constexpr auto NUM_ELEMENTS
Definition TArithmeticArrayBase.h:36
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)
Derived ceil() const
Definition TArithmeticArrayBase.ipp:428
Derived & complementLocal()
Definition TArithmeticArrayBase.ipp:509
Derived rcp() const
Definition TArithmeticArrayBase.ipp:484
Definition TVectorNBase.h:14
friend Derived operator*(const T rhs, const Derived &lhs)
Definition TVectorNBase.h:143
friend Derived operator-(const T rhs, const Derived &lhs)
Definition TVectorNBase.h:138
T length() const
Definition TVectorNBase.ipp:38
PH_DEFINE_INLINE_RULE_OF_5_MEMBERS(TVectorNBase)
friend Derived operator+(const T rhs, const Derived &lhs)
Non-member operators for expressions beginning with a single element value.
Definition TVectorNBase.h:133
Derived & normalizeLocal()
Definition TVectorNBase.ipp:57
T dot(const Derived &rhs) const
Definition TVectorNBase.ipp:14
Derived normalize() const
Normalize the vector. Notice that normalizing a integer typed vector will result in 0-vector most of ...
Definition TVectorNBase.ipp:50
Derived safeNormalize(const Derived &fallback=Derived{}) const
Definition TVectorNBase.ipp:66
T absDot(const Derived &rhs) const
Definition TVectorNBase.ipp:26
T lengthSquared() const
Definition TVectorNBase.ipp:44
std::size_t maxDimension() const
Definition TVectorNBase.ipp:81
friend Derived operator/(const T rhs, const Derived &lhs)
Definition TVectorNBase.h:148
std::size_t minDimension() const
Definition TVectorNBase.ipp:74
Math functions and utilities.
Definition TransformInfo.h:10