mirror of
https://github.com/orange-cpp/omath.git
synced 2026-02-13 15:03:27 +00:00
added convertors
This commit is contained in:
@@ -3,13 +3,19 @@
|
||||
//
|
||||
|
||||
#pragma once
|
||||
#include <tuple>
|
||||
#include <cmath>
|
||||
#include <tuple>
|
||||
|
||||
#ifdef OMATH_IMGUI_INTEGRATION
|
||||
class ImVec2;
|
||||
#endif
|
||||
|
||||
|
||||
namespace omath
|
||||
{
|
||||
|
||||
template<class Type> requires std::is_arithmetic_v<Type>
|
||||
template<class Type>
|
||||
requires std::is_arithmetic_v<Type>
|
||||
class Vector2
|
||||
{
|
||||
public:
|
||||
@@ -19,7 +25,9 @@ namespace omath
|
||||
// Constructors
|
||||
constexpr Vector2() = default;
|
||||
|
||||
constexpr Vector2(const Type& x, const Type& y) : x(x), y(y) {}
|
||||
constexpr Vector2(const Type& x, const Type& y) : x(x), y(y)
|
||||
{
|
||||
}
|
||||
|
||||
// Equality operators
|
||||
[[nodiscard]]
|
||||
@@ -145,7 +153,7 @@ namespace omath
|
||||
|
||||
constexpr Vector2& Abs()
|
||||
{
|
||||
//FIXME: Replace with std::abs, if it will become constexprable
|
||||
// FIXME: Replace with std::abs, if it will become constexprable
|
||||
x = x < 0 ? -x : x;
|
||||
y = y < 0 ? -y : y;
|
||||
return *this;
|
||||
@@ -188,7 +196,7 @@ namespace omath
|
||||
return {x / fl, y / fl};
|
||||
}
|
||||
|
||||
// Sum of elements
|
||||
// Sum of elements
|
||||
[[nodiscard]] constexpr Type Sum() const
|
||||
{
|
||||
return x + y;
|
||||
@@ -199,5 +207,19 @@ namespace omath
|
||||
{
|
||||
return std::make_tuple(x, y);
|
||||
}
|
||||
|
||||
#ifdef OMATH_IMGUI_INTEGRATION
|
||||
[[nodiscard]]
|
||||
const ImVec2& ToImVec2() const
|
||||
{
|
||||
return *reinterpret_cast<const ImVec2*>(this);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
ImVec2& ToImVec2()
|
||||
{
|
||||
return *reinterpret_cast<ImVec2*>(this);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
}
|
||||
} // namespace omath
|
||||
|
||||
@@ -4,13 +4,12 @@
|
||||
|
||||
#pragma once
|
||||
|
||||
#include "Vector2.hpp"
|
||||
#include <cstdint>
|
||||
#include <functional>
|
||||
#include "omath/Vector2.hpp"
|
||||
#include "omath/Angle.hpp"
|
||||
#include <expected>
|
||||
#include <immintrin.h>
|
||||
|
||||
#include <functional>
|
||||
#include "omath/Angle.hpp"
|
||||
#include "omath/Vector2.hpp"
|
||||
|
||||
namespace omath
|
||||
{
|
||||
|
||||
@@ -6,6 +6,10 @@
|
||||
#include <omath/Vector3.hpp>
|
||||
#include <algorithm>
|
||||
|
||||
#ifdef OMATH_IMGUI_INTEGRATION
|
||||
class ImVec4;
|
||||
#endif
|
||||
|
||||
namespace omath
|
||||
{
|
||||
template <class Type>
|
||||
@@ -154,5 +158,19 @@ namespace omath
|
||||
{
|
||||
return Vector3<Type>::Sum() + w;
|
||||
}
|
||||
|
||||
#ifdef OMATH_IMGUI_INTEGRATION
|
||||
[[nodiscard]]
|
||||
constexpr ImVec4& ToImVec4() const
|
||||
{
|
||||
return *reinterpret_cast<const ImVec4*>(this);
|
||||
}
|
||||
|
||||
[[nodiscard]]
|
||||
constexpr ImVec2& ToImVec2()
|
||||
{
|
||||
return *reinterpret_cast<ImVec4*>(this);
|
||||
}
|
||||
#endif
|
||||
};
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user