MathLib
Loading...
Searching...
No Matches
Vector3D.hpp
Go to the documentation of this file.
1#pragma once
2
5#include <Math/Concepts.hpp>
6#include <concepts>
7#include <tuple>
8#include <cmath>
9
17namespace Math
18{
19
24template <class Type>
26{
30 using value_type = Type;
32
39 template <class RType>
40 struct BasicRef
41 {
45 using value_type = RType;
47
48 constexpr BasicRef(RType &x_in, RType &y_in, RType &z_in) : x{x_in}, y{y_in}, z{z_in} { }
49 constexpr BasicRef(const BasicRef &) = default;
50 constexpr BasicRef(const BasicVector3D<RType> &other) : x{other.x}, y{other.y}, z{other.z} { }
51
52 constexpr BasicRef &operator =(BasicRef input)
53 {
54 x = input.x;
55 y = input.y;
56 z = input.z;
57 return *this;
58 }
59
60 constexpr BasicRef &operator =(const BasicVector3D<RType> &input)
61 {
62 x = input.x;
63 y = input.y;
64 z = input.z;
65 return *this;
66 }
67
68 constexpr operator BasicVector3D<RType>() const { return { x, y, z }; }
69
70 constexpr operator std::tuple<RType, RType, RType>() const { return std::make_tuple( x, y, z ); }
71
72 RType &x;
73 RType &y;
74 RType &z;
75
76 template <class U>
78 friend constexpr bool operator ==(BasicRef left, BasicRef<U> right)
79 {
80 return approximately_equal_to( left, right );
81 }
82
83 template <class U>
85 friend constexpr bool operator ==(BasicRef left, const BasicVector3D<U> &right)
86 {
87 return approximately_equal_to( left, right );
88 }
89
90 template <class U>
93 {
94 return { left.x + right.x, left.y + right.y, left.z + right.z };
95 }
96
97 template <class U>
99 friend constexpr BasicVector3D<RType> operator +(BasicRef left, const BasicVector3D<U> &right)
100 {
101 return { left.x + right.x, left.y + right.y, left.z + right.z };
102 }
103
104 template <class U>
107 {
108 return { left.x - right.x, left.y - right.y, left.z - right.z };
109 }
110
111 template <class U>
113 friend constexpr BasicVector3D<RType> operator -(BasicRef left, const BasicVector3D<U> &right)
114 {
115 return { left.x - right.x, left.y - right.y, left.z - right.z };
116 }
117
118 template <class U>
121 {
122 return { left.x * right.x, left.y * right.y, left.z * right.z };
123 }
124
125 template <class U>
127 friend constexpr BasicVector3D<RType> operator *(BasicRef left, const BasicVector3D<U> &right)
128 {
129 return { left.x * right.x, left.y * right.y, left.z * right.z };
130 }
131
132 template <class U>
134 friend constexpr BasicVector3D<RType> operator *(BasicRef left, const U &scalar)
135 {
136 return { left.x * scalar, left.y * scalar, left.z * scalar };
137 }
138
139 template <class U>
141 friend constexpr BasicVector3D<RType> operator *(const U &scalar, BasicRef right)
142 {
143 return { scalar * right.x, scalar * right.y, scalar * right.z };
144 }
145
146 template <class U>
149 {
150 return { left.x / right.x, left.y / right.y, left.z / right.z };
151 }
152
153 template <class U>
155 friend constexpr BasicVector3D<RType> operator /(BasicRef left, const BasicVector3D<U> &right)
156 {
157 return { left.x / right.x, left.y / right.y, left.z / right.z };
158 }
159
160 template <class U>
162 friend constexpr BasicVector3D<RType> operator /(BasicRef left, const U &scalar)
163 {
164 return { left.x / scalar, left.y / scalar, left.z / scalar };
165 }
166
167 template <class U, std::floating_point OT = float>
169 friend constexpr bool approximately_equal_to(BasicRef value_to_test,
170 BasicRef<U> value_it_should_be,
171 OT tolerance = OT{0.0002})
172 {
173 return approximately_equal_to(value_to_test.x, value_it_should_be.x, tolerance) &&
174 approximately_equal_to(value_to_test.y, value_it_should_be.y, tolerance) &&
175 approximately_equal_to(value_to_test.z, value_it_should_be.z, tolerance);
176 }
177
178 template <class U, std::floating_point OT = float>
180 friend constexpr bool approximately_equal_to( BasicRef value_to_test,
181 const BasicVector3D<U> &value_it_should_be,
182 OT tolerance = OT{0.0002})
183 {
184 return approximately_equal_to(value_to_test.x, value_it_should_be.x, tolerance) &&
185 approximately_equal_to(value_to_test.y, value_it_should_be.y, tolerance) &&
186 approximately_equal_to(value_to_test.z, value_it_should_be.z, tolerance);
187 }
188
189 friend constexpr RType accumulate(BasicRef input)
190 {
191 return input.x + input.y + input.z;
192 }
193
194 template <class U>
196 friend constexpr RType dot(BasicRef left, BasicRef<U> right)
197 {
198 return (left.x * right.x) + (left.y * right.y) + (left.z * right.z);
199 }
200
201 template <class U>
203 friend constexpr RType dot(BasicRef left, const BasicVector3D<U> &right)
204 {
205 return (left.x * right.x) + (left.y * right.y) + (left.z * right.z);
206 }
207
208 template <class U>
210 friend constexpr RType dot_normalized(BasicRef left, BasicRef<U> right)
211 {
212 return dot(left, right) / (left.magnitude() * right.magnitude());
213 }
214
215 template <class U>
217 friend constexpr RType dot_normalized(BasicRef left, const BasicVector3D<U> &right)
218 {
219 return dot(left, right) / (left.magnitude() * right.magnitude());
220 }
221
222 template <class U>
224 friend constexpr BasicVector3D<RType> cross(BasicRef left, BasicRef<U> right)
225 {
226 return cross( BasicVector3D<RType>(left), BasicVector3D<RType>(right) );
227 }
228
230 {
231 return BasicVector3D<RType>( input ).normalized();
232 }
233
234 friend constexpr BasicVector3D<RType> abs(BasicRef input)
235 {
236 return { std::abs(input.x), std::abs(input.y), std::abs(input.z) };
237 }
238
239 friend constexpr BasicVector3D<RType> fract(BasicRef input)
240 {
241 RType dummy;
242
243 return { std::modf(input.x, &dummy),
244 std::modf(input.y, &dummy),
245 std::modf(input.z, &dummy) };
246 }
247
248 friend constexpr BasicVector3D<RType> saturate(BasicRef input, RType lower_bound, RType upper_bound)
249 {
250 return { Math::saturate(input.x, lower_bound, upper_bound),
251 Math::saturate(input.y, lower_bound, upper_bound),
252 Math::saturate(input.z, lower_bound, upper_bound) };
253 }
254
255 template <class U>
257 friend constexpr BasicVector3D<RType> lerp(BasicRef input_lower_bound,
258 BasicRef<U> input_upper_bound,
259 float percentage_zero_to_one)
260 {
261 return (input_upper_bound - input_lower_bound) * percentage_zero_to_one + input_lower_bound;
262 }
263
264 template <class U>
266 friend constexpr BasicVector3D<RType> lerp( BasicRef input_lower_bound,
267 const BasicVector3D<U> &input_upper_bound,
268 float percentage_zero_to_one)
269 {
270 return (input_upper_bound - input_lower_bound) * percentage_zero_to_one + input_lower_bound;
271 }
272
273 template <class U>
275 friend constexpr BasicVector3D<RType> mix(BasicRef input_lower_bound,
276 BasicRef<U> input_upper_bound,
277 float percentage_zero_to_one)
278 {
279 return lerp( input_lower_bound, input_upper_bound, percentage_zero_to_one );
280 }
281
282 template <class U>
284 friend constexpr BasicVector3D<RType> mix( BasicRef input_lower_bound,
285 const BasicVector3D<U> &input_upper_bound,
286 float percentage_zero_to_one)
287 {
288 return lerp( input_lower_bound, input_upper_bound, percentage_zero_to_one );
289 }
290
291 friend std::string format(BasicRef input)
292 {
293 return std::format("[x: {:.6}, y: {:.6}, z: {:.6}]", input.x, input.y, input.z);
294 }
295
296 template <class U, std::floating_point OT = float>
298 friend bool check_if_equal(BasicRef input,
299 BasicRef<U> near_to,
300 OT tolerance = OT{0.0002})
301 {
302 if (!approximately_equal_to(input, near_to, tolerance))
303 {
304 auto diff{ near_to - input };
305
306 std::cout << std::format("input: {} is not equal to near_to: {} within tolerance: {}. Difference is {} .",
307 format(input),
308 format(near_to),
309 tolerance,
310 format(near_to - input))
311 << std::endl;
312 return false;
313 }
314 return true;
315 }
316
317 template <class U, std::floating_point OT = float>
319 friend bool check_if_equal( BasicRef input,
320 const BasicVector3D<U> &near_to,
321 OT tolerance = OT{0.0002})
322 {
323 if (!approximately_equal_to(input, near_to, tolerance))
324 {
325 auto diff{ near_to - input };
326
327 std::cout << std::format("input: {} is not equal to near_to: {} within tolerance: {}. Difference is {} .",
328 format(input),
329 format(near_to),
330 tolerance,
331 format(near_to - input))
332 << std::endl;
333 return false;
334 }
335 return true;
336 }
337
338 template <class U, std::floating_point OT = float>
340 friend bool check_if_not_equal(BasicRef input,
341 BasicRef near_to,
342 OT tolerance = OT{0.0002})
343 {
344 if (approximately_equal_to(input, near_to, tolerance))
345 {
346 auto diff{ near_to - input };
347
348 std::cout << std::format("input: {} is equal to near_to: {} within tolerance: {}. Difference is {} .",
349 format(input),
350 format(near_to),
351 tolerance,
352 format(near_to - input))
353 << std::endl;
354 return false;
355 }
356 return true;
357 }
358
359 template <class U, std::floating_point OT = float>
361 friend bool check_if_not_equal( BasicRef input,
362 const BasicVector3D<U> &near_to,
363 OT tolerance = OT{0.0002})
364 {
365 if (approximately_equal_to(input, near_to, tolerance))
366 {
367 auto diff{ near_to - input };
368
369 std::cout << std::format("input: {} is equal to near_to: {} within tolerance: {}. Difference is {} .",
370 format(input),
371 format(near_to),
372 tolerance,
373 format(near_to - input))
374 << std::endl;
375 return false;
376 }
377 return true;
378 }
379
380 template <class U, std::floating_point OT = float>
382 friend void CHECK_IF_EQUAL(BasicRef input,
383 BasicRef<U> near_to,
384 OT tolerance = OT{0.0002})
385 {
386 assert( check_if_equal(input, near_to, tolerance) );
387 }
388
389 template <class U, std::floating_point OT = float>
391 friend void CHECK_IF_EQUAL( BasicRef input,
392 const BasicVector3D<U> &near_to,
393 OT tolerance = OT{0.0002})
394 {
395 assert( check_if_equal(input, near_to, tolerance) );
396 }
397
398 template <class U, std::floating_point OT = float>
400 friend void CHECK_IF_NOT_EQUAL(BasicRef input,
401 BasicRef<U> near_to,
402 OT tolerance = OT{0.0002})
403 {
404 assert( check_if_not_equal(input, near_to, tolerance) );
405 }
406
407 template <class U, std::floating_point OT = float>
409 friend void CHECK_IF_NOT_EQUAL( BasicRef input,
410 const BasicVector3D<U> &near_to,
411 OT tolerance = OT{0.0002})
412 {
413 assert( check_if_not_equal(input, near_to, tolerance) );
414 }
415
416 template <std::floating_point OT = float>
417 friend void CHECK_IF_ZERO(BasicRef input, OT tolerance = OT{0.0002})
418 {
419 assert( check_if_equal(input, BasicVector3D<RType>::zero(), tolerance));
420 }
421 };
422
425
429 constexpr BasicVector3D() = default;
430 constexpr BasicVector3D(const Type &x_in, const Type &y_in = 0, const Type &z_in = 0)
431 :
432 x{x_in},
433 y{y_in},
434 z{z_in}
435 {
436 }
437 constexpr BasicVector3D(const BasicVector2D<Type> &other, Type z_in = 0)
438 :
439 x{other.x},
440 y{other.y},
441 z{z_in}
442 {
443 }
444 constexpr BasicVector3D(Type x_in, const BasicVector2D<Type> &other)
445 :
446 x{x_in},
447 y{other.x},
448 z{other.y}
449 {
450 }
451 constexpr BasicVector3D(const std::tuple<Type, Type, Type> &init_value)
452 :
453 x{ std::get<0>(init_value) },
454 y{ std::get<1>(init_value) },
455 z{ std::get<2>(init_value) }
456 {
457 }
459
463 constexpr BasicVector3D<Type> &operator =(const BasicVector3D &other) = default;
465 {
466 x = other.x;
467 y = other.y;
468 return *this;
469 }
471
475 constexpr operator std::tuple<Type, Type, Type>() const { return std::make_tuple( x, y, z ); }
477
481 constexpr static BasicVector3D<Type> unit_x() { return { Type{1}, Type{0}, Type{0} }; }
482 constexpr static BasicVector3D<Type> unit_y() { return { Type{0}, Type{1}, Type{0} }; }
483 constexpr static BasicVector3D<Type> unit_z() { return { Type{0}, Type{0}, Type{1} }; }
484
485 constexpr static BasicVector3D<Type> zero() { return { }; }
487
488 constexpr value_type normSquared() const { return (x * x) + (y * y) + (z * z); }
489 constexpr value_type norm() const { return std::sqrt( normSquared() ); }
490
491 constexpr value_type magnitudeSquared() const { return normSquared(); }
492 constexpr value_type magnitude() const { return norm(); }
493
495 {
496 auto n = magnitude();
497
498 return { x / n, y / n, z / n };
499 }
500
504 bool isNaN() const { return std::isnan(x) || std::isnan(y) || std::isnan(z); }
505 bool isInf() const { return std::isinf(x) || std::isinf(y) || std::isinf(z); }
507
511 constexpr BasicVector2D<Type>::ConstRef xy() const & { return { x, y }; }
512 constexpr BasicVector2D<Type>::Ref xy() & { return { x, y }; }
513 constexpr BasicVector2D<Type> xy() && { return { x, y }; }
514
515 constexpr BasicVector2D<Type>::ConstRef xz() const & { return { x, z }; }
516 constexpr BasicVector2D<Type>::Ref xz() & { return { x, z }; }
517 constexpr BasicVector2D<Type> xz() && { return { x, z }; }
518
519 constexpr BasicVector2D<Type>::ConstRef yx() const & { return { y, x }; }
520 constexpr BasicVector2D<Type>::Ref yx() & { return { y, x }; }
521 constexpr BasicVector2D<Type> yx() && { return { y, x }; }
522
523 constexpr BasicVector2D<Type>::ConstRef yz() const & { return { y, z }; }
524 constexpr BasicVector2D<Type>::Ref yz() & { return { y, z }; }
525 constexpr BasicVector2D<Type> yz() && { return { y, z }; }
526
527 constexpr BasicVector2D<Type>::ConstRef zx() const & { return { z, x }; }
528 constexpr BasicVector2D<Type>::Ref zx() & { return { z, x }; }
529 constexpr BasicVector2D<Type> zx() && { return { z, x }; }
530
531 constexpr ConstRef xyz() const & { return { x, y, z }; }
532 constexpr Ref xyz() & { return { x, y, z }; }
533 constexpr BasicVector3D<Type> xyz() && { return { x, y, z }; }
534
535 constexpr ConstRef xzy() const & { return { x, z, y }; }
536 constexpr Ref xzy() & { return { x, z, y }; }
537 constexpr BasicVector3D<Type> xzy() && { return { x, z, y }; }
538
539 constexpr ConstRef zxy() const & { return { z, x, y }; }
540 constexpr Ref zxy() & { return { z, x, y }; }
541 constexpr BasicVector3D<Type> zxy() && { return { z, x, y }; }
542
543 constexpr ConstRef zyx() const & { return { z, y, x }; }
544 constexpr Ref zyx() & { return { z, y, x }; }
545 constexpr BasicVector3D<Type> zyx() && { return { z, y, x }; }
547
555
556private:
557
570 template <class U>
572 friend constexpr bool operator ==(const BasicVector3D &left, const BasicVector3D<U> &right)
573 {
574 return approximately_equal_to(left, right);
575 }
576
583 template <class U>
585 friend constexpr bool operator ==(const BasicVector3D &left, BasicRef<U> right)
586 {
587 return approximately_equal_to(left, right);
588 }
589
598 template <class U, std::floating_point OT = float>
600 friend constexpr bool approximately_equal_to(const BasicVector3D &value_to_test,
601 const BasicVector3D<U> &value_it_should_be,
602 OT tolerance = OT{0.0002})
603 {
604 return approximately_equal_to(value_to_test.x, value_it_should_be.x, tolerance) &&
605 approximately_equal_to(value_to_test.y, value_it_should_be.y, tolerance) &&
606 approximately_equal_to(value_to_test.z, value_it_should_be.z, tolerance);
607 }
608
617 template <class U, std::floating_point OT = float>
619 friend constexpr bool approximately_equal_to(const BasicVector3D &value_to_test,
620 BasicRef<U> value_it_should_be,
621 OT tolerance = OT{0.0002})
622 {
623 return approximately_equal_to(value_to_test.x, value_it_should_be.x, tolerance) &&
624 approximately_equal_to(value_to_test.y, value_it_should_be.y, tolerance) &&
625 approximately_equal_to(value_to_test.z, value_it_should_be.z, tolerance);
626 }
628
641 template <class U>
643 friend constexpr BasicVector3D<Type> operator +(const BasicVector3D &left, const BasicVector3D<U> &right)
644 {
645 return { left.x + right.x, left.y + right.y, left.z + right.z };
646 }
647
648 template <class U>
650 friend constexpr BasicVector3D<Type> operator +(const BasicVector3D &left, BasicRef<U> right)
651 {
652 return { left.x + right.x, left.y + right.y, left.z + right.z };
653 }
654
655 template <class U>
657 friend constexpr BasicVector3D<Type> operator -(const BasicVector3D &left, const BasicVector3D<U> &right)
658 {
659 return { left.x - right.x, left.y - right.y, left.z - right.z };
660 }
661
662 template <class U>
664 friend constexpr BasicVector3D<Type> operator -(const BasicVector3D &left, BasicRef<U> right)
665 {
666 return { left.x - right.x, left.y - right.y, left.z - right.z };
667 }
668
669 template <class U>
671 friend constexpr BasicVector3D<Type> operator *(const BasicVector3D &left, const BasicVector3D<U> &right)
672 {
673 return { left.x * right.x, left.y * right.y, left.z * right.z };
674 }
675
676 template <class U>
678 friend constexpr BasicVector3D<Type> operator *(const BasicVector3D &left, const Type &right)
679 {
680 return { left.x * right, left.y * right, left.z * right };
681 }
682
683 template <class U>
685 friend constexpr BasicVector3D<Type> operator *(const BasicVector3D &left, const U &scalar)
686 {
687 return { left.x * scalar, left.y * scalar, left.z * scalar };
688 }
689
690 template <class U>
692 friend constexpr BasicVector3D<Type> operator *(const U &scalar, const BasicVector3D &right)
693 {
694 return { scalar * right.x, scalar * right.y };
695 }
696
697 template <class U>
699 friend constexpr BasicVector3D<Type> operator /(const BasicVector3D &left, const BasicVector3D<U> &right)
700 {
701 return { left.x / right.x, left.y / right.y, left.z / right.z };
702 }
703
704 template <class U>
706 friend constexpr BasicVector3D<Type> operator /(const BasicVector3D &left, BasicRef<U> right)
707 {
708 return { left.x / right.x, left.y / right.y, left.z / right.z };
709 }
710
711 friend constexpr BasicVector3D<Type> operator /(const BasicVector3D &left, const Type &right)
712 {
713 return { left.x / right, left.y / right, left.z / right };
714 }
717
730 friend constexpr Type accumulate(const BasicVector3D<Type> &input)
731 {
732 return input.x + input.y + input.z;
733 }
734
746 template <class U>
748 friend constexpr Type dot(const BasicVector3D &left, const BasicVector3D<U> &right)
749 {
750 return (left.x * right.x) + (left.y * right.y) + (left.z * right.z);
751 }
752
764 template <class U>
766 friend constexpr Type dot(const BasicVector3D &left, BasicRef<U> right)
767 {
768 return (left.x * right.x) + (left.y * right.y) + (left.z * right.z);
769 }
770
782 template <class U>
784 friend constexpr Type dot_normalized(const BasicVector3D &left, const BasicVector3D<U> &right)
785 {
786 return dot(left, right) / (left.magnitude() * right.magnitude());
787 }
788
800 template <class U>
802 friend constexpr Type dot_normalized(const BasicVector3D &left, BasicRef<U> right)
803 {
804 return dot(left, right) / (left.magnitude() * right.magnitude());
805 }
806
814 {
815 return input.normalized();
816 }
817
825 template <class U>
827 friend constexpr BasicVector3D<Type> cross(const BasicVector3D &left, const BasicVector3D<U> &right)
828 {
829 return { cross( left.yz(), right.yz() ),
830 cross( left.zx(), right.zx() ),
831 cross( left.xy(), right.xy() ) };
832 }
833
841 template <class U>
843 friend constexpr BasicVector3D<Type> cross(const BasicVector3D &left, BasicRef<U> right)
844 {
845 return { cross( left.yz(), right.yz() ),
846 cross( left.zx(), right.zx() ),
847 cross( left.xy(), right.xy() ) };
848 }
849
856 friend constexpr BasicVector3D<Type> abs(const BasicVector3D<Type> &input)
857 {
858 return { std::abs(input.x), std::abs(input.y), std::abs(input.z) };
859 }
860
867 friend constexpr BasicVector3D<Type> fract(const BasicVector3D<Type> &input)
868 {
869 Type dummy;
870
871 return { std::modf(input.x, &dummy), std::modf(input.y, &dummy), std::modf(input.z, &dummy) };
872 }
873
874 friend constexpr BasicVector3D<Type> saturate(const BasicVector3D<Type> &input,
875 Type lower_bound,
876 Type upper_bound)
877 {
878 return { Math::saturate(input.x, lower_bound, upper_bound),
879 Math::saturate(input.y, lower_bound, upper_bound),
880 Math::saturate(input.z, lower_bound, upper_bound) };
881 }
882
883 template <class U>
885 friend constexpr BasicVector3D<Type> lerp(const BasicVector3D &input_lower_bound,
886 const BasicVector3D<U> &input_upper_bound,
887 float percentage_zero_to_one)
888 {
889 return (input_upper_bound - input_lower_bound) * percentage_zero_to_one + input_lower_bound;
890 }
891
892 template <class U>
894 friend constexpr BasicVector3D<Type> lerp(const BasicVector3D &input_lower_bound,
895 BasicRef<U> input_upper_bound,
896 float percentage_zero_to_one)
897 {
898 return (input_upper_bound - input_lower_bound) * percentage_zero_to_one + input_lower_bound;
899 }
900
901 template <class U>
903 friend constexpr BasicVector3D<Type> mix(const BasicVector3D &input_lower_bound,
904 const BasicVector3D<U> &input_upper_bound,
905 float percentage_zero_to_one)
906 {
907 return lerp( input_lower_bound, input_upper_bound, percentage_zero_to_one );
908 }
909
910 template <class U>
912 friend constexpr BasicVector3D<Type> mix(const BasicVector3D &input_lower_bound,
913 BasicRef<U> input_upper_bound,
914 float percentage_zero_to_one)
915 {
916 return lerp( input_lower_bound, input_upper_bound, percentage_zero_to_one );
917 }
918
919 friend std::string format(const BasicVector3D<Type> &input)
920 {
921 return std::format("[x: {:.6}, y: {:.6}, z: {:.6}]", input.x, input.y, input.z);
922 }
924
942 template <class U, std::floating_point OT = float>
944 friend bool check_if_equal(const BasicVector3D &input,
945 const BasicVector3D<U> &near_to,
946 OT tolerance = OT{0.0002})
947 {
948 if (!approximately_equal_to(input, near_to, tolerance))
949 {
950 auto diff{ near_to - input };
951
952 std::cout << std::format("input: {} is not equal to near_to: {} within tolerance: {}. Difference is {} .",
953 format(input),
954 format(near_to),
955 tolerance,
956 format(near_to - input))
957 << std::endl;
958 return false;
959 }
960 return true;
961 }
962
971 template <class U, std::floating_point OT = float>
973 friend bool check_if_equal(const BasicVector3D &input,
974 BasicRef<U> near_to,
975 OT tolerance = OT{0.0002})
976 {
977 if (!approximately_equal_to(input, near_to, tolerance))
978 {
979 auto diff{ near_to - input };
980
981 std::cout << std::format("input: {} is not equal to near_to: {} within tolerance: {}. Difference is {} .",
982 format(input),
983 format(near_to),
984 tolerance,
985 format(near_to - input))
986 << std::endl;
987 return false;
988 }
989 return true;
990 }
991
1000 template <class U, std::floating_point OT = float>
1002 friend bool check_if_not_equal(const BasicVector3D &input,
1003 const BasicVector3D<U> &near_to,
1004 OT tolerance = OT{0.0002})
1005 {
1006 if (approximately_equal_to(input, near_to, tolerance))
1007 {
1008 auto diff{ near_to - input };
1009
1010 std::cout << std::format("input: {} is equal to near_to: {} within tolerance: {}. Difference is {} .",
1011 format(input),
1012 format(near_to),
1013 tolerance,
1014 format(near_to - input))
1015 << std::endl;
1016 return false;
1017 }
1018 return true;
1019 }
1020
1029 template <class U, std::floating_point OT = float>
1031 friend bool check_if_not_equal(const BasicVector3D &input,
1032 BasicRef<U> near_to,
1033 OT tolerance = OT{0.0002})
1034 {
1035 if (approximately_equal_to(input, near_to, tolerance))
1036 {
1037 auto diff{ near_to - input };
1038
1039 std::cout << std::format("input: {} is equal to near_to: {} within tolerance: {}. Difference is {} .",
1040 format(input),
1041 format(near_to),
1042 tolerance,
1043 format(near_to - input))
1044 << std::endl;
1045 return false;
1046 }
1047 return true;
1048 }
1051
1069 template <class U, std::floating_point OT = float>
1071 friend void CHECK_IF_EQUAL(const BasicVector3D &input,
1072 const BasicVector3D<U> &near_to,
1073 OT tolerance = OT{0.0002})
1074 {
1075 assert( check_if_equal(input, near_to, tolerance) );
1076 }
1077
1086 template <class U, std::floating_point OT = float>
1088 friend void CHECK_IF_EQUAL(const BasicVector3D &input,
1089 BasicRef<U> near_to,
1090 OT tolerance = OT{0.0002})
1091 {
1092 assert( check_if_equal(input, near_to, tolerance) );
1093 }
1094
1103 template <class U, std::floating_point OT = float>
1105 friend void CHECK_IF_NOT_EQUAL(const BasicVector3D &input,
1106 const BasicVector3D<U> &near_to,
1107 OT tolerance = OT{0.0002})
1108 {
1109 assert( check_if_not_equal(input, near_to, tolerance) );
1110 }
1111
1120 template <class U, std::floating_point OT = float>
1122 friend void CHECK_IF_NOT_EQUAL(const BasicVector3D &input,
1123 BasicRef<U> near_to,
1124 OT tolerance = OT{0.0002})
1125 {
1126 assert( check_if_not_equal(input, near_to, tolerance) );
1127 }
1128
1136 template <std::floating_point OT = float>
1137 friend void CHECK_IF_ZERO(const BasicVector3D<Type> &input, OT tolerance = OT{0.0002})
1138 {
1139 assert( check_if_equal(input, BasicVector3D<Type>::zero(), tolerance));
1140 }
1143};
1144
1161
1167
1168
1186
1187}
friend void CHECK_IF_NOT_EQUAL(const BasicVector3D &input, BasicRef< U > near_to, OT tolerance=OT{0.0002})
friend void CHECK_IF_EQUAL(const BasicVector3D &input, const BasicVector3D< U > &near_to, OT tolerance=OT{0.0002})
friend void CHECK_IF_ZERO(const BasicVector3D< Type > &input, OT tolerance=OT{0.0002})
friend void CHECK_IF_NOT_EQUAL(const BasicVector3D &input, const BasicVector3D< U > &near_to, OT tolerance=OT{0.0002})
friend void CHECK_IF_EQUAL(const BasicVector3D &input, BasicRef< U > near_to, OT tolerance=OT{0.0002})
constexpr value_type normSquared() const
Definition Vector3D.hpp:488
friend constexpr bool operator==(const BasicVector3D &left, const BasicVector3D< U > &right)
Definition Vector3D.hpp:572
friend constexpr bool approximately_equal_to(const BasicVector3D &value_to_test, BasicRef< U > value_it_should_be, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:619
constexpr BasicVector2D< Type > zx() &&
Definition Vector3D.hpp:529
friend constexpr Type dot(const BasicVector3D &left, BasicRef< U > right)
Definition Vector3D.hpp:766
constexpr BasicVector2D< Type >::Ref xz() &
Definition Vector3D.hpp:516
bool isNaN() const
Definition Vector3D.hpp:504
friend std::string format(BasicRef input)
Definition Vector3D.hpp:291
constexpr Ref xyz() &
Definition Vector3D.hpp:532
friend constexpr bool approximately_equal_to(BasicRef value_to_test, BasicRef< U > value_it_should_be, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:169
friend bool check_if_not_equal(BasicRef input, BasicRef near_to, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:340
friend constexpr BasicVector3D< Type > normalized(const BasicVector3D< Type > &input)
Definition Vector3D.hpp:813
constexpr BasicVector3D< Type > xyz() &&
Definition Vector3D.hpp:533
friend void CHECK_IF_EQUAL(BasicRef input, BasicRef< U > near_to, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:382
constexpr BasicVector3D< Type > zxy() &&
Definition Vector3D.hpp:541
constexpr value_type magnitude() const
Definition Vector3D.hpp:492
constexpr BasicRef & operator=(BasicRef input)
Definition Vector3D.hpp:52
friend constexpr BasicVector3D< Type > lerp(const BasicVector3D &input_lower_bound, const BasicVector3D< U > &input_upper_bound, float percentage_zero_to_one)
Definition Vector3D.hpp:885
constexpr BasicVector2D< Type > xy() &&
Definition Vector3D.hpp:513
static constexpr BasicVector3D< Type > unit_x()
Definition Vector3D.hpp:481
friend bool check_if_equal(BasicRef input, const BasicVector3D< U > &near_to, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:319
friend constexpr BasicVector3D< RType > operator*(BasicRef left, BasicRef< U > right)
Definition Vector3D.hpp:120
constexpr BasicVector2D< Type >::Ref yz() &
Definition Vector3D.hpp:524
friend bool check_if_equal(BasicRef input, BasicRef< U > near_to, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:298
constexpr BasicVector2D< Type >::Ref zx() &
Definition Vector3D.hpp:528
friend constexpr RType dot_normalized(BasicRef left, const BasicVector3D< U > &right)
Definition Vector3D.hpp:217
friend constexpr BasicVector3D< Type > mix(const BasicVector3D &input_lower_bound, const BasicVector3D< U > &input_upper_bound, float percentage_zero_to_one)
Definition Vector3D.hpp:903
friend void CHECK_IF_ZERO(BasicRef input, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:417
friend void CHECK_IF_NOT_EQUAL(BasicRef input, const BasicVector3D< U > &near_to, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:409
constexpr BasicVector3D(const std::tuple< Type, Type, Type > &init_value)
Definition Vector3D.hpp:451
friend constexpr bool approximately_equal_to(BasicRef value_to_test, const BasicVector3D< U > &value_it_should_be, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:180
static constexpr BasicVector3D< Type > unit_y()
Definition Vector3D.hpp:482
friend void CHECK_IF_EQUAL(BasicRef input, const BasicVector3D< U > &near_to, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:391
constexpr BasicVector2D< Type > xz() &&
Definition Vector3D.hpp:517
constexpr value_type norm() const
Definition Vector3D.hpp:489
constexpr BasicRef(const BasicRef &)=default
friend constexpr BasicVector3D< Type > cross(const BasicVector3D &left, const BasicVector3D< U > &right)
Definition Vector3D.hpp:827
friend constexpr BasicVector3D< RType > mix(BasicRef input_lower_bound, BasicRef< U > input_upper_bound, float percentage_zero_to_one)
Definition Vector3D.hpp:275
static constexpr BasicVector3D< Type > unit_z()
Definition Vector3D.hpp:483
friend constexpr BasicVector3D< RType > cross(BasicRef left, BasicRef< U > right)
Definition Vector3D.hpp:224
friend constexpr BasicVector3D< RType > operator+(BasicRef left, BasicRef< U > right)
Definition Vector3D.hpp:92
constexpr BasicVector2D< Type >::ConstRef yx() const &
Definition Vector3D.hpp:519
friend constexpr Type dot_normalized(const BasicVector3D &left, BasicRef< U > right)
Definition Vector3D.hpp:802
constexpr ConstRef xyz() const &
Definition Vector3D.hpp:531
friend constexpr BasicVector3D< Type > saturate(const BasicVector3D< Type > &input, Type lower_bound, Type upper_bound)
Definition Vector3D.hpp:874
constexpr value_type magnitudeSquared() const
Definition Vector3D.hpp:491
static constexpr BasicVector3D< Type > zero()
Definition Vector3D.hpp:485
RType value_type
The underlying implementation type.
Definition Vector3D.hpp:45
friend constexpr BasicVector3D< RType > abs(BasicRef input)
Definition Vector3D.hpp:234
BasicRef< const Type > ConstRef
Definition Vector3D.hpp:424
constexpr BasicVector2D< Type >::Ref xy() &
Definition Vector3D.hpp:512
constexpr ConstRef zxy() const &
Definition Vector3D.hpp:539
friend std::string format(const BasicVector3D< Type > &input)
Definition Vector3D.hpp:919
friend constexpr BasicVector3D< RType > lerp(BasicRef input_lower_bound, BasicRef< U > input_upper_bound, float percentage_zero_to_one)
Definition Vector3D.hpp:257
friend constexpr BasicVector3D< RType > saturate(BasicRef input, RType lower_bound, RType upper_bound)
Definition Vector3D.hpp:248
friend constexpr BasicVector3D< RType > normalized(BasicRef input)
Definition Vector3D.hpp:229
friend constexpr BasicVector3D< RType > mix(BasicRef input_lower_bound, const BasicVector3D< U > &input_upper_bound, float percentage_zero_to_one)
Definition Vector3D.hpp:284
constexpr BasicVector3D(Type x_in, const BasicVector2D< Type > &other)
Definition Vector3D.hpp:444
friend constexpr Type dot_normalized(const BasicVector3D &left, const BasicVector3D< U > &right)
Definition Vector3D.hpp:784
constexpr Ref zyx() &
Definition Vector3D.hpp:544
constexpr BasicRef(RType &x_in, RType &y_in, RType &z_in)
Definition Vector3D.hpp:48
constexpr Ref zxy() &
Definition Vector3D.hpp:540
friend constexpr BasicVector3D< Type > abs(const BasicVector3D< Type > &input)
Definition Vector3D.hpp:856
friend constexpr Type accumulate(const BasicVector3D< Type > &input)
Definition Vector3D.hpp:730
friend constexpr bool operator==(BasicRef left, BasicRef< U > right)
Definition Vector3D.hpp:78
friend constexpr RType dot_normalized(BasicRef left, BasicRef< U > right)
Definition Vector3D.hpp:210
constexpr BasicVector3D()=default
constexpr BasicVector3D< Type > normalized() const
Definition Vector3D.hpp:494
friend void CHECK_IF_NOT_EQUAL(BasicRef input, BasicRef< U > near_to, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:400
constexpr BasicVector3D< Type > & operator=(const BasicVector3D &other)=default
BasicRef< Type > Ref
Definition Vector3D.hpp:423
constexpr BasicVector2D< Type >::ConstRef yz() const &
Definition Vector3D.hpp:523
constexpr BasicVector2D< Type >::ConstRef xy() const &
Definition Vector3D.hpp:511
constexpr BasicVector2D< Type >::ConstRef xz() const &
Definition Vector3D.hpp:515
friend constexpr BasicVector3D< RType > lerp(BasicRef input_lower_bound, const BasicVector3D< U > &input_upper_bound, float percentage_zero_to_one)
Definition Vector3D.hpp:266
friend constexpr BasicVector3D< RType > operator-(BasicRef left, BasicRef< U > right)
Definition Vector3D.hpp:106
friend constexpr RType dot(BasicRef left, BasicRef< U > right)
Definition Vector3D.hpp:196
constexpr BasicVector3D< Type > xzy() &&
Definition Vector3D.hpp:537
friend constexpr RType dot(BasicRef left, const BasicVector3D< U > &right)
Definition Vector3D.hpp:203
constexpr BasicVector3D(const BasicVector2D< Type > &other, Type z_in=0)
Definition Vector3D.hpp:437
friend constexpr BasicVector3D< Type > cross(const BasicVector3D &left, BasicRef< U > right)
Definition Vector3D.hpp:843
constexpr BasicVector2D< Type > yx() &&
Definition Vector3D.hpp:521
friend constexpr BasicVector3D< RType > fract(BasicRef input)
Definition Vector3D.hpp:239
constexpr BasicVector3D< Type > zyx() &&
Definition Vector3D.hpp:545
constexpr Ref xzy() &
Definition Vector3D.hpp:536
constexpr BasicVector2D< Type > yz() &&
Definition Vector3D.hpp:525
friend constexpr bool approximately_equal_to(const BasicVector3D &value_to_test, const BasicVector3D< U > &value_it_should_be, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:600
constexpr BasicVector2D< Type >::ConstRef zx() const &
Definition Vector3D.hpp:527
friend constexpr BasicVector3D< RType > operator/(BasicRef left, BasicRef< U > right)
Definition Vector3D.hpp:148
constexpr ConstRef zyx() const &
Definition Vector3D.hpp:543
friend constexpr BasicVector3D< Type > mix(const BasicVector3D &input_lower_bound, BasicRef< U > input_upper_bound, float percentage_zero_to_one)
Definition Vector3D.hpp:912
friend constexpr BasicVector3D< Type > lerp(const BasicVector3D &input_lower_bound, BasicRef< U > input_upper_bound, float percentage_zero_to_one)
Definition Vector3D.hpp:894
friend constexpr Type dot(const BasicVector3D &left, const BasicVector3D< U > &right)
Definition Vector3D.hpp:748
friend bool check_if_not_equal(BasicRef input, const BasicVector3D< U > &near_to, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:361
constexpr BasicRef(const BasicVector3D< RType > &other)
Definition Vector3D.hpp:50
constexpr ConstRef xzy() const &
Definition Vector3D.hpp:535
Type value_type
The underlying implementation type.
Definition Vector3D.hpp:30
constexpr BasicVector2D< Type >::Ref yx() &
Definition Vector3D.hpp:520
friend constexpr BasicVector3D< Type > fract(const BasicVector3D< Type > &input)
Definition Vector3D.hpp:867
friend constexpr RType accumulate(BasicRef input)
Definition Vector3D.hpp:189
bool isInf() const
Definition Vector3D.hpp:505
constexpr BasicVector3D(const Type &x_in, const Type &y_in=0, const Type &z_in=0)
Definition Vector3D.hpp:430
BasicVector3D< float >::Ref Vector3DfRef
BasicVector3D< double >::Ref Vector3DRef
BasicVector3D< long double >::Ref Vector3DlRef
BasicVector3D< double >::ConstRef Vector3DdConstRef
BasicVector3D< float >::ConstRef Vector3DfConstRef
BasicVector3D< double >::Ref Vector3DdRef
BasicVector3D< double >::ConstRef Vector3DConstRef
BasicVector3D< long double >::ConstRef Vector3DlConstRef
friend bool check_if_equal(const BasicVector3D &input, BasicRef< U > near_to, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:973
friend bool check_if_not_equal(const BasicVector3D &input, const BasicVector3D< U > &near_to, OT tolerance=OT{0.0002})
friend bool check_if_equal(const BasicVector3D &input, const BasicVector3D< U > &near_to, OT tolerance=OT{0.0002})
Definition Vector3D.hpp:944
friend bool check_if_not_equal(const BasicVector3D &input, BasicRef< U > near_to, OT tolerance=OT{0.0002})
friend constexpr BasicVector3D< Type > operator+(const BasicVector3D &left, const BasicVector3D< U > &right)
Definition Vector3D.hpp:643
friend constexpr BasicVector3D< Type > operator*(const BasicVector3D &left, const BasicVector3D< U > &right)
Definition Vector3D.hpp:671
friend constexpr BasicVector3D< Type > operator/(const BasicVector3D &left, const BasicVector3D< U > &right)
Definition Vector3D.hpp:699
friend constexpr BasicVector3D< Type > operator-(const BasicVector3D &left, const BasicVector3D< U > &right)
Definition Vector3D.hpp:657
Definition Angle.hpp:16
constexpr const Type & saturate(const Type &value, const Type &lower_bound, const Type &upper_bound)
Definition Functions.hpp:94