MathLib
Loading...
Searching...
No Matches
Vector4D.hpp
Go to the documentation of this file.
1#pragma once
2
6#include <tuple>
7#include <concepts>
8
16namespace Math
17{
18
23template <class Type>
25{
29 using value_type = Type;
31
38 template <class RType>
39 struct BasicRef
40 {
44 using value_type = RType;
46
47 constexpr BasicRef(RType &x_in, RType &y_in, RType &z_in, RType &w_in) : x{x_in}, y{y_in}, z{z_in}, w{w_in} { }
48 constexpr BasicRef(const BasicRef &) = default;
49 constexpr BasicRef(const BasicVector4D<RType> &other) : x{other.x}, y{other.y}, z{other.z}, w{other.w} { }
50
51 constexpr BasicRef &operator =(BasicRef input)
52 {
53 x = input.x;
54 y = input.y;
55 z = input.z;
56 w = input.w;
57 return *this;
58 }
59
60 constexpr BasicRef &operator =(const BasicVector4D<RType> &input)
61 {
62 x = input.x;
63 y = input.y;
64 z = input.z;
65 w = input.w;
66 return *this;
67 }
68
69 constexpr operator BasicVector4D<RType>() const { return { x, y, z, w }; }
70
71 constexpr operator std::tuple<RType, RType, RType, RType>() const { return std::make_tuple( x, y, z, w ); }
72
73 RType &x;
74 RType &y;
75 RType &z;
76 RType &w;
77
78 template <class U>
80 friend constexpr bool operator ==(BasicRef left, BasicRef<U> right)
81 {
82 return approximately_equal_to( left, right );
83 }
84
85 template <class U>
87 friend constexpr bool operator ==(BasicRef left, const BasicVector4D<U> &right)
88 {
89 return approximately_equal_to( left, right );
90 }
91
92 template <class U>
95 {
96 return { left.x + right.x,
97 left.y + right.y,
98 left.z + right.z,
99 left.w + right.w };
100 }
101
102 template <class U>
104 friend constexpr BasicVector4D<RType> operator +(BasicRef left, const BasicVector4D<U> &right)
105 {
106 return { left.x + right.x,
107 left.y + right.y,
108 left.z + right.z,
109 left.w + right.w };
110 }
111
112 template <class U>
115 {
116 return { left.x - right.x,
117 left.y - right.y,
118 left.z - right.z,
119 left.w - right.w };
120 }
121
122 template <class U>
124 friend constexpr BasicVector4D<RType> operator -(BasicRef left, const BasicVector4D<U> &right)
125 {
126 return { left.x - right.x,
127 left.y - right.y,
128 left.z - right.z,
129 left.w - right.w };
130 }
131
132 template <class U>
135 {
136 return { left.x * right.x,
137 left.y * right.y,
138 left.z * right.z,
139 left.w * right.w };
140 }
141
142 template <class U>
144 friend constexpr BasicVector4D<RType> operator *(BasicRef left, const BasicVector4D<U> &right)
145 {
146 return { left.x * right.x,
147 left.y * right.y,
148 left.z * right.z,
149 left.w * right.w };
150 }
151
152 template <class U>
154 friend constexpr BasicVector4D<RType> operator *(BasicRef left, const U &scalar)
155 {
156 return { left.x * scalar, left.y * scalar, left.z * scalar, left.w * scalar };
157 }
158
159 template <class U>
161 friend constexpr BasicVector4D<RType> operator *(const U &scalar, BasicRef right)
162 {
163 return { scalar * right.x, scalar * right.y, scalar * right.z, scalar * right.w };
164 }
165
166 template <class U>
169 {
170 return { left.x / right.x,
171 left.y / right.y,
172 left.z / right.z,
173 left.w / right.w };
174 }
175
176 template <class U>
178 friend constexpr BasicVector4D<RType> operator /(BasicRef left, const BasicVector4D<U> &right)
179 {
180 return { left.x / right.x,
181 left.y / right.y,
182 left.z / right.z,
183 left.w / right.w };
184 }
185
186 template <class U>
188 friend constexpr BasicVector4D<RType> operator /(BasicRef left, const U &scalar)
189 {
190 return { left.x / scalar, left.y / scalar, left.z / scalar, left.w / scalar };
191 }
192
193 template <class U, std::floating_point OT = float>
195 friend constexpr bool approximately_equal_to(BasicRef value_to_test,
196 BasicRef<U> value_it_should_be,
197 OT tolerance = OT{0.0002})
198 {
199 return approximately_equal_to(value_to_test.x, value_it_should_be.x, tolerance) &&
200 approximately_equal_to(value_to_test.y, value_it_should_be.y, tolerance) &&
201 approximately_equal_to(value_to_test.z, value_it_should_be.z, tolerance) &&
202 approximately_equal_to(value_to_test.w, value_it_should_be.w, tolerance);
203 }
204
205 template <class U, std::floating_point OT = float>
207 friend constexpr bool approximately_equal_to( BasicRef value_to_test,
208 const BasicVector4D<U> &value_it_should_be,
209 OT tolerance = OT{0.0002})
210 {
211 return approximately_equal_to(value_to_test.x, value_it_should_be.x, tolerance) &&
212 approximately_equal_to(value_to_test.y, value_it_should_be.y, tolerance) &&
213 approximately_equal_to(value_to_test.z, value_it_should_be.z, tolerance) &&
214 approximately_equal_to(value_to_test.w, value_it_should_be.w, tolerance);
215 }
216
217 friend constexpr RType accumulate(BasicRef input)
218 {
219 return input.x + input.y + input.z + input.w;
220 }
221
222 template <class U>
224 friend constexpr RType dot(BasicRef left, BasicRef<U> right)
225 {
226 return (left.x * right.x) + (left.y * right.y) + (left.z * right.z) + (left.w * right.w);
227 }
228
229 template <class U>
231 friend constexpr RType dot(BasicRef left, const BasicVector4D<U> &right)
232 {
233 return (left.x * right.x) + (left.y * right.y) + (left.z * right.z) + (left.w * right.w);
234 }
235
236 template <class U>
238 friend constexpr RType dot_normalized(BasicRef left, BasicRef<U> right)
239 {
240 return dot(left, right) / (left.magnitude() * right.magnitude());
241 }
242
243 template <class U>
245 friend constexpr RType dot_normalized(BasicRef left, const BasicVector4D<U> &right)
246 {
247 return dot(left, right) / (left.magnitude() * right.magnitude());
248 }
249
251 {
252 return BasicVector4D<RType>( input ).normalized();
253 }
254
255 friend constexpr BasicVector4D<RType> abs(BasicRef input)
256 {
257 return { std::abs(input.x), std::abs(input.y), std::abs(input.z), std::abs(input.w) };
258 }
259
261 {
262 RType dummy;
263
264 return { std::modf(input.x, &dummy),
265 std::modf(input.y, &dummy),
266 std::modf(input.z, &dummy),
267 std::modf(input.w, &dummy) };
268 }
269
270 friend constexpr BasicVector4D<RType> saturate(BasicRef input, RType lower_bound, RType upper_bound)
271 {
272 return { Math::saturate(input.x, lower_bound, upper_bound),
273 Math::saturate(input.y, lower_bound, upper_bound),
274 Math::saturate(input.z, lower_bound, upper_bound),
275 Math::saturate(input.w, lower_bound, upper_bound) };
276 }
277
278 template <class U>
280 friend constexpr BasicVector4D<RType> lerp(BasicRef input_lower_bound,
281 BasicRef<U> input_upper_bound,
282 float percentage_zero_to_one)
283 {
284 return (input_upper_bound - input_lower_bound) * percentage_zero_to_one + input_lower_bound;
285 }
286
287 template <class U>
289 friend constexpr BasicVector4D<RType> lerp(BasicRef input_lower_bound,
290 BasicVector4D<U> &input_upper_bound,
291 float percentage_zero_to_one)
292 {
293 return (input_upper_bound - input_lower_bound) * percentage_zero_to_one + input_lower_bound;
294 }
295
296 template <class U>
298 friend constexpr BasicVector4D<RType> mix(BasicRef input_lower_bound,
299 BasicRef<U> input_upper_bound,
300 float percentage_zero_to_one)
301 {
302 return lerp( input_lower_bound, input_upper_bound, percentage_zero_to_one );
303 }
304
305 template <class U>
307 friend constexpr BasicVector4D<RType> mix(BasicRef input_lower_bound,
308 BasicVector4D<U> &input_upper_bound,
309 float percentage_zero_to_one)
310 {
311 return lerp( input_lower_bound, input_upper_bound, percentage_zero_to_one );
312 }
313
314 friend std::string format(BasicRef input)
315 {
316 return std::format("[x: {:.6}, y: {:.6}, z: {:.6}, w: {:.6}]", input.x, input.y, input.z, input.w);
317 }
318
319 template <class U, std::floating_point OT = float>
321 friend bool check_if_equal(BasicRef input,
322 BasicRef<U> near_to,
323 OT tolerance = OT{0.0002})
324 {
325 if (!approximately_equal_to(input, near_to, tolerance))
326 {
327 auto diff{ near_to - input };
328
329 std::cout << std::format("input: {} is not equal to near_to: {} within tolerance: {}. Difference is {} .",
330 format(input),
331 format(near_to),
332 tolerance,
333 format(near_to - input))
334 << std::endl;
335 return false;
336 }
337 return true;
338 }
339
340 template <class U, std::floating_point OT = float>
342 friend bool check_if_equal( BasicRef input,
343 const BasicVector4D<U> &near_to,
344 OT tolerance = OT{0.0002})
345 {
346 if (!approximately_equal_to(input, near_to, tolerance))
347 {
348 auto diff{ near_to - input };
349
350 std::cout << std::format("input: {} is not equal to near_to: {} within tolerance: {}. Difference is {} .",
351 format(input),
352 format(near_to),
353 tolerance,
354 format(near_to - input))
355 << std::endl;
356 return false;
357 }
358 return true;
359 }
360
361 template <class U, std::floating_point OT = float>
363 friend bool check_if_not_equal(BasicRef input,
364 BasicRef near_to,
365 OT tolerance = OT{0.0002})
366 {
367 if (approximately_equal_to(input, near_to, tolerance))
368 {
369 auto diff{ near_to - input };
370
371 std::cout << std::format("input: {} is equal to near_to: {} within tolerance: {}. Difference is {} .",
372 format(input),
373 format(near_to),
374 tolerance,
375 format(near_to - input))
376 << std::endl;
377 return false;
378 }
379 return true;
380 }
381
382 template <class U, std::floating_point OT = float>
384 friend bool check_if_not_equal( BasicRef input,
385 const BasicVector4D<U> &near_to,
386 OT tolerance = OT{0.0002})
387 {
388 if (approximately_equal_to(input, near_to, tolerance))
389 {
390 auto diff{ near_to - input };
391
392 std::cout << std::format("input: {} is equal to near_to: {} within tolerance: {}. Difference is {} .",
393 format(input),
394 format(near_to),
395 tolerance,
396 format(near_to - input))
397 << std::endl;
398 return false;
399 }
400 return true;
401 }
402
403 template <class U, std::floating_point OT = float>
405 friend void CHECK_IF_NOT_EQUAL(BasicRef input,
406 BasicRef<U> near_to,
407 OT tolerance = OT{0.0002})
408 {
409 assert( check_if_not_equal(input, near_to, tolerance) );
410 }
411
412 template <class U, std::floating_point OT = float>
414 friend void CHECK_IF_NOT_EQUAL( BasicRef input,
415 const BasicVector4D<U> &near_to,
416 OT tolerance = OT{0.0002})
417 {
418 assert( check_if_not_equal(input, near_to, tolerance) );
419 }
420
421 template <std::floating_point OT = float>
422 friend void CHECK_IF_ZERO(BasicRef input, OT tolerance = OT{0.0002})
423 {
424 assert( check_if_equal(input, BasicVector4D<RType>::zero(), tolerance));
425 }
426 };
427
430
434 constexpr BasicVector4D() = default;
435 constexpr BasicVector4D(const Type &x_in, const Type &y_in = 0, const Type &z_in = 0, const Type &w_in = 0)
436 :
437 x{x_in},
438 y{y_in},
439 z{z_in},
440 w{w_in}
441 {
442 }
443 constexpr BasicVector4D(const BasicVector3D<Type> &first3, const Type &w_in = 0)
444 :
445 x{first3.x},
446 y{first3.y},
447 z{first3.z},
448 w{w_in}
449 {
450 }
451 constexpr BasicVector4D(const BasicVector2D<Type> &first2, const BasicVector2D<Type> &second2)
452 :
453 x{first2.x},
454 y{first2.y},
455 z{second2.x},
456 w{second2.y}
457 {
458 }
459 constexpr BasicVector4D(const Type &x_in, const BasicVector3D<Type> &last3)
460 :
461 x{x_in},
462 y{last3.x},
463 z{last3.y},
464 w{last3.z}
465 {
466 }
468
472 constexpr BasicVector4D<Type> &operator =(const BasicVector4D &other) = default;
474 {
475 x = other.x;
476 y = other.y;
477 z = other.z;
478 w = other.w;
479 return *this;
480 }
482
486 constexpr operator std::tuple<Type, Type, Type, Type>() const { return std::make_tuple( x, y, z ); }
488
492 constexpr static BasicVector4D<Type> unit_x() { return { Type{1}, Type{0}, Type{0}, Type{0} }; }
493 constexpr static BasicVector4D<Type> unit_y() { return { Type{0}, Type{1}, Type{0}, Type{0} }; }
494 constexpr static BasicVector4D<Type> unit_z() { return { Type{0}, Type{0}, Type{1}, Type{0} }; }
495 constexpr static BasicVector4D<Type> unit_w() { return { Type{0}, Type{0}, Type{0}, Type{1} }; }
496
497 constexpr static BasicVector4D<Type> zero() { return { }; }
499
500 constexpr value_type normSquared() const { return (x * x) + (y * y) + (z * z) + (w * w); }
501 constexpr value_type norm() const { return std::sqrt( normSquared() ); }
502
503 constexpr value_type magnitudeSquared() const { return normSquared(); }
504 constexpr value_type magnitude() const { return norm(); }
505
507 {
508 auto n = magnitude();
509
510 return { x / n, y / n, z / n, w / n };
511 }
512
516 bool isNaN() const { return std::isnan(x) || std::isnan(y) || std::isnan(z) || std::isnan(w); }
517 bool isInf() const { return std::isinf(x) || std::isinf(y) || std::isinf(z) || std::isinf(w); }
519
523 constexpr BasicVector2D<Type>::ConstRef xy() const & { return { x, y }; }
524 constexpr BasicVector2D<Type>::Ref xy() & { return { x, y }; }
525 constexpr BasicVector2D<Type> xy() && { return { x, y }; }
526
527 constexpr BasicVector2D<Type>::ConstRef xz() const & { return { x, z }; }
528 constexpr BasicVector2D<Type>::Ref xz() & { return { x, z }; }
529 constexpr BasicVector2D<Type> xz() && { return { x, z }; }
530
531 constexpr BasicVector2D<Type>::ConstRef yx() const & { return { y, x }; }
532 constexpr BasicVector2D<Type>::Ref yx() & { return { y, x }; }
533 constexpr BasicVector2D<Type> yx() && { return { y, x }; }
534
535 constexpr BasicVector2D<Type>::ConstRef yz() const & { return { y, z }; }
536 constexpr BasicVector2D<Type>::Ref yz() & { return { y, z }; }
537 constexpr BasicVector2D<Type> yz() && { return { y, z }; }
538
539 constexpr BasicVector2D<Type>::ConstRef zx() const & { return { z, x }; }
540 constexpr BasicVector2D<Type>::Ref zx() & { return { z, x }; }
541 constexpr BasicVector2D<Type> zx() && { return { z, x }; }
542
543 constexpr BasicVector3D<Type>::ConstRef xyz() const & { return { x, y, z }; }
544 constexpr BasicVector3D<Type>::Ref xyz() & { return { x, y, z }; }
545 constexpr BasicVector3D<Type> xyz() && { return { x, y, z }; }
546
547 constexpr BasicVector3D<Type>::ConstRef xzy() const & { return { x, z, y }; }
548 constexpr BasicVector3D<Type>::Ref xzy() & { return { x, z, y }; }
549 constexpr BasicVector3D<Type> xzy() && { return { x, z, y }; }
550
551 constexpr BasicVector3D<Type>::ConstRef zxy() const & { return { z, x, y }; }
552 constexpr BasicVector3D<Type>::Ref zxy() & { return { z, x, y }; }
553 constexpr BasicVector3D<Type> zxy() && { return { z, x, y }; }
554
555 constexpr BasicVector3D<Type>::ConstRef zyx() const & { return { z, y, x }; }
556 constexpr BasicVector3D<Type>::Ref zyx() & { return { z, y, x }; }
557 constexpr BasicVector3D<Type> zyx() && { return { z, y, x }; }
558
559 constexpr BasicVector3D<Type>::ConstRef xxx() const & { return { x, x, x }; }
560 constexpr BasicVector3D<Type>::Ref xxx() & { return { x, x, x }; }
561 constexpr BasicVector3D<Type> xxx() && { return { x, x, x }; }
562
563 constexpr BasicVector3D<Type>::ConstRef yyy() const & { return { y, y, y }; }
564 constexpr BasicVector3D<Type>::Ref yyy() & { return { y, y, y }; }
565 constexpr BasicVector3D<Type> yyy() && { return { y, y, y }; }
566
567 constexpr BasicVector3D<Type>::ConstRef zzz() const & { return { z, z, z }; }
568 constexpr BasicVector3D<Type>::Ref zzz() & { return { z, z, z }; }
569 constexpr BasicVector3D<Type> zzz() && { return { z, z, z }; }
570
571 constexpr BasicVector3D<Type>::ConstRef www() const & { return { w, w, w }; }
572 constexpr BasicVector3D<Type>::Ref www() & { return { w, w, w }; }
573 constexpr BasicVector3D<Type> www() && { return { w, w, w }; }
575
584
585private:
586
599 template <class U>
601 friend constexpr bool operator ==(const BasicVector4D &left, const BasicVector4D<U> &right)
602 {
603 return approximately_equal_to(left, right);
604 }
605
612 template <class U>
614 friend constexpr bool operator ==(const BasicVector4D &left, BasicRef<U> right)
615 {
616 return approximately_equal_to(left, right);
617 }
618
627 template <class U, std::floating_point OT = float>
629 friend constexpr bool approximately_equal_to(const BasicVector4D &value_to_test,
630 const BasicVector4D<U> &value_it_should_be,
631 OT tolerance = OT{0.0002})
632 {
633 return approximately_equal_to(value_to_test.x, value_it_should_be.x, tolerance) &&
634 approximately_equal_to(value_to_test.y, value_it_should_be.y, tolerance) &&
635 approximately_equal_to(value_to_test.z, value_it_should_be.z, tolerance) &&
636 approximately_equal_to(value_to_test.w, value_it_should_be.w, tolerance);
637 }
638
647 template <class U, std::floating_point OT = float>
649 friend constexpr bool approximately_equal_to(const BasicVector4D &value_to_test,
650 BasicRef<U> value_it_should_be,
651 OT tolerance = OT{0.0002})
652 {
653 return approximately_equal_to(value_to_test.x, value_it_should_be.x, tolerance) &&
654 approximately_equal_to(value_to_test.y, value_it_should_be.y, tolerance) &&
655 approximately_equal_to(value_to_test.z, value_it_should_be.z, tolerance) &&
656 approximately_equal_to(value_to_test.w, value_it_should_be.w, tolerance);
657 }
659
672 template <class U>
674 friend constexpr BasicVector4D<Type> operator +(const BasicVector4D &left, const BasicVector4D<U> &right)
675 {
676 return { left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w };
677 }
678
679 template <class U>
681 friend constexpr BasicVector4D<Type> operator +(const BasicVector4D &left, BasicRef<U> right)
682 {
683 return { left.x + right.x, left.y + right.y, left.z + right.z, left.w + right.w };
684 }
685
686 template <class U>
688 friend constexpr BasicVector4D<Type> operator -(const BasicVector4D &left, const BasicVector4D<U> &right)
689 {
690 return { left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w };
691 }
692
693 template <class U>
695 friend constexpr BasicVector4D<Type> operator -(const BasicVector4D &left, BasicRef<U> right)
696 {
697 return { left.x - right.x, left.y - right.y, left.z - right.z, left.w - right.w };
698 }
699
700 template <class U>
702 friend constexpr BasicVector4D<Type> operator *(const BasicVector4D &left, const BasicVector4D<U> &right)
703 {
704 return { left.x * right.x, left.y * right.y, left.z * right.z, left.w * right.w };
705 }
706
707 template <class U>
709 friend constexpr BasicVector4D<Type> operator *(const BasicVector4D &left, BasicRef<U> right)
710 {
711 return { left.x * right.x, left.y * right.y, left.z * right.z, left.w * right.w };
712 }
713
714 template <class U>
716 friend constexpr BasicVector4D<Type> operator *(const BasicVector4D &left, const U &scalar)
717 {
718 return { left.x * scalar, left.y * scalar, left.z * scalar, left.w * scalar };
719 }
720
721 template <class U>
723 friend constexpr BasicVector4D<Type> operator *(const U &scalar, const BasicVector4D<U> &right)
724 {
725 return { scalar * right.x, scalar * right.y, scalar * right.z, scalar * right.w };
726 }
727
728 template <class U>
730 friend constexpr BasicVector4D<Type> operator /(const BasicVector4D &left, const BasicVector4D<U> &right)
731 {
732 return { left.x / right.x, left.y / right.y, left.z / right.z, left.w / right.w };
733 }
734
735 template <class U>
737 friend constexpr BasicVector4D<Type> operator /(const BasicVector4D &left, BasicRef<U> right)
738 {
739 return { left.x / right.x, left.y / right.y, left.z / right.z, left.w / right.w };
740 }
741
742 template <class U>
744 friend constexpr BasicVector4D<Type> operator /(const BasicVector4D<Type> &left, const U &right)
745 {
746 return { left.x / right, left.y / right, left.z / right, left.w / right };
747 }
750
763 friend constexpr Type accumulate(const BasicVector4D<Type> &input)
764 {
765 return input.x + input.y + input.z + input.w;
766 }
767
779 template <class U>
781 friend constexpr Type dot(const BasicVector4D &left, const BasicVector4D<U> &right)
782 {
783 return (left.x * right.x) + (left.y * right.y) + (left.z * right.z) + (left.w * right.w);
784 }
785
797 template <class U>
799 friend constexpr Type dot(const BasicVector4D &left, BasicRef<U> right)
800 {
801 return (left.x * right.x) + (left.y * right.y) + (left.z * right.z) + (left.w * right.w);
802 }
803
815 template <class U>
817 friend constexpr Type dot_normalized(const BasicVector4D &left, const BasicVector4D<U> &right)
818 {
819 return dot(left, right) / (left.magnitude() * right.magnitude());
820 }
821
833 template <class U>
835 friend constexpr Type dot_normalized(const BasicVector4D &left, BasicRef<U> right)
836 {
837 return dot(left, right) / (left.magnitude() * right.magnitude());
838 }
839
847 {
848 return input.normalized();
849 }
850
857 friend constexpr BasicVector4D<Type> abs(const BasicVector4D<Type> &input)
858 {
859 return { std::abs(input.x),
860 std::abs(input.y),
861 std::abs(input.z),
862 std::abs(input.w) };
863 }
864
872 {
873 Type dummy;
874
875 return { std::modf(input.x, &dummy),
876 std::modf(input.y, &dummy),
877 std::modf(input.z, &dummy),
878 std::modf(input.w, &dummy) };
879 }
880
881 friend constexpr BasicVector4D<Type> saturate(const BasicVector4D<Type> &input,
882 Type lower_bound,
883 Type upper_bound)
884 {
885 return { Math::saturate(input.x, lower_bound, upper_bound),
886 Math::saturate(input.y, lower_bound, upper_bound),
887 Math::saturate(input.z, lower_bound, upper_bound),
888 Math::saturate(input.w, lower_bound, upper_bound) };
889 }
890
891 template <class U>
893 friend constexpr BasicVector4D<Type> lerp(const BasicVector4D &input_lower_bound,
894 const BasicVector4D<U> &input_upper_bound,
895 float percentage_zero_to_one)
896 {
897 return (input_upper_bound - input_lower_bound) * percentage_zero_to_one + input_lower_bound;
898 }
899
900 template <class U>
902 friend constexpr BasicVector4D<Type> lerp(const BasicVector4D &input_lower_bound,
903 BasicRef<U> input_upper_bound,
904 float percentage_zero_to_one)
905 {
906 return (input_upper_bound - input_lower_bound) * percentage_zero_to_one + input_lower_bound;
907 }
908
909 template <class U>
911 friend constexpr BasicVector4D<Type> mix(const BasicVector4D &input_lower_bound,
912 const BasicVector4D<U> &input_upper_bound,
913 float percentage_zero_to_one)
914 {
915 return lerp( input_lower_bound, input_upper_bound, percentage_zero_to_one );
916 }
917
918 template <class U>
920 friend constexpr BasicVector4D<Type> mix(const BasicVector4D &input_lower_bound,
921 BasicRef<U> input_upper_bound,
922 float percentage_zero_to_one)
923 {
924 return lerp( input_lower_bound, input_upper_bound, percentage_zero_to_one );
925 }
926
927 friend std::string format(const BasicVector4D &input)
928 {
929 return std::format("[x: {:.6}, y: {:.6}, z: {:.6}, w: {:.6}]", input.x, input.y, input.z, input.w);
930 }
932
950 template <class U, std::floating_point OT = float>
952 friend bool check_if_equal(const BasicVector4D &input,
953 const BasicVector4D<U> &near_to,
954 OT tolerance = OT{0.0002})
955 {
956 if (!approximately_equal_to(input, near_to, tolerance))
957 {
958 auto diff{ near_to - input };
959
960 std::cout << std::format("input: {} is not equal to near_to: {} within tolerance: {}. Difference is {} .",
961 format(input),
962 format(near_to),
963 tolerance,
964 format(near_to - input))
965 << std::endl;
966 return false;
967 }
968 return true;
969 }
970
979 template <class U, std::floating_point OT = float>
981 friend bool check_if_equal(const BasicVector4D &input,
982 BasicRef<U> near_to,
983 OT tolerance = OT{0.0002})
984 {
985 if (!approximately_equal_to(input, near_to, tolerance))
986 {
987 auto diff{ near_to - input };
988
989 std::cout << std::format("input: {} is not equal to near_to: {} within tolerance: {}. Difference is {} .",
990 format(input),
991 format(near_to),
992 tolerance,
993 format(near_to - input))
994 << std::endl;
995 return false;
996 }
997 return true;
998 }
999
1008 template <class U, std::floating_point OT = float>
1010 friend bool check_if_not_equal(const BasicVector4D &input,
1011 const BasicVector4D<U> &near_to,
1012 OT tolerance = OT{0.0002})
1013 {
1014 if (approximately_equal_to(input, near_to, tolerance))
1015 {
1016 auto diff{ near_to - input };
1017
1018 std::cout << std::format("input: {} is equal to near_to: {} within tolerance: {}. Difference is {} .",
1019 format(input),
1020 format(near_to),
1021 tolerance,
1022 format(near_to - input))
1023 << std::endl;
1024 return false;
1025 }
1026 return true;
1027 }
1028
1037 template <class U, std::floating_point OT = float>
1039 friend bool check_if_not_equal(const BasicVector4D &input,
1040 BasicRef<U> near_to,
1041 OT tolerance = OT{0.0002})
1042 {
1043 if (approximately_equal_to(input, near_to, tolerance))
1044 {
1045 auto diff{ near_to - input };
1046
1047 std::cout << std::format("input: {} is equal to near_to: {} within tolerance: {}. Difference is {} .",
1048 format(input),
1049 format(near_to),
1050 tolerance,
1051 format(near_to - input))
1052 << std::endl;
1053 return false;
1054 }
1055 return true;
1056 }
1059
1077 template <class U, std::floating_point OT = float>
1079 friend void CHECK_IF_EQUAL(const BasicVector4D &input,
1080 const BasicVector4D<U> &near_to,
1081 OT tolerance = OT{0.0002})
1082 {
1083 assert( check_if_equal(input, near_to, tolerance) );
1084 }
1085
1094 template <class U, std::floating_point OT = float>
1096 friend void CHECK_IF_EQUAL(const BasicVector4D &input,
1097 BasicRef<U> near_to,
1098 OT tolerance = OT{0.0002})
1099 {
1100 assert( check_if_equal(input, near_to, tolerance) );
1101 }
1102
1111 template <class U, std::floating_point OT = float>
1113 friend void CHECK_IF_NOT_EQUAL(const BasicVector4D &input,
1114 const BasicVector4D<U> &near_to,
1115 OT tolerance = OT{0.0002})
1116 {
1117 assert( check_if_not_equal(input, near_to, tolerance) );
1118 }
1119
1128 template <class U, std::floating_point OT = float>
1130 friend void CHECK_IF_NOT_EQUAL(const BasicVector4D &input,
1131 BasicRef<U> near_to,
1132 OT tolerance = OT{0.0002})
1133 {
1134 assert( check_if_not_equal(input, near_to, tolerance) );
1135 }
1136
1144 template <std::floating_point OT = float>
1145 friend void CHECK_IF_ZERO(const BasicVector4D<Type> &input, OT tolerance = OT{0.0002})
1146 {
1147 assert( check_if_equal(input, BasicVector4D<Type>::zero(), tolerance));
1148 }
1151};
1152
1153
1170
1176
1177
1195
1196}
friend void CHECK_IF_ZERO(const BasicVector4D< Type > &input, OT tolerance=OT{0.0002})
friend void CHECK_IF_EQUAL(const BasicVector4D &input, BasicRef< U > near_to, OT tolerance=OT{0.0002})
friend void CHECK_IF_EQUAL(const BasicVector4D &input, const BasicVector4D< U > &near_to, OT tolerance=OT{0.0002})
friend void CHECK_IF_NOT_EQUAL(const BasicVector4D &input, BasicRef< U > near_to, OT tolerance=OT{0.0002})
friend void CHECK_IF_NOT_EQUAL(const BasicVector4D &input, const BasicVector4D< U > &near_to, OT tolerance=OT{0.0002})
constexpr value_type normSquared() const
Definition Vector4D.hpp:500
constexpr BasicVector3D< Type >::ConstRef xxx() const &
Definition Vector4D.hpp:559
constexpr BasicVector3D< Type >::ConstRef xzy() const &
Definition Vector4D.hpp:547
constexpr BasicVector2D< Type > zx() &&
Definition Vector4D.hpp:541
constexpr BasicVector2D< Type >::Ref xz() &
Definition Vector4D.hpp:528
bool isNaN() const
Definition Vector4D.hpp:516
static constexpr BasicVector4D< Type > unit_x()
Definition Vector4D.hpp:492
friend constexpr BasicVector4D< RType > lerp(BasicRef input_lower_bound, BasicVector4D< U > &input_upper_bound, float percentage_zero_to_one)
Definition Vector4D.hpp:289
friend std::string format(BasicRef input)
Definition Vector4D.hpp:314
constexpr BasicVector4D()=default
friend constexpr bool approximately_equal_to(BasicRef value_to_test, BasicRef< U > value_it_should_be, OT tolerance=OT{0.0002})
Definition Vector4D.hpp:195
friend bool check_if_not_equal(BasicRef input, BasicRef near_to, OT tolerance=OT{0.0002})
Definition Vector4D.hpp:363
constexpr BasicVector3D< Type > zzz() &&
Definition Vector4D.hpp:569
constexpr BasicVector3D< Type > xyz() &&
Definition Vector4D.hpp:545
constexpr BasicVector3D< Type > zxy() &&
Definition Vector4D.hpp:553
constexpr BasicRef(const BasicVector4D< RType > &other)
Definition Vector4D.hpp:49
friend constexpr BasicVector4D< RType > operator/(BasicRef left, BasicRef< U > right)
Definition Vector4D.hpp:168
constexpr value_type magnitude() const
Definition Vector4D.hpp:504
constexpr BasicVector4D< Type > & operator=(const BasicVector4D &other)=default
constexpr BasicRef & operator=(BasicRef input)
Definition Vector4D.hpp:51
constexpr BasicVector3D< Type >::ConstRef xyz() const &
Definition Vector4D.hpp:543
constexpr BasicVector2D< Type > xy() &&
Definition Vector4D.hpp:525
constexpr BasicVector3D< Type >::ConstRef zxy() const &
Definition Vector4D.hpp:551
constexpr BasicRef(RType &x_in, RType &y_in, RType &z_in, RType &w_in)
Definition Vector4D.hpp:47
static constexpr BasicVector4D< Type > unit_z()
Definition Vector4D.hpp:494
constexpr BasicVector2D< Type >::Ref yz() &
Definition Vector4D.hpp:536
friend constexpr BasicVector4D< Type > saturate(const BasicVector4D< Type > &input, Type lower_bound, Type upper_bound)
Definition Vector4D.hpp:881
friend constexpr bool operator==(const BasicVector4D &left, const BasicVector4D< U > &right)
Definition Vector4D.hpp:601
constexpr BasicVector3D< Type >::Ref www() &
Definition Vector4D.hpp:572
constexpr BasicVector3D< Type >::ConstRef yyy() const &
Definition Vector4D.hpp:563
friend bool check_if_equal(BasicRef input, BasicRef< U > near_to, OT tolerance=OT{0.0002})
Definition Vector4D.hpp:321
constexpr BasicVector2D< Type >::Ref zx() &
Definition Vector4D.hpp:540
friend constexpr BasicVector4D< RType > operator*(BasicRef left, BasicRef< U > right)
Definition Vector4D.hpp:134
friend void CHECK_IF_ZERO(BasicRef input, OT tolerance=OT{0.0002})
Definition Vector4D.hpp:422
constexpr BasicVector3D< Type > xxx() &&
Definition Vector4D.hpp:561
constexpr BasicVector3D< Type >::Ref zzz() &
Definition Vector4D.hpp:568
friend constexpr bool approximately_equal_to(const BasicVector4D &value_to_test, const BasicVector4D< U > &value_it_should_be, OT tolerance=OT{0.0002})
Definition Vector4D.hpp:629
constexpr BasicVector2D< Type > xz() &&
Definition Vector4D.hpp:529
constexpr value_type norm() const
Definition Vector4D.hpp:501
friend constexpr BasicVector4D< RType > operator+(BasicRef left, BasicRef< U > right)
Definition Vector4D.hpp:94
constexpr BasicRef(const BasicRef &)=default
friend constexpr bool approximately_equal_to(const BasicVector4D &value_to_test, BasicRef< U > value_it_should_be, OT tolerance=OT{0.0002})
Definition Vector4D.hpp:649
friend constexpr BasicVector4D< Type > lerp(const BasicVector4D &input_lower_bound, BasicRef< U > input_upper_bound, float percentage_zero_to_one)
Definition Vector4D.hpp:902
static constexpr BasicVector4D< Type > zero()
Definition Vector4D.hpp:497
constexpr BasicVector2D< Type >::ConstRef yx() const &
Definition Vector4D.hpp:531
friend constexpr bool approximately_equal_to(BasicRef value_to_test, const BasicVector4D< U > &value_it_should_be, OT tolerance=OT{0.0002})
Definition Vector4D.hpp:207
friend BasicVector4D< RType > fract(BasicRef input)
Definition Vector4D.hpp:260
constexpr value_type magnitudeSquared() const
Definition Vector4D.hpp:503
RType value_type
The underlying implementation type.
Definition Vector4D.hpp:44
BasicRef< const Type > ConstRef
Definition Vector4D.hpp:429
constexpr BasicVector2D< Type >::Ref xy() &
Definition Vector4D.hpp:524
static constexpr BasicVector4D< Type > unit_w()
Definition Vector4D.hpp:495
friend constexpr BasicVector4D< Type > abs(const BasicVector4D< Type > &input)
Definition Vector4D.hpp:857
friend constexpr BasicVector4D< RType > saturate(BasicRef input, RType lower_bound, RType upper_bound)
Definition Vector4D.hpp:270
friend constexpr BasicVector4D< RType > normalized(BasicRef input)
Definition Vector4D.hpp:250
friend constexpr Type dot(const BasicVector4D &left, BasicRef< U > right)
Definition Vector4D.hpp:799
constexpr BasicVector3D< Type >::Ref zxy() &
Definition Vector4D.hpp:552
friend bool check_if_equal(BasicRef input, const BasicVector4D< U > &near_to, OT tolerance=OT{0.0002})
Definition Vector4D.hpp:342
friend constexpr Type dot(const BasicVector4D &left, const BasicVector4D< U > &right)
Definition Vector4D.hpp:781
friend constexpr BasicVector4D< Type > normalized(const BasicVector4D< Type > &input)
Definition Vector4D.hpp:846
constexpr BasicVector3D< Type >::Ref zyx() &
Definition Vector4D.hpp:556
constexpr BasicVector3D< Type > yyy() &&
Definition Vector4D.hpp:565
friend constexpr BasicVector4D< RType > abs(BasicRef input)
Definition Vector4D.hpp:255
constexpr BasicVector3D< Type >::Ref yyy() &
Definition Vector4D.hpp:564
friend constexpr BasicVector4D< RType > operator-(BasicRef left, BasicRef< U > right)
Definition Vector4D.hpp:114
friend constexpr Type accumulate(const BasicVector4D< Type > &input)
Definition Vector4D.hpp:763
friend constexpr BasicVector4D< RType > mix(BasicRef input_lower_bound, BasicRef< U > input_upper_bound, float percentage_zero_to_one)
Definition Vector4D.hpp:298
constexpr BasicVector3D< Type >::Ref xxx() &
Definition Vector4D.hpp:560
friend constexpr RType dot(BasicRef left, const BasicVector4D< U > &right)
Definition Vector4D.hpp:231
friend constexpr bool operator==(BasicRef left, BasicRef< U > right)
Definition Vector4D.hpp:80
friend constexpr RType dot_normalized(BasicRef left, BasicRef< U > right)
Definition Vector4D.hpp:238
friend void CHECK_IF_NOT_EQUAL(BasicRef input, const BasicVector4D< U > &near_to, OT tolerance=OT{0.0002})
Definition Vector4D.hpp:414
friend void CHECK_IF_NOT_EQUAL(BasicRef input, BasicRef< U > near_to, OT tolerance=OT{0.0002})
Definition Vector4D.hpp:405
BasicRef< Type > Ref
Definition Vector4D.hpp:428
constexpr BasicVector2D< Type >::ConstRef yz() const &
Definition Vector4D.hpp:535
constexpr BasicVector3D< Type >::ConstRef www() const &
Definition Vector4D.hpp:571
constexpr BasicVector2D< Type >::ConstRef xy() const &
Definition Vector4D.hpp:523
constexpr BasicVector4D(const BasicVector2D< Type > &first2, const BasicVector2D< Type > &second2)
Definition Vector4D.hpp:451
constexpr BasicVector3D< Type >::Ref xyz() &
Definition Vector4D.hpp:544
friend constexpr RType dot_normalized(BasicRef left, const BasicVector4D< U > &right)
Definition Vector4D.hpp:245
friend std::string format(const BasicVector4D &input)
Definition Vector4D.hpp:927
friend constexpr Type dot_normalized(const BasicVector4D &left, const BasicVector4D< U > &right)
Definition Vector4D.hpp:817
constexpr BasicVector2D< Type >::ConstRef xz() const &
Definition Vector4D.hpp:527
constexpr BasicVector4D< Type > normalized() const
Definition Vector4D.hpp:506
friend constexpr Type dot_normalized(const BasicVector4D &left, BasicRef< U > right)
Definition Vector4D.hpp:835
friend constexpr RType dot(BasicRef left, BasicRef< U > right)
Definition Vector4D.hpp:224
constexpr BasicVector4D(const BasicVector3D< Type > &first3, const Type &w_in=0)
Definition Vector4D.hpp:443
constexpr BasicVector3D< Type > xzy() &&
Definition Vector4D.hpp:549
constexpr BasicVector2D< Type > yx() &&
Definition Vector4D.hpp:533
static constexpr BasicVector4D< Type > unit_y()
Definition Vector4D.hpp:493
friend constexpr BasicVector4D< Type > mix(const BasicVector4D &input_lower_bound, const BasicVector4D< U > &input_upper_bound, float percentage_zero_to_one)
Definition Vector4D.hpp:911
constexpr BasicVector3D< Type > zyx() &&
Definition Vector4D.hpp:557
constexpr BasicVector2D< Type > yz() &&
Definition Vector4D.hpp:537
constexpr BasicVector2D< Type >::ConstRef zx() const &
Definition Vector4D.hpp:539
constexpr BasicVector4D(const Type &x_in, const BasicVector3D< Type > &last3)
Definition Vector4D.hpp:459
constexpr BasicVector4D(const Type &x_in, const Type &y_in=0, const Type &z_in=0, const Type &w_in=0)
Definition Vector4D.hpp:435
constexpr BasicVector3D< Type > www() &&
Definition Vector4D.hpp:573
constexpr BasicVector3D< Type >::ConstRef zyx() const &
Definition Vector4D.hpp:555
friend bool check_if_not_equal(BasicRef input, const BasicVector4D< U > &near_to, OT tolerance=OT{0.0002})
Definition Vector4D.hpp:384
friend constexpr BasicVector4D< RType > mix(BasicRef input_lower_bound, BasicVector4D< U > &input_upper_bound, float percentage_zero_to_one)
Definition Vector4D.hpp:307
friend constexpr BasicVector4D< RType > lerp(BasicRef input_lower_bound, BasicRef< U > input_upper_bound, float percentage_zero_to_one)
Definition Vector4D.hpp:280
constexpr BasicVector3D< Type >::ConstRef zzz() const &
Definition Vector4D.hpp:567
Type value_type
The underlying implementation type.
Definition Vector4D.hpp:29
friend constexpr BasicVector4D< Type > lerp(const BasicVector4D &input_lower_bound, const BasicVector4D< U > &input_upper_bound, float percentage_zero_to_one)
Definition Vector4D.hpp:893
constexpr BasicVector2D< Type >::Ref yx() &
Definition Vector4D.hpp:532
friend constexpr BasicVector4D< Type > mix(const BasicVector4D &input_lower_bound, BasicRef< U > input_upper_bound, float percentage_zero_to_one)
Definition Vector4D.hpp:920
friend constexpr RType accumulate(BasicRef input)
Definition Vector4D.hpp:217
constexpr BasicVector3D< Type >::Ref xzy() &
Definition Vector4D.hpp:548
bool isInf() const
Definition Vector4D.hpp:517
friend BasicVector4D< Type > fract(const BasicVector4D< Type > &input)
Definition Vector4D.hpp:871
BasicVector4D< double >::ConstRef Vector4DConstRef
BasicVector4D< double >::Ref Vector4DdRef
BasicVector4D< float >::Ref Vector4DfRef
BasicVector4D< float >::ConstRef Vector4DfConstRef
BasicVector4D< long double >::Ref Vector4DlRef
BasicVector4D< double >::Ref Vector4DRef
BasicVector4D< long double >::ConstRef Vector4DlConstRef
BasicVector4D< double >::ConstRef Vector4DdConstRef
friend bool check_if_equal(const BasicVector4D &input, BasicRef< U > near_to, OT tolerance=OT{0.0002})
Definition Vector4D.hpp:981
friend bool check_if_not_equal(const BasicVector4D &input, const BasicVector4D< U > &near_to, OT tolerance=OT{0.0002})
friend bool check_if_not_equal(const BasicVector4D &input, BasicRef< U > near_to, OT tolerance=OT{0.0002})
friend bool check_if_equal(const BasicVector4D &input, const BasicVector4D< U > &near_to, OT tolerance=OT{0.0002})
Definition Vector4D.hpp:952
friend constexpr BasicVector4D< Type > operator-(const BasicVector4D &left, const BasicVector4D< U > &right)
Definition Vector4D.hpp:688
friend constexpr BasicVector4D< Type > operator/(const BasicVector4D &left, const BasicVector4D< U > &right)
Definition Vector4D.hpp:730
friend constexpr BasicVector4D< Type > operator*(const BasicVector4D &left, const BasicVector4D< U > &right)
Definition Vector4D.hpp:702
friend constexpr BasicVector4D< Type > operator+(const BasicVector4D &left, const BasicVector4D< U > &right)
Definition Vector4D.hpp:674
Definition Angle.hpp:16
constexpr const Type & saturate(const Type &value, const Type &lower_bound, const Type &upper_bound)
Definition Functions.hpp:94