Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TVectorNBase.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
10namespace ph::math
11{
12
13template<typename Derived, typename T, std::size_t N>
14inline T TVectorNBase<Derived, T, N>::dot(const Derived& rhs) const
15{
16 return ::ph::math::dot_product(m, rhs.Self::m);
17}
18
19template<typename Derived, typename T, std::size_t N>
20inline T TVectorNBase<Derived, T, N>::dot(const T rhs) const
21{
22 return sum() * rhs;
23}
24
25template<typename Derived, typename T, std::size_t N>
26inline T TVectorNBase<Derived, T, N>::absDot(const Derived& rhs) const
27{
28 return std::abs(dot(rhs));
29}
31template<typename Derived, typename T, std::size_t N>
32inline T TVectorNBase<Derived, T, N>::absDot(const T rhs) const
34 return std::abs(dot(rhs));
37template<typename Derived, typename T, std::size_t N>
39{
40 return ::ph::math::length(m);
41}
43template<typename Derived, typename T, std::size_t N>
45{
46 return ::ph::math::length_squared(m);
47}
49template<typename Derived, typename T, std::size_t N>
51-> Derived
52{
53 return Derived(static_cast<const Derived&>(*this)).normalizeLocal();
54}
55
56template<typename Derived, typename T, std::size_t N>
58-> Derived&
59{
61
62 return static_cast<Derived&>(*this);
63}
64
65template<typename Derived, typename T, std::size_t N>
66inline auto TVectorNBase<Derived, T, N>::safeNormalize(const Derived& fallback) const
67-> Derived
68{
69 const Derived normalized = normalize();
70 return !normalized.isZero() && normalized.isFinite() ? normalized : fallback;
71}
72
73template<typename Derived, typename T, std::size_t N>
75{
76 // minIndex() is not exposed; use "this" to access it in current scope
77 return this->minIndex();
78}
79
80template<typename Derived, typename T, std::size_t N>
82{
83 // maxIndex() is not exposed; use "this" to access it in current scope
84 return this->maxIndex();
85}
86
87}// end namespace ph::math
T length() const
Definition TVectorNBase.ipp:38
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
std::size_t minDimension() const
Definition TVectorNBase.ipp:74
Miscellaneous math utilities.
Math functions and utilities.
Definition TransformInfo.h:10
void normalize(std::array< T, N > &vec)
Treating input values as a vector and normalize it. Notice that normalizing a integer typed vector wi...
Definition math.ipp:142