33#include <NDEVR/Vector.h>
58 template<
class t_vector_type, u
int01 t_dims,
class t_type>
59 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, t_type>, t_vector_type>::value, t_vector_type>
::type
63 for (
uint01 dim = 0; dim < t_dims; ++dim)
64 sum[dim] = vec_a[dim] + vec_b[dim];
82 template<u
int01 t_dims,
class t_type>
86 for (
uint01 dim = 0; dim < t_dims; ++dim)
87 sum[dim] = scaler_a + vec_b[dim];
105 template<
class t_vector_type,
class t_type>
106 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>
::type
107 operator+(
const t_vector_type& vec_a,
const t_type& scaler_b)
110 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
111 sum[dim] = vec_a[dim] + scaler_b;
114 template<
class t_vector_type,
class t_type>
115 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>
::type
116 operator+(
const t_type& scaler_a,
const t_vector_type& vec_b)
119 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
120 sum[dim] = scaler_a + vec_b[dim];
138 template<u
int01 t_dims,
class t_type>
141 for (
uint01 dim = 0; dim < t_dims; ++dim)
142 vec_a[dim] += vec_b[dim];
160 template<u
int01 t_dims,
class t_type>
163 for (
uint01 dim = 0; dim < t_dims; ++dim)
164 vec_a[dim] += scaler_b;
182 template<
class t_vector_type, u
int01 t_dims,
class t_type>
183 constexpr typename std::enable_if<std::is_base_of<Vector<t_dims, t_type>, t_vector_type>::value, t_vector_type>
::type
187 for (
uint01 dim = 0; dim < t_dims; ++dim)
206 template<u
int01 t_dims,
class t_type>
210 for (
uint01 dim = 0; dim < t_dims; ++dim)
229 template<
class t_vector_type,
class t_type>
230 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>
::type
231 operator-(
const t_vector_type& vec_a,
const t_type& value_b)
234 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
253 template<u
int01 t_dims,
class t_type>
256 for (
uint01 dim = 0; dim < t_dims; ++dim)
257 vec_a[dim] -= vec_b[dim];
275 template<u
int01 t_dims,
class t_type>
278 for (
uint01 dim = 0; dim < t_dims; ++dim)
279 vec_a[dim] -= value_b;
297 template<u
int01 t_dims,
class t_type>
301 for (
uint01 dim = 0; dim < t_dims; ++dim)
302 product[dim] = vec_a[dim] * vec_b[dim];
320 template<
class t_vector_type,
class t_type>
321 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>
::type
322 operator*(
const t_type& value_a,
const t_vector_type& vec_b)
324 t_vector_type product;
325 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
326 product[dim] = value_a * vec_b[dim];
344 template<
class t_vector_type,
class t_type>
345 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>
::type
346 operator*(
const t_vector_type& vec_a,
const t_type& value_b)
348 t_vector_type product;
349 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
350 product[dim] = vec_a[dim] * value_b;
368 template<u
int01 t_dims,
class t_type>
371 for (
uint01 dim = 0; dim < t_dims; ++dim)
372 vec_a[dim] *= vec_b[dim];
390 template<u
int01 t_dims,
class t_type>
393 for (
uint01 dim = 0; dim < t_dims; ++dim)
394 vec_a[dim] *= value_b;
412 template<u
int01 t_dims,
class t_type>
416 for (
uint01 dim = 0; dim < t_dims; ++dim)
417 quotient[dim] = vec_a[dim] / vec_b[dim];
435 template<
class t_vector_type,
class t_type>
436 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>
::type
437 operator/(
const t_type& value_a,
const t_vector_type& vec_b)
439 t_vector_type quotient;
440 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
441 quotient[dim] = value_a / vec_b[dim];
459 template<
class t_vector_type,
class t_type>
460 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value, t_vector_type>
::type
461 operator/(
const t_vector_type& vec_a,
const t_type& value_b)
463 t_vector_type quotient;
464 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); ++dim)
465 quotient[dim] = vec_a[dim] / value_b;
494 template<u
int01 t_dims,
class t_type>
498 for (
uint01 dim = 0; dim < t_dims; ++dim)
499 mod [dim] = std::fmod(vec_a[dim], vec_b[dim]);
502 template<u
int01 t_dims,
class t_type>
503 constexpr Vector<t_dims, t_type>
operator%(
const Vector<t_dims, t_type>& vec_a,
const t_type& value_b)
505 Vector<t_dims, t_type> mod;
506 for (
uint01 dim = 0; dim < t_dims; ++dim)
526 template<u
int01 t_dims,
class t_type>
529 for (
uint01 dim = 0; dim < t_dims; ++dim)
530 vec_a[dim] = vec_a[dim] / vec_b[dim];
549 template<u
int01 t_dims,
class t_type>
552 for (
uint01 dim = 0; dim < t_dims; ++dim)
553 vec_a[dim] = vec_a[dim] / value_b;
557 template<
class t_vector_type,
class t_type>
558 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value,
bool>
::type
559 operator==(
const t_vector_type& v,
const t_type& s)
561 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
568 template<
class t_vector_type,
class t_type>
569 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value,
bool>
::type
570 operator==(
const t_type& s,
const t_vector_type& v)
572 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
579 template<
class t_vector_type>
580 constexpr typename std::enable_if<IsVec<t_vector_type>::value,
bool>
::type
581 operator==(
const t_vector_type& v_a,
const t_vector_type& v_b)
583 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
585 if (v_a[dim] != v_b[dim])
590 template<
class t_type>
591 constexpr typename std::enable_if<!IsVec<t_type>::value,
bool>
::type
592 AreSame(
const t_type& a,
const t_type& b)
596 template<
class t_type>
597 constexpr typename std::enable_if<!IsVec<t_type>::value,
bool>
::type
598 AreSame(
const t_type& a,
const t_type& b,
const t_type& epsilon)
601 ||
::abs(a - b) < epsilon;
604 template<
class t_vector_type>
605 constexpr typename std::enable_if<IsVec<t_vector_type>::value,
bool>
::type
606 AreSame(
const t_vector_type& v_a,
const t_vector_type& v_b)
608 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
610 if (!AreSame(v_a[dim], v_b[dim]))
615 template<
class t_vector_type,
class t_type>
616 constexpr typename std::enable_if<IsVec<t_vector_type>::value,
bool>
::type
617 AreSame(
const t_vector_type& v_a,
const t_vector_type& v_b,
const t_type& epsilon)
620 ||
abs(v_a - v_b) < epsilon;
622 template<
class t_vector_type>
623 constexpr typename std::enable_if<IsVec<t_vector_type>::value,
bool>
::type
624 operator!=(
const t_vector_type& v_a,
const t_vector_type& v_b)
626 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
628 if (v_a[dim] != v_b[dim])
633 template<
class t_vector_type,
class t_type>
634 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value,
bool>
::type
635 operator!=(
const t_vector_type& v,
const t_type& s)
637 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
644 template<
class t_vector_type,
class t_type>
645 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value,
bool>
::type
646 operator!=(
const t_type& s,
const t_vector_type& v)
648 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
670 template<u
int01 vec_1_size, u
int01 vec_2_size,
class t_type>
674 for (
uint01 dim = 0; dim < min_val; ++dim)
676 if (!(v1[dim] >= v2[dim]))
682 template<u
int01 t_dims,
class t_type>
683 constexpr bool operator>=(
const Vector<t_dims, t_type>& v1,
const t_type& s)
685 for (
uint01 dim = 0; dim < t_dims; ++dim)
708 template<u
int01 vec_1_size, u
int01 vec_2_size,
class t_type>
712 for (
uint01 dim = 0; dim < min_val; ++dim)
714 if (!(v1[dim] > v2[dim]))
720 template<u
int01 vec_1_size, u
int01 vec_2_size,
class t_type>
721 constexpr bool operator<(
const Vector<vec_1_size, t_type>& v1,
const Vector<vec_2_size, t_type>& v2)
723 const t_type min_val =
getMin(vec_1_size, vec_2_size);
724 for (
uint01 dim = 0; dim < min_val; ++dim)
726 if (!(v1[dim] < v2[dim]))
731 template<u
int01 vec_1_size, u
int01 vec_2_size,
class t_type>
735 for (
uint01 dim = 0; dim < min_val; ++dim)
737 if (!(v1[dim] <= v2[dim]))
756 template<u
int01 t_dims,
class t_type>
759 for (
uint01 dim = 0; dim < t_dims; ++dim)
761 if (!(v1[dim] >= v2[dim]))
782 template<u
int01 t_dims,
class t_type>
785 for (
uint01 dim = 0; dim < t_dims; dim++)
787 if (!(v1[dim] > v2[dim]))
793 template<u
int01 t_dims,
class t_type>
794 constexpr bool operator<(
const Vector<t_dims, t_type>& v1,
const Vector<t_dims, t_type>& v2)
796 for (
uint01 dim = 0; dim < t_dims; dim++)
798 if (!(v1[dim] < v2[dim]))
804 template<
class t_vector_type,
class t_type>
805 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value,
bool>
::type
806 operator<(
const t_vector_type& v,
const t_type& s)
808 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
815 template<
class t_vector_type,
class t_type>
816 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value,
bool>
::type
817 operator<(
const t_type& s,
const t_vector_type& v)
819 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
826 template<
class t_vector_type,
class t_type>
827 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value,
bool>
::type
828 operator<=(
const t_type& s,
const t_vector_type& v)
830 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
838 template<
class t_vector_type,
class t_type>
839 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value,
bool>
::type
840 operator<=(
const t_vector_type& v,
const t_type& s)
842 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
849 template<
class t_vector_type,
class t_type>
850 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value,
bool>
::type
851 operator>(
const t_vector_type& v,
const t_type& s)
853 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
860 template<
class t_vector_type,
class t_type>
861 constexpr typename std::enable_if<IsVecType<t_vector_type, t_type>::value,
bool>
::type
862 operator>(
const t_type& s,
const t_vector_type& v)
864 for (
uint01 dim = 0; dim < t_vector_type::NumberOfDimensions(); dim++)
872 template<u
int01 t_dims,
class t_type>
875 for (
uint01 dim = 0; dim < t_dims; dim++)
877 if (!(v1[dim] <= v2[dim]))
898 template<
class t_type>
903 template<
class t_type>
904 constexpr t_type
cross(
const Vector<2, t_type>& v1,
const Vector<2, t_type>& v2)
906 return v1[X] * v2[Y] - v1[Y] * v2[X];
908 template<
class t_type>
913 template<
class t_type>
917 cross[X] = ((v1[Y] * v2[Z]) - (v1[Z] * v2[Y]));
918 cross[Y] = ((v1[Z] * v2[X]) - (v1[X] * v2[Z]));
919 cross[Z] = ((v1[X] * v2[Y]) - (v1[Y] * v2[X]));
937 template<u
int01 t_dims,
class t_type>
941 for (
uint01 dim = 0; dim < t_dims; dim++)
943 vec[dim] =
getMax(v1[dim], v2[dim]);
962 template<u
int01 t_dims,
class t_type>
966 for (
uint01 dim = 0; dim < t_dims; dim++)
968 vec[dim] =
getMin(v1[dim], v2[dim]);
987 template<u
int01 t_dims,
class t_type>
990 return (v1[X] * v2[Y]) - (v1[Y] * v2[X]);
1008 template<u
int01 t_dims,
class t_type>
1014 return x_det - y_det + z_det;
1030 template<u
int01 t_dims,
class t_type>
1034 for (
uint01 dim = 0; dim < t_dims; ++dim)
1035 value += v1[dim] * v2[dim];
1053 template<u
int01 t_dims,
class t_type>
1056 t_type magnitude_1 = v1.getMagnitudeSquared();
1057 t_type magnitude_2 = v2.getMagnitudeSquared();
1058 return v2 * v2 * (magnitude_1) == v1 * v1 * magnitude_2;
1076 template<u
int01 t_dims,
class t_type>
1079 return (
abs(left - right) < epsilon);
1086 template<
class t_type>
1087 constexpr typename std::enable_if<!IsVec<t_type>::value, t_type>
::type
1090 return std::abs(value);
1097 template<
class t_type>
1098 constexpr typename std::enable_if<IsVec<t_type>::value, t_type>
::type
1102 for (
uint01 dim = 0; dim < t_type::NumberOfDimensions(); ++dim)
1103 abs_value[dim] =
abs(value[dim]);
1107 template<
class t_to,
class t_from>
1108 constexpr t_to
cast(Vector<1, t_from>& value)
1110 return static_cast<t_to
>(value[0]);
1159 template<u
int01 t_dims,
class t_type>
1163 for (
uint01 dim = 0; dim < t_dims; ++dim)
1164 value[dim] =
abs(vector[dim]);
1180 template<
class t_type>
1183 return ::sqrt(value);
1198 template<u
int01 t_dims,
class t_type>
1202 for (
uint01 dim = 0; dim < t_dims; ++dim)
1204 vec[dim] = std::sqrt(vector[dim]);
1223 template<u
int01 t_dims,
class t_type>
1227 for (
uint01 dim = 0; dim < t_dims; ++dim)
1229 const t_type dn = (v1[dim] - v2[dim]);
1249 template<u
int01 t_dims,
class t_type>
1252 return sqrt(distanceSquared(v1, v2));
1273 template<
class t_distance_type, u
int01 t_dims,
class t_type>
1279 template <u
int01 t_dims,
typename t_type>
1280 constexpr Vector<t_dims, t_type>
clip(
const Vector<t_dims, t_type>& value,
const Vector<t_dims, t_type>& lower_bound,
const Vector<t_dims, t_type>& upper_bound)
1282 Vector<t_dims, t_type> clipped;
1283 for (
uint01 i = 0; i < t_dims; i++)
1285 clipped[i] =
clip(value[i], lower_bound[i], upper_bound[i]);
Provides free functions for vector arithmetic and geometric operations.
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
The primary namespace for the NDEVR SDK.
static constexpr Angle< t_angle_type > & operator-=(Angle< t_angle_type > &angle, const Angle< t_angle_type > &sub)
Subtraction assignment operator for Angles.
@ type
The type identifier string for this model node.
constexpr bool operator!=(const Vector< t_dims, t_type > &vec_a, const Vector< t_dims, t_type > &vec_b)
Inequality operator.
constexpr t_type getMin(const t_type &left, const t_type &right)
Finds the minimum of the given arguments based on the < operator Author: Tyler Parke Date: 2017-11-05...
constexpr t_type getMax(const t_type &left, const t_type &right)
Finds the max of the given arguments using the > operator The only requirement is that t_type have > ...
t_type determinate(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
t_type dot(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
uint16_t uint02
-Defines an alias representing a 2 byte, unsigned integer -Can represent exact integer values 0 throu...
constexpr Angle< t_angle_type > abs(const Angle< t_angle_type > &value)
Changes an input with a negative sign, to a positive sign.
static constexpr bool operator<=(const Angle< t_type_a > &angle_a, const Angle< t_type_b > &angle_b)
Less-than-or-equal comparison operator.
uint64_t uint08
-Defines an alias representing an 8 byte, unsigned integer
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr bool operator>=(const Angle< t_type_a > &angle_a, const Angle< t_type_b > &angle_b)
Greater-than-or-equal comparison operator.
static constexpr Angle< t_type > operator*(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Multiplication operator.
constexpr Vector< 1, t_type > cross(const Vector< 1, t_type > &, const Vector< 1, t_type > &)
static constexpr Angle< t_type > operator-(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Subtraction operator.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr Angle< t_angle_type > & operator+=(Angle< t_angle_type > &angle, const Angle< t_angle_type > &add)
Addition assignment operator for Angles.
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.
static constexpr Angle< t_angle_type > & operator/=(Angle< t_angle_type > &angle, const t_type &mult)
Division assignment operator for an Angle and a scalar.
static constexpr bool operator<(const Angle< t_type_a > &angle_a, const Angle< t_type_b > &angle_b)
Less-than comparison operator.
static constexpr Angle< t_type > difference(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Calculates minimal absolute signed angle between two angles.
static constexpr Angle< t_angle_type > & operator*=(Angle< t_angle_type > &angle, const t_type &mult)
Multiplication assignment operator for an Angle and a scalar.
bool AreParallel(const Vector< t_dims, t_type > &v1, const Vector< t_dims, t_type > &v2)
static constexpr Angle< t_type > operator+(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Addition operator.
t_type sqrt(const t_type &value)
static constexpr fltp08 operator/(const Angle< t_type > &angle_a, const Angle< t_type > &angle_b)
Division operator.
constexpr bool equals(const LineSegment< t_dims, t_type, t_vertex > &left, const LineSegment< t_dims, t_type, t_vertex > &right, const t_type &epsilon=cast< t_type >(0))
Tests if objects are considered equal.
constexpr Vector< t_dims, Angle< t_angle_type > > operator%(const Vector< t_dims, Angle< t_angle_type > > &vec_a, const Vector< t_dims, Angle< t_angle_type > > &vec_b)
Element-wise modulo operator for two Vectors of Angles.
constexpr t_type clip(const t_type &value, const t_type &lower_bound, const t_type &upper_bound)
Clips the value given so that that the returned value falls between upper and lower bound.
static constexpr bool operator>(const Angle< t_type_a > &angle_a, const Angle< t_type_b > &angle_b)
Greater-than comparison operator.
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.