Photon Engine 2.0.0-beta
A physically based renderer.
Loading...
Searching...
No Matches
TLineSegment.ipp
Go to the documentation of this file.
1#pragma once
2
4
5#include <Common/assertion.h>
6
7#include <limits>
8#include <cmath>
9
10namespace ph::math
11{
12
13template<typename T>
14inline TLineSegment<T>::TLineSegment(const TVector3<T>& origin, const TVector3<T>& dir) :
16 origin,
17 dir,
18 static_cast<T>(0),
19 std::numeric_limits<T>::max())
20{}
21
22template<typename T>
24 const TVector3<T>& origin,
25 const TVector3<T>& dir,
26 const T minT,
27 const T maxT)
28{
29 setOrigin(origin);
30 setDir(dir);
31 setRange(minT, maxT);
32}
34template<typename T>
36{
37 m_dir.mulLocal(T(-1));
38
39 return *this;
40}
41
42template<typename T>
43inline void TLineSegment<T>::setMinT(const T t)
44{
45 m_minT = t;
46}
47
48template<typename T>
49inline void TLineSegment<T>::setMaxT(const T t)
51 m_maxT = t;
52}
53
54template<typename T>
55inline void TLineSegment<T>::setRange(const T minT, const T maxT)
56{
57 PH_ASSERT_LE(minT, maxT);
59 setMinT(minT);
60 setMaxT(maxT);
61}
62
63template<typename T>
64inline void TLineSegment<T>::setRange(const std::pair<T, T>& minMaxT)
65{
66 setRange(minMaxT.first, minMaxT.second);
67}
69template<typename T>
71{
72 m_origin = pos;
73}
74
75template<typename T>
76inline void TLineSegment<T>::setDir(const TVector3<T>& dir)
77{
78 m_dir = dir;
79}
80
81template<typename T>
83{
84 return m_origin;
85}
87template<typename T>
90 return m_dir;
91}
92
93template<typename T>
95{
96 return m_minT;
97}
99template<typename T>
101{
102 return m_maxT;
103}
104
105template<typename T>
106inline std::pair<T, T> TLineSegment<T>::getRange() const
107{
108 return {m_minT, m_maxT};
109}
111template<typename T>
113{
114 return m_dir * m_minT + m_origin;
115}
116
117template<typename T>
119{
120 return m_dir * m_maxT + m_origin;
121}
122
123template<typename T>
125{
126 return m_origin.add(m_dir.mul(t));
127}
128
129template<typename T>
130inline T TLineSegment<T>::getProjectedT(const TVector3<T>& point) const
131{
132 const TVector3<T> pointVec = point - m_origin;
133 return pointVec.dot(m_dir) / m_dir.lengthSquared();
134}
135
136template<typename T>
137inline T TLineSegment<T>::getFoldedT(const TVector3<T>& point) const
138{
139 const TVector3<T> pointVec = point - m_origin;
140 return std::sqrt(pointVec.lengthSquared() / m_dir.lengthSquared());
141}
142
143template<typename T>
145{
146 return m_maxT - m_minT;
147}
148
149}// end namespace ph::math
Represents a line segment in space.
Definition TLineSegment.h:25
void setMinT(T t)
Set the parametric distance where the segment starts.
Definition TLineSegment.ipp:43
TVector3< T > getHead() const
Get the coordinates on maximum parametric distance.
Definition TLineSegment.ipp:118
void setMaxT(T t)
Set the parametric distance where the segment ends.
Definition TLineSegment.ipp:49
T getMinT() const
Definition TLineSegment.ipp:94
void setOrigin(const TVector3< T > &pos)
Set the origin of the line.
Definition TLineSegment.ipp:70
const TVector3< T > & getOrigin() const
Definition TLineSegment.ipp:82
const TVector3< T > & getDir() const
Definition TLineSegment.ipp:88
void setDir(const TVector3< T > &dir)
Set the direction vector of the line.
Definition TLineSegment.ipp:76
TVector3< T > getPoint(T t) const
Get the coordinates referred to by the parametric distance t.
Definition TLineSegment.ipp:124
TLineSegment()=default
A line which state is unspecified.
T getMaxT() const
Definition TLineSegment.ipp:100
TVector3< T > getTail() const
Get the coordinates on minimum parametric distance.
Definition TLineSegment.ipp:112
T getDeltaT() const
Get the length of line in terms of parametric distance.
Definition TLineSegment.ipp:144
std::pair< T, T > getRange() const
Definition TLineSegment.ipp:106
void setRange(T minT, T maxT)
Set the parametric range where the segment extends. The range is [minT, maxT). This is equivalent to ...
Definition TLineSegment.ipp:55
TLineSegment & flip()
Point the line in opposite direction.
Definition TLineSegment.ipp:35
T getFoldedT(const TVector3< T > &point) const
Get the parametric distance of a point when it is rotated to the line.
Definition TLineSegment.ipp:137
T getProjectedT(const TVector3< T > &point) const
Get the parametric distance of a point when it is projected on the line.
Definition TLineSegment.ipp:130
Represents a 3-D vector.
Definition TVector3.h:17
T dot(const Derived &rhs) const
Definition TVectorNBase.ipp:14
T lengthSquared() const
Definition TVectorNBase.ipp:44
Derived add(const Derived &rhs) const
Definition TArithmeticArrayBase.ipp:26
Math functions and utilities.
Definition TransformInfo.h:10
Definition TAABB2D.h:96