allow any type that can be static_cast to type of vector in operators like +, -, *. /

v1
Brett 2024-05-01 21:28:42 -04:00
parent 37da0bd76d
commit 3f0ea887cd
2 changed files with 25 additions and 25 deletions

View File

@ -1,7 +1,7 @@
cmake_minimum_required(VERSION 3.20)
include(cmake/color.cmake)
set(BLT_VERSION 0.16.19)
set(BLT_VERSION 0.16.20)
set(BLT_TEST_VERSION 0.0.1)
set(BLT_TARGET BLT)

View File

@ -291,39 +291,39 @@ namespace blt
return initializer;
}
template<typename T, blt::u32 size>
inline constexpr vec<T, size> operator+(const vec<T, size>& left, T right)
template<typename T, typename G, blt::u32 size>
inline constexpr vec<T, size> operator+(const vec<T, size>& left, G right)
{
vec<T, size> initializer{};
for (blt::u32 i = 0; i < size; i++)
initializer[i] = left[i] + right;
initializer[i] = left[i] + static_cast<T>(right);
return initializer;
}
template<typename T, blt::u32 size>
inline constexpr vec<T, size> operator-(const vec<T, size>& left, T right)
template<typename T, typename G, blt::u32 size>
inline constexpr vec<T, size> operator-(const vec<T, size>& left, G right)
{
vec<T, size> initializer{};
for (blt::u32 i = 0; i < size; i++)
initializer[i] = left[i] + right;
initializer[i] = left[i] + static_cast<T>(right);
return initializer;
}
template<typename T, blt::u32 size>
inline constexpr vec<T, size> operator+(T f, const vec<T, size>& right)
template<typename T, typename G, blt::u32 size>
inline constexpr vec<T, size> operator+(G left, const vec<T, size>& right)
{
vec<T, size> initializer{};
for (blt::u32 i = 0; i < size; i++)
initializer[i] = f + right[i];
initializer[i] = static_cast<T>(left) + right[i];
return initializer;
}
template<typename T, blt::u32 size>
inline constexpr vec<T, size> operator-(T f, const vec<T, size>& right)
template<typename T, typename G, blt::u32 size>
inline constexpr vec<T, size> operator-(G left, const vec<T, size>& right)
{
vec<T, size> initializer{};
for (blt::u32 i = 0; i < size; i++)
initializer[i] = f - right[i];
initializer[i] = static_cast<T>(left) - right[i];
return initializer;
}
@ -336,39 +336,39 @@ namespace blt
return initializer;
}
template<typename T, blt::u32 size>
inline constexpr vec<T, size> operator*(const vec<T, size>& left, T right)
template<typename T, typename G, blt::u32 size>
inline constexpr vec<T, size> operator*(const vec<T, size>& left, G right)
{
vec<T, size> initializer{};
for (blt::u32 i = 0; i < size; i++)
initializer[i] = left[i] * right;
initializer[i] = left[i] * static_cast<T>(right);
return initializer;
}
template<typename T, blt::u32 size>
inline constexpr vec<T, size> operator*(T f, const vec<T, size>& right)
template<typename T, typename G, blt::u32 size>
inline constexpr vec<T, size> operator*(G left, const vec<T, size>& right)
{
vec<T, size> initializer{};
for (blt::u32 i = 0; i < size; i++)
initializer[i] = f * right[i];
initializer[i] = static_cast<T>(left) * right[i];
return initializer;
}
template<typename T, blt::u32 size>
inline constexpr vec<T, size> operator/(const vec<T, size>& left, T right)
template<typename T, typename G, blt::u32 size>
inline constexpr vec<T, size> operator/(const vec<T, size>& left, G right)
{
vec<T, size> initializer{};
for (blt::u32 i = 0; i < size; i++)
initializer[i] = left[i] / right;
initializer[i] = left[i] / static_cast<T>(right);
return initializer;
}
template<typename T, blt::u32 size>
inline constexpr vec<T, size> operator/(T left, const vec<T, size>& right)
template<typename T, typename G, blt::u32 size>
inline constexpr vec<T, size> operator/(G left, const vec<T, size>& right)
{
vec<T, size> initializer{};
for (blt::u32 i = 0; i < size; i++)
initializer[i] = left / right[i];
initializer[i] = static_cast<T>(left) / right[i];
return initializer;
}