33#include <NDEVR/BaseValues.h>
34#include <NDEVR/LibAssert.h>
60 template<u
int01 t_dims,
class t_type>
64 constexpr Vector() noexcept
78 template<
class t_vec_type>
79 constexpr explicit Vector(
const Vector<t_dims, t_vec_type>& vector) noexcept
82 for (
uint01 dim = 0; dim < t_dims; ++dim)
97 constexpr explicit Vector(
const t_type& scaler) noexcept
100 for(
uint01 dim = 0; dim < t_dims; ++dim)
116 template<u
int01 tdims = t_dims>
117 constexpr Vector(
const t_type& x,
typename std::enable_if<tdims == 2, const t_type&>::type y)
120 static_assert(t_dims == 2,
"Unexpected Number of Dimensions. Vector Size Required: 2");
136 template<u
int01 tdims = t_dims>
137 constexpr Vector(
const t_type& x,
const t_type& y,
const typename std::enable_if<tdims == 3, const t_type&>::type z)
140 static_assert(t_dims == 3,
"Unexpected Number of Dimensions. Vector Size Required: 3");
157 template<u
int01 tdims = t_dims>
158 constexpr Vector(
const t_type& x,
const t_type& y,
const t_type& z,
typename std::enable_if<tdims == 4, const t_type&>::type w)
161 static_assert(t_dims == 4,
"Unexpected Number of Dimensions. Vector Size Required: 4");
164 template<u
int01 tdims = t_dims>
165 constexpr Vector(
const t_type& x,
const t_type& y,
const t_type& z,
const t_type& w,
typename std::enable_if<tdims == 5, const t_type&>::type v)
168 static_assert(t_dims == 5,
"Unexpected Number of Dimensions. Vector Size Required: 5");
171 template<u
int01 tdims = t_dims>
172 constexpr Vector(
const t_type& x,
const t_type& y,
const t_type& z,
const t_type& w,
const t_type& v,
typename std::enable_if<tdims == 6, const t_type&>::type u)
175 static_assert(t_dims == 6,
"Unexpected Number of Dimensions. Vector Size Required: 6");
177 template<u
int01 tdims = t_dims>
178 constexpr Vector(
const t_type& x,
const t_type& y,
const t_type& z,
const t_type& w,
const t_type& v,
const t_type& u,
const t_type& t,
const t_type& s,
typename std::enable_if<tdims == 9, const t_type&>::type r)
179 :
m_values{ x, y, z, w, v, u, t, s, r }
181 static_assert(t_dims == 9,
"Unexpected Number of Dimensions. Vector Size Required: 9");
193 constexpr explicit Vector(
const t_type(&vector)[t_dims])
196 for (
uint01 dim = 0; dim < t_dims; dim++)
211 template<u
int01 tdims = t_dims>
212 constexpr Vector(
const Vector<tdims - 1, t_type>& vector,
typename std::enable_if<tdims >= 2,
const t_type&>
::type suffix)
215 static_assert(t_dims >= 2,
"Unexpected Number of Dimensions. Vector Size Required: >= 2");
216 for(
uint01 dim = 0; dim < t_dims - 1; ++dim)
233 template<u
int01 tdims = t_dims>
234 constexpr Vector(
const Vector<
getMax(tdims - 2, 0), t_type>& vector,
const t_type& suffix_a,
typename std::enable_if<tdims >= 3,
const t_type&>
::type suffix_b)
237 static_assert(t_dims >= 3,
"Unexpected Number of Dimensions. Vector Size Required: >= 3");
238 for(
uint01 dim = 0; dim < t_dims - 2; ++dim)
255 template<u
int01 tdims = t_dims>
256 constexpr Vector(
const t_type& prefix,
typename std::enable_if<tdims >= 2,
const Vector<t_dims - 1, t_type>&>
::type vector)
259 static_assert(t_dims >= 2,
"Unexpected Number of Dimensions. Vector Size Required: >= 2");
261 for(
uint01 dim = Y; dim < t_dims; ++dim)
276 template<u
int01 tdims = t_dims>
277 constexpr Vector(
const t_type& prefix_a,
const t_type& prefix_b,
typename std::enable_if<tdims >= 3,
const Vector<tdims - 1, t_type>&>
::type vector)
280 static_assert(t_dims >= 3,
"Unexpected Number of Dimensions. Vector Size Required: >= 3");
283 for (
uint01 dim = Z; dim < t_dims; ++dim)
300 template<
class t_new_type>
301 constexpr decltype(
auto)
as()
const
303 if constexpr (std::is_same_v<t_new_type, t_type>)
305 return static_cast<const Vector<t_dims, t_type>&
>(*this);
309 Vector<t_dims, t_new_type> vec;
310 for (
uint01 dim = 0; dim < t_dims; ++dim)
315 template<u
int01 t_new_dim,
class t_new_type>
316 constexpr decltype(
auto)
as()
const
318 if constexpr (t_new_dim == t_dims && std::is_same_v<t_new_type, t_type>)
324 Vector<t_new_dim, t_new_type> vec;
326 for (
uint01 dim = 0; dim < min; ++dim)
331 template<u
int01 t_new_dim,
class t_new_type>
332 constexpr decltype(
auto)
as(t_new_type extra_fill_value)
const
334 if constexpr (t_new_dim == t_dims && std::is_same_v<t_new_type, t_type>)
336 return static_cast<const Vector<t_dims, t_type>&
>(*this);
340 Vector<t_new_dim, t_new_type> vec;
343 for (; dim < min; dim++)
345 for (; dim < t_new_dim; dim++)
346 vec[dim] = extra_fill_value;
361 template<LocationValues t_max_min>
365 for(
uint01 dim = 1; dim < t_dims; ++dim)
367 if constexpr(t_max_min == MAX)
391 template<LocationValues t_max_min>
395 for(
uint01 dim = 1; dim < t_dims; ++dim)
397 if constexpr (t_max_min == MAX)
421 template<
uint01 tdims = t_dims
422 ,
typename =
typename std::enable_if<tdims == 1>::type>
423 constexpr operator t_type&()
428 template<
uint01 tdims = t_dims
429 ,
typename =
typename std::enable_if<tdims == 1>::type>
430 constexpr operator const t_type &()
const
451 for(
uint01 dim = 0; dim < t_dims; ++dim)
469 template<
class t_magnitude_type = t_type>
485 template<
class t_norm_type = t_type>
486 constexpr Vector<t_dims, t_norm_type>
normalized(Vector<t_dims, t_norm_type> value_if_nan =
Constant<Vector<t_dims, t_norm_type>>::Invalid)
const
493 for (
uint01 dim = 0; dim < t_dims; dim++)
510 [[nodiscard]]
constexpr t_type
product()
const
513 for(
uint01 dim = 1; dim < t_dims; ++dim)
527 [[nodiscard]]
constexpr t_type
sum()
const
530 for (
uint01 dim = 1; dim < t_dims; ++dim)
550 #if defined(__clang__) || defined(__GNUC__)
551 if constexpr (__builtin_constant_p(dimension_index))
552 static_assert(dimension_index < t_dims,
"Dimension requested Exceeded maximum vector dimension");
554 lib_assert(dimension_index < t_dims,
"Dimension requested Exceeded maximum vector dimension");
559 #if defined(__clang__) || defined(__GNUC__)
560 if constexpr (__builtin_constant_p(dimension_index))
561 static_assert(dimension_index < t_dims,
"Dimension requested Exceeded maximum vector dimension");
563 lib_assert(dimension_index < t_dims,
"Dimension requested Exceeded maximum vector dimension");
578 Vector<t_dims, t_type> value;
579 for(
uint01 dim = 0; dim < t_dims; ++dim)
597 constexpr Vector<t_dims, t_type>&
operator=(
const t_type& scaler)
599 for (
uint01 dim = 0; dim < t_dims; ++dim)
626 constexpr static t_type
Type() {
return t_type(); }
648 template<u
int01 t_dims,
class t_type>
651 for (
uint01 dim = 0; dim < t_dims; ++dim)
653 if (vec_a[dim] != vec_b[dim])
672 template<u
int01 t_dims,
class t_type>
675 for (
uint01 dim = 0; dim < t_dims; ++dim)
677 if (vec_a[dim] != vec_b[dim])
698 template<u
int01 t_dims,
class t_type>
701 return (((value.template as<t_dims, fltp08>() /
cast<fltp08>(d) + 0.5).template as<t_dims, sint08>()).template as<t_dims, fltp08>() *
cast<fltp08>(d)).template as<t_dims, t_type>();
707 template<u
int01 t_dims,
class t_type>
710 return (((value.template as<t_dims, fltp08>()
711 / d.template as<t_dims, fltp08>() + 0.5).template as<t_dims, uint08>()).template as<t_dims, fltp08>()
712 * d.template as<t_dims, fltp08>()).template as<t_dims, t_type>();
714 template<u
int01 t_dims,
class t_type>
715 struct Constant<Vector<t_dims, t_type>>
718 constexpr const static Vector<t_dims, t_type>
Invalid{ Constant<t_type>::Invalid };
720 constexpr const static Vector<t_dims, t_type> Min{ Constant<t_type>::Min };
722 constexpr const static Vector<t_dims, t_type> Max{ Constant<t_type>::Max };
725 template<u
int01 t_dims,
class t_type>
728 for (
uint01 dim = 0; dim < t_dims; ++dim)
735 template<u
int01 t_dims,
class t_type>
738 for (
uint01 dim = 0; dim < t_dims; ++dim)
745 template <
template <u
int01 t_dims,
class t_type>
class base,
typename derived>
746 struct is_base_of_template_impl
748 template<u
int01 t_dims,
class t_type>
749 static constexpr std::true_type test(
const base<t_dims, t_type>*);
750 static constexpr std::false_type test(...);
751 using type =
decltype(test(std::declval<derived*>()));
754 template <
template <u
int01 t_dims,
class t_type>
class base,
typename derived>
755 using is_base_of_template =
typename is_base_of_template_impl<base, derived>::type;
757 template<
class t_type>
760 static constexpr bool value = is_base_of_template<Vector, t_type>::value;
762 template<
class t_type_a,
class t_type_b>
765 static constexpr bool value =
false;
767 template<
class t_type_a>
768 struct IsSameType<t_type_a, t_type_a>
770 static constexpr bool value =
true;
772 template<
class t_type_a,
class t_type_b>
776 template<class t = t_type_a, std::enable_if_t<!IsVec<t>::value,
int> = 0>
777 static constexpr bool internalValue()
781 template<class t = t_type_a, std::enable_if_t<IsVec<t>::value,
int> = 0>
782 static constexpr bool internalValue()
784 return IsSameType<
decltype(t::Type()), t_type_b>::value;
787 static constexpr bool value = internalValue();
793 struct hash<Vector<2, uint04>>
795 std::size_t operator()(
const Vector<2, uint04>& s)
const noexcept
797 std::size_t h = 0, g = 0;
798 const uint01* bytes =
reinterpret_cast<const uint01*
>(&s[0]);
799 for (
size_t i = 0; i < 2 *
sizeof(
uint04); i++)
801 h = (h << 4) + bytes[i];
811 struct hash<Vector<3, uint04>>
813 std::size_t operator()(
const Vector<3, uint04>& s)
const noexcept
815 std::size_t h = 0, g = 0;
816 const uint01* bytes =
reinterpret_cast<const uint01*
>(&s[0]);
817 for (
size_t i = 0; i < 3 *
sizeof(
uint04); i++)
819 h = (h << 4) + bytes[i];
829 struct hash<Vector<3, fltp08>>
831 std::size_t operator()(
const Vector<3, fltp08>& s)
const noexcept
833 std::size_t h = 0, g = 0;
834 const uint01* bytes =
reinterpret_cast<const uint01*
>(&s[0]);
835 for (
size_t i = 0; i < 3 *
sizeof(
fltp08); i++)
837 h = (h << 4) + bytes[i];
847 struct hash<Vector<3, fltp04>>
849 std::size_t operator()(
const Vector<3, fltp04>& s)
const noexcept
851 std::size_t h = 0, g = 0;
852 const uint01* bytes =
reinterpret_cast<const uint01*
>(&s[0]);
855 h = (h << 4) + bytes[i];
865#include "BoolVector.hpp"
A fixed-size array with N dimensions used as the basis for geometric and mathematical types.
constexpr t_type sum() const
Returns the sum, or value of each dimension added together.
constexpr Vector(const t_type &prefix, typename std::enable_if< tdims >=2, const Vector< t_dims - 1, t_type > & >::type vector)
Creates a vector where the prefix scaler is combined with the suffix vector.
constexpr t_type product() const
Returns the product, or value of each dimension multiplied together.
constexpr Vector(const Vector< tdims - 1, t_type > &vector, typename std::enable_if< tdims >=2, const t_type & >::type suffix)
Creates a vector where the prefix vector is combined with the suffix scalers.
constexpr Vector(const t_type(&vector)[t_dims])
Given a container of statically determined array, transforms it to a vector.
constexpr Vector(const t_type &scaler) noexcept
t_type m_values[t_dims]
The values[t dims].
constexpr decltype(auto) as() const
Returns the vector as a new time of vector.
constexpr Vector< t_dims, t_norm_type > normalized(Vector< t_dims, t_norm_type > value_if_nan=Constant< Vector< t_dims, t_norm_type > >::Invalid) const
Gets the normalized, or unit length representation of this vector.
constexpr t_type magnitudeSquared() const
Vectors are commonly used to model forces such as wind, sea current, gravity, and electromagnetism.
constexpr Vector(const t_type &x, const t_type &y, const typename std::enable_if< tdims==3, const t_type & >::type z)
Sets values in each dimension to the respective value in the passed in scaler.
constexpr Vector(const t_type &prefix_a, const t_type &prefix_b, typename std::enable_if< tdims >=3, const Vector< tdims - 1, t_type > & >::type vector)
Creates a vector where the prefix scaler values are combined with the suffix vector.
constexpr Vector< t_dims, t_type > & operator=(const t_type &scaler)
Assignment operator.
constexpr Vector(const Vector< getMax(tdims - 2, 0), t_type > &vector, const t_type &suffix_a, typename std::enable_if< tdims >=3, const t_type & >::type suffix_b)
Creates a vector where the prefix vector is combined with the suffix scalers.
constexpr Vector< t_dims, t_type > operator-() const
Negation operator.
constexpr Vector(const t_type &x, typename std::enable_if< tdims==2, const t_type & >::type y)
Sets values in each dimension to the respective value in the passed in scaler.
constexpr Vector(const t_type &x, const t_type &y, const t_type &z, typename std::enable_if< tdims==4, const t_type & >::type w)
Sets values in each dimension to the respective value in the passed in scaler.
constexpr t_type dimensionalValue() const
Used with template arguments MAX or MIN, Gets the dimensional value for the value that is either max ...
constexpr t_type & operator[](uint01 dimension_index)
Accesses the value of a certain dimension.
static constexpr uint01 NumberOfDimensions()
Number of dimensions in this vector class.
static constexpr t_type Type()
Returns the type of this class.
constexpr t_magnitude_type magnitude() const
Vectors are commonly used to model forces such as wind, sea current, gravity, and electromagnetism.
constexpr uint01 dimensionalIndex() const
Used with template arguments MAX or MIN, Gets the dimensional index for the value that is either max ...
constexpr Vector(const Vector< t_dims, t_vec_type > &vector) noexcept
The primary namespace for the NDEVR SDK.
@ 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...
float fltp04
Defines an alias representing a 4 byte floating-point number Bit layout is as follows: -Sign: 1 bit a...
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 > ...
static constexpr bool IsValid(const Angle< t_type > &value)
Checks whether the given Angle holds a valid value.
constexpr HSLColor Constant< HSLColor >::Invalid
The invalid HSLColor constant with all components set to invalid.
constexpr Vector< t_dims, Angle< t_angle_type > > quantize(const Vector< t_dims, Angle< t_angle_type > > &value, Angle< t_angle_type > d=Angle< t_angle_type >(DEGREES, 1.0))
Quantizes a Vector of Angles to the nearest multiple of a given step size.
uint32_t uint04
-Defines an alias representing a 4 byte, unsigned integer -Can represent exact integer values 0 throu...
double fltp08
Defines an alias representing an 8 byte floating-point number.
uint8_t uint01
-Defines an alias representing a 1 byte, unsigned integer -Can represent exact integer values 0 throu...
static constexpr bool IsInvalid(const Angle< t_type > &value)
Checks whether the given Angle holds an invalid value.
t_type sqrt(const t_type &value)
constexpr t_to cast(const Angle< t_from > &value)
Casts an Angle from one backing type to another.
Defines for a given type (such as sint04, fltp08, UUID, etc) a maximum, minimum, and reserved 'invali...