21 #ifndef LIB_LIGHTMETRICA_VECTOR_H
22 #define LIB_LIGHTMETRICA_VECTOR_H
24 #include "math.common.h"
25 #include "math.simd.h"
28 LM_MATH_NAMESPACE_BEGIN
30 template <
typename T>
struct TVec2;
31 template <
typename T>
struct TVec3;
32 template <
typename T>
struct TVec4;
45 LM_FORCE_INLINE
TVec2();
49 LM_FORCE_INLINE
TVec2(
const T& v);
50 LM_FORCE_INLINE
TVec2(
const T& x,
const T& y);
51 LM_FORCE_INLINE T& operator[](
int i);
52 LM_FORCE_INLINE
const T& operator[](
int i)
const;
57 LM_FORCE_INLINE
TVec2<T>& operator*=(
const T& s);
59 LM_FORCE_INLINE
TVec2<T>& operator/=(
const T& s);
65 template <
typename T> LM_FORCE_INLINE
TVec2<T> operator*(
const TVec2<T>& v,
const T& s);
66 template <
typename T> LM_FORCE_INLINE
TVec2<T> operator*(
const T& s,
const TVec2<T>& v);
68 template <
typename T> LM_FORCE_INLINE
TVec2<T> operator/(
const TVec2<T>& v,
const T& s);
71 template <
typename T> LM_FORCE_INLINE
bool operator==(
const TVec2<T>& v1,
const TVec2<T>& v2);
72 template <
typename T> LM_FORCE_INLINE
bool operator!=(
const TVec2<T>& v1,
const TVec2<T>& v2);
74 template <
typename T> LM_FORCE_INLINE T Length(
const TVec2<T>& v);
75 template <
typename T> LM_FORCE_INLINE T Length2(
const TVec2<T>& v);
77 template <
typename T> LM_FORCE_INLINE T Dot(
const TVec2<T>& v1,
const TVec2<T>& v2);
78 template <
typename T> LM_FORCE_INLINE T LInfinityNorm(
const TVec2<T>& v);
100 LM_FORCE_INLINE
TVec3();
104 LM_FORCE_INLINE
TVec3(
const T& v);
105 LM_FORCE_INLINE
TVec3(
const T& x,
const T& y,
const T& z);
107 LM_FORCE_INLINE T& operator[](
int i);
108 LM_FORCE_INLINE
const T& operator[](
int i)
const;
113 LM_FORCE_INLINE
TVec3<T>& operator*=(
const T& s);
115 LM_FORCE_INLINE
TVec3<T>& operator/=(
const T& s);
121 template <
typename T> LM_FORCE_INLINE
TVec3<T> operator*(
const TVec3<T>& v,
const T& s);
122 template <
typename T> LM_FORCE_INLINE
TVec3<T> operator*(
const T& s,
const TVec3<T>& v);
124 template <
typename T> LM_FORCE_INLINE
TVec3<T> operator/(
const TVec3<T>& v,
const T& s);
126 template <
typename T> LM_FORCE_INLINE
TVec3<T> operator-(
const TVec3<T>& v);
127 template <
typename T> LM_FORCE_INLINE
bool operator==(
const TVec3<T>& v1,
const TVec3<T>& v2);
128 template <
typename T> LM_FORCE_INLINE
bool operator!=(
const TVec3<T>& v1,
const TVec3<T>& v2);
130 template <
typename T> LM_FORCE_INLINE T Length(
const TVec3<T>& v);
131 template <
typename T> LM_FORCE_INLINE T Length2(
const TVec3<T>& v);
132 template <
typename T> LM_FORCE_INLINE
TVec3<T> Normalize(
const TVec3<T>& v);
133 template <
typename T> LM_FORCE_INLINE T Dot(
const TVec3<T>& v1,
const TVec3<T>& v2);
135 template <
typename T> LM_FORCE_INLINE T LInfinityNorm(
const TVec3<T>& v);
140 template <
typename T> LM_FORCE_INLINE T Luminance(
const TVec3<T>& v);
141 template <
typename T> LM_FORCE_INLINE
bool IsZero(
const TVec3<T>& v);
145 template <
typename T> LM_FORCE_INLINE T CosThetaZUp(
const TVec3<T>& v);
146 template <
typename T> LM_FORCE_INLINE T AbsCosThetaZUp(
const TVec3<T>& v);
147 template <
typename T> LM_FORCE_INLINE T SinTheta2ZUp(
const TVec3<T>& v);
148 template <
typename T> LM_FORCE_INLINE T TanThetaZUp(
const TVec3<T>& v);
149 template <
typename T> LM_FORCE_INLINE
TVec3<T> ReflectZUp(
const TVec3<T>& wi);
150 template <
typename T> LM_FORCE_INLINE
TVec3<T> RefractZUp(
const TVec3<T>& wi,
const T& eta,
const T& cosThetaT);
163 template <
typename T>
169 LM_FORCE_INLINE
TVec4();
173 LM_FORCE_INLINE
TVec4(
const T& v);
174 LM_FORCE_INLINE
TVec4(
const T& x,
const T& y,
const T& z,
const T& w);
176 LM_FORCE_INLINE T& operator[](
int i);
177 LM_FORCE_INLINE
const T& operator[](
int i)
const;
182 LM_FORCE_INLINE
TVec4<T>& operator*=(
const T& s);
184 LM_FORCE_INLINE
TVec4<T>& operator/=(
const T& s);
190 template <
typename T> LM_FORCE_INLINE
TVec4<T> operator*(
const TVec4<T>& v,
const T& s);
191 template <
typename T> LM_FORCE_INLINE
TVec4<T> operator*(
const T& s,
const TVec4<T>& v);
193 template <
typename T> LM_FORCE_INLINE
TVec4<T> operator/(
const TVec4<T>& v,
const T& s);
195 template <
typename T> LM_FORCE_INLINE
TVec4<T> operator-(
const TVec4<T>& v);
196 template <
typename T> LM_FORCE_INLINE
bool operator==(
const TVec4<T>& v1,
const TVec4<T>& v2);
197 template <
typename T> LM_FORCE_INLINE
bool operator!=(
const TVec4<T>& v1,
const TVec4<T>& v2);
199 template <
typename T> LM_FORCE_INLINE T Length(
const TVec4<T>& v);
200 template <
typename T> LM_FORCE_INLINE T Length2(
const TVec4<T>& v);
201 template <
typename T> LM_FORCE_INLINE
TVec4<T> Normalize(
const TVec4<T>& v);
202 template <
typename T> LM_FORCE_INLINE T Dot(
const TVec4<T>& v1,
const TVec4<T>& v2);
220 struct LM_ALIGN_16
TVec3<float>
226 struct {
float x, y, z, _; };
229 LM_FORCE_INLINE
TVec3();
233 LM_FORCE_INLINE
TVec3(
float v);
234 LM_FORCE_INLINE
TVec3(__m128 v);
235 LM_FORCE_INLINE
TVec3(
float x,
float y,
float z);
236 LM_FORCE_INLINE
TVec3(
const Vec2f& v,
float z);
237 LM_FORCE_INLINE
float operator[](
int i)
const;
238 LM_FORCE_INLINE
Vec3f& operator=(
const Vec3f& v);
239 LM_FORCE_INLINE
Vec3f& operator+=(
const Vec3f& v);
240 LM_FORCE_INLINE
Vec3f& operator-=(
const Vec3f& v);
241 LM_FORCE_INLINE
Vec3f& operator*=(
const Vec3f& v);
242 LM_FORCE_INLINE
Vec3f& operator*=(
float s);
243 LM_FORCE_INLINE
Vec3f& operator/=(
const Vec3f& v);
244 LM_FORCE_INLINE
Vec3f& operator/=(
float s);
248 template <> LM_FORCE_INLINE
Vec3f operator+(
const Vec3f& v1,
const Vec3f& v2);
249 template <> LM_FORCE_INLINE
Vec3f operator-(
const Vec3f& v1,
const Vec3f& v2);
250 template <> LM_FORCE_INLINE
Vec3f operator*(
const Vec3f& v,
const float& s);
251 template <> LM_FORCE_INLINE
Vec3f operator*(
const float& s,
const Vec3f& v);
252 template <> LM_FORCE_INLINE
Vec3f operator*(
const Vec3f& v1,
const Vec3f& v2);
253 template <> LM_FORCE_INLINE
Vec3f operator/(
const Vec3f& v,
const float& s);
254 template <> LM_FORCE_INLINE
Vec3f operator/(
const Vec3f& v1,
const Vec3f& v2);
255 template <> LM_FORCE_INLINE
Vec3f operator-(
const Vec3f& v);
257 template <> LM_FORCE_INLINE
float Length(
const Vec3f& v);
258 template <> LM_FORCE_INLINE
float Length2(
const Vec3f& v);
259 template <> LM_FORCE_INLINE
Vec3f Normalize(
const Vec3f& v);
260 template <> LM_FORCE_INLINE
float Dot(
const Vec3f& v1,
const Vec3f& v2);
261 template <> LM_FORCE_INLINE
Vec3f Cross(
const Vec3f& v1,
const Vec3f& v2);
262 template <> LM_FORCE_INLINE
float LInfinityNorm(
const Vec3f& v);
264 template <> LM_FORCE_INLINE
Vec3f Min(
const Vec3f& v1,
const Vec3f& v2);
265 template <> LM_FORCE_INLINE
Vec3f Max(
const Vec3f& v1,
const Vec3f& v2);
267 template <> LM_FORCE_INLINE
bool IsZero(
const Vec3f& v);
276 struct LM_ALIGN_16
TVec4<float>
282 struct {
float x, y, z, w; };
285 LM_FORCE_INLINE
TVec4();
289 LM_FORCE_INLINE
TVec4(
float v);
290 LM_FORCE_INLINE
TVec4(__m128 v);
291 LM_FORCE_INLINE
TVec4(
float x,
float y,
float z,
float w);
292 LM_FORCE_INLINE
TVec4(
const Vec3f& v,
float w);
293 LM_FORCE_INLINE
float operator[](
int i)
const;
294 LM_FORCE_INLINE
Vec4f& operator=(
const Vec4f& v);
295 LM_FORCE_INLINE
Vec4f& operator+=(
const Vec4f& v);
296 LM_FORCE_INLINE
Vec4f& operator-=(
const Vec4f& v);
297 LM_FORCE_INLINE
Vec4f& operator*=(
const Vec4f& v);
298 LM_FORCE_INLINE
Vec4f& operator*=(
float s);
299 LM_FORCE_INLINE
Vec4f& operator/=(
const Vec4f& v);
300 LM_FORCE_INLINE
Vec4f& operator/=(
float s);
304 template <> LM_FORCE_INLINE
Vec4f operator+(
const Vec4f& v1,
const Vec4f& v2);
305 template <> LM_FORCE_INLINE
Vec4f operator-(
const Vec4f& v1,
const Vec4f& v2);
306 template <> LM_FORCE_INLINE
Vec4f operator*(
const Vec4f& v,
const float& s);
307 template <> LM_FORCE_INLINE
Vec4f operator*(
const float& s,
const Vec4f& v);
308 template <> LM_FORCE_INLINE
Vec4f operator*(
const Vec4f& v1,
const Vec4f& v2);
309 template <> LM_FORCE_INLINE
Vec4f operator/(
const Vec4f& v,
const float& s);
310 template <> LM_FORCE_INLINE
Vec4f operator/(
const Vec4f& v1,
const Vec4f& v2);
311 template <> LM_FORCE_INLINE
Vec4f operator-(
const Vec4f& v);
313 template <> LM_FORCE_INLINE
float Length(
const Vec4f& v);
314 template <> LM_FORCE_INLINE
float Length2(
const Vec4f& v);
315 template <> LM_FORCE_INLINE
Vec4f Normalize(
const Vec4f& v);
316 template <> LM_FORCE_INLINE
float Dot(
const Vec4f& v1,
const Vec4f& v2);
318 template <> LM_FORCE_INLINE
Vec4f Min(
const Vec4f& v1,
const Vec4f& v2);
319 template <> LM_FORCE_INLINE
Vec4f Max(
const Vec4f& v1,
const Vec4f& v2);
332 struct LM_ALIGN_32
TVec3<double>
338 struct {
double x, y, z, _; };
341 LM_FORCE_INLINE
TVec3();
345 LM_FORCE_INLINE
TVec3(
double v);
346 LM_FORCE_INLINE
TVec3(__m256d v);
347 LM_FORCE_INLINE
TVec3(
double x,
double y,
double z);
348 LM_FORCE_INLINE
TVec3(
const Vec2d& v,
double z);
349 LM_FORCE_INLINE
double operator[](
int i)
const;
350 LM_FORCE_INLINE
Vec3d& operator=(
const Vec3d& v);
351 LM_FORCE_INLINE
Vec3d& operator+=(
const Vec3d& v);
352 LM_FORCE_INLINE
Vec3d& operator-=(
const Vec3d& v);
353 LM_FORCE_INLINE
Vec3d& operator*=(
const Vec3d& v);
354 LM_FORCE_INLINE
Vec3d& operator*=(
double s);
355 LM_FORCE_INLINE
Vec3d& operator/=(
const Vec3d& v);
356 LM_FORCE_INLINE
Vec3d& operator/=(
double s);
360 template <> LM_FORCE_INLINE
Vec3d operator+(
const Vec3d& v1,
const Vec3d& v2);
361 template <> LM_FORCE_INLINE
Vec3d operator-(
const Vec3d& v1,
const Vec3d& v2);
362 template <> LM_FORCE_INLINE
Vec3d operator*(
const Vec3d& v,
const double& s);
363 template <> LM_FORCE_INLINE
Vec3d operator*(
const double& s,
const Vec3d& v);
364 template <> LM_FORCE_INLINE
Vec3d operator*(
const Vec3d& v1,
const Vec3d& v2);
365 template <> LM_FORCE_INLINE
Vec3d operator/(
const Vec3d& v,
const double& s);
366 template <> LM_FORCE_INLINE
Vec3d operator/(
const Vec3d& v1,
const Vec3d& v2);
367 template <> LM_FORCE_INLINE
Vec3d operator-(
const Vec3d& v);
369 template <> LM_FORCE_INLINE
double Length(
const Vec3d& v);
370 template <> LM_FORCE_INLINE
double Length2(
const Vec3d& v);
371 template <> LM_FORCE_INLINE
Vec3d Normalize(
const Vec3d& v);
372 template <> LM_FORCE_INLINE
double Dot(
const Vec3d& v1,
const Vec3d& v2);
373 template <> LM_FORCE_INLINE
Vec3d Cross(
const Vec3d& v1,
const Vec3d& v2);
374 template <> LM_FORCE_INLINE
double LInfinityNorm(
const Vec3d& v);
376 template <> LM_FORCE_INLINE
Vec3d Min(
const Vec3d& v1,
const Vec3d& v2);
377 template <> LM_FORCE_INLINE
Vec3d Max(
const Vec3d& v1,
const Vec3d& v2);
379 template <> LM_FORCE_INLINE
bool IsZero(
const Vec3d& v);
388 struct LM_ALIGN_32
TVec4<double>
396 struct {
double x, y, z, w; };
399 LM_FORCE_INLINE
TVec4();
403 LM_FORCE_INLINE
TVec4(
double v);
404 LM_FORCE_INLINE
TVec4(__m256d v);
405 LM_FORCE_INLINE
TVec4(
double x,
double y,
double z,
double w);
406 LM_FORCE_INLINE
TVec4(
const Vec3d& v,
double w);
407 LM_FORCE_INLINE
double operator[](
int i)
const;
408 LM_FORCE_INLINE
Vec4d& operator=(
const Vec4d& v);
409 LM_FORCE_INLINE
Vec4d& operator+=(
const Vec4d& v);
410 LM_FORCE_INLINE
Vec4d& operator-=(
const Vec4d& v);
411 LM_FORCE_INLINE
Vec4d& operator*=(
const Vec4d& v);
412 LM_FORCE_INLINE
Vec4d& operator*=(
double s);
413 LM_FORCE_INLINE
Vec4d& operator/=(
const Vec4d& v);
414 LM_FORCE_INLINE
Vec4d& operator/=(
double s);
418 template <> LM_FORCE_INLINE
Vec4d operator+(
const Vec4d& v1,
const Vec4d& v2);
419 template <> LM_FORCE_INLINE
Vec4d operator-(
const Vec4d& v1,
const Vec4d& v2);
420 template <> LM_FORCE_INLINE
Vec4d operator*(
const Vec4d& v,
const double& s);
421 template <> LM_FORCE_INLINE
Vec4d operator*(
const double& s,
const Vec4d& v);
422 template <> LM_FORCE_INLINE
Vec4d operator*(
const Vec4d& v1,
const Vec4d& v2);
423 template <> LM_FORCE_INLINE
Vec4d operator/(
const Vec4d& v,
const double& s);
424 template <> LM_FORCE_INLINE
Vec4d operator/(
const Vec4d& v1,
const Vec4d& v2);
425 template <> LM_FORCE_INLINE
Vec4d operator-(
const Vec4d& v);
427 template <> LM_FORCE_INLINE
double Length(
const Vec4d& v);
428 template <> LM_FORCE_INLINE
double Length2(
const Vec4d& v);
429 template <> LM_FORCE_INLINE
Vec4d Normalize(
const Vec4d& v);
430 template <> LM_FORCE_INLINE
double Dot(
const Vec4d& v1,
const Vec4d& v2);
432 template <> LM_FORCE_INLINE
Vec4d Min(
const Vec4d& v1,
const Vec4d& v2);
433 template <> LM_FORCE_INLINE
Vec4d Max(
const Vec4d& v1,
const Vec4d& v2);
437 LM_MATH_NAMESPACE_END
440 #include "math.vector.inl"
442 #endif // LIB_LIGHTMETRICA_VECTOR_H
Definition: math.vector.h:32
Definition: math.vector.h:31
Definition: math.vector.h:30