mirror of
https://github.com/orange-cpp/omath.git
synced 2026-04-27 03:23:27 +00:00
added typecasting for vectors
This commit is contained in:
@@ -26,6 +26,12 @@ namespace omath
|
||||
// Constructors
|
||||
constexpr Vector2() = default;
|
||||
|
||||
template<class CastedType>
|
||||
requires std::is_arithmetic_v<CastedType>
|
||||
[[nodiscard]] constexpr explicit operator Vector2<CastedType>() const noexcept
|
||||
{
|
||||
return {static_cast<CastedType>(x), static_cast<CastedType>(y)};
|
||||
}
|
||||
constexpr Vector2(const Type& x, const Type& y) noexcept: x(x), y(y)
|
||||
{
|
||||
}
|
||||
|
||||
@@ -30,6 +30,13 @@ namespace omath
|
||||
}
|
||||
constexpr Vector3() noexcept: Vector2<Type>() {};
|
||||
|
||||
template<class CastedType>
|
||||
requires std::is_arithmetic_v<CastedType>
|
||||
[[nodiscard]] constexpr explicit operator Vector3<CastedType>() const noexcept
|
||||
{
|
||||
return {static_cast<CastedType>(this->x), static_cast<CastedType>(this->y),
|
||||
static_cast<CastedType>(this->z)};
|
||||
}
|
||||
[[nodiscard]] constexpr bool operator==(const Vector3& other) const noexcept
|
||||
{
|
||||
return Vector2<Type>::operator==(other) && (other.z == z);
|
||||
|
||||
@@ -21,6 +21,15 @@ namespace omath
|
||||
}
|
||||
constexpr Vector4() noexcept: Vector3<Type>(), w(static_cast<Type>(0)) {};
|
||||
|
||||
|
||||
template<class CastedType>
|
||||
requires std::is_arithmetic_v<CastedType>
|
||||
[[nodiscard]] constexpr explicit operator Vector4<CastedType>() const noexcept
|
||||
{
|
||||
return {static_cast<CastedType>(this->x), static_cast<CastedType>(this->y),
|
||||
static_cast<CastedType>(this->z), static_cast<CastedType>(this->w)};
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr bool operator==(const Vector4& other) const noexcept
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user