Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
THeavisideStep2D.h
Go to the documentation of this file.
1#pragma once
2
4#include "Math/TVector2.h"
5
6#include <cmath>
7#include <algorithm>
8
9namespace ph::math
10{
11
18template<typename Value>
19class THeavisideStep2D : public TMathFunction2D<Value>
20{
21public:
22 static auto makeHorizontal() -> THeavisideStep2D;
23 static auto makeVertical() -> THeavisideStep2D;
24
25 explicit THeavisideStep2D(TVector2<Value> normal);
26
27 Value evaluate(Value x, Value y) const override;
28
29private:
30 TVector2<Value> m_unitNormal;
31};
32
33template<typename Value>
39
40template<typename Value>
43{
44 return THeavisideStep2D({0, 1});
45}
46
47template<typename Value>
49 : m_unitNormal(normal.normalize())
50{}
51
52template<typename Value>
53inline Value THeavisideStep2D<Value>::evaluate(const Value x, const Value y) const
54{
55 const Value projectedSignedLengthOnNormal = m_unitNormal.dot({x, y});
56 return projectedSignedLengthOnNormal > 0
57 ? 1
58 : (projectedSignedLengthOnNormal < 0 ? 0 : static_cast<Value>(0.5));
59}
60
61}// end namespace ph::math
A step function in 2-D, with a specific normal direction. This is a simplified version of general Hea...
Definition THeavisideStep2D.h:20
static auto makeVertical() -> THeavisideStep2D
Definition THeavisideStep2D.h:41
Value evaluate(Value x, Value y) const override
Definition THeavisideStep2D.h:53
static auto makeHorizontal() -> THeavisideStep2D
Definition THeavisideStep2D.h:34
THeavisideStep2D(TVector2< Value > normal)
Definition THeavisideStep2D.h:48
Definition TMathFunction2D.h:8
Represents a 2-D vector.
Definition TVector2.h:19
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