Merge pull request 'Tests & fixes for various parts of Math module' (#137) from tests_math into master
Reviewed-on: https://git.madvoxel.net/OpenVulkano/OpenVulkano/pulls/137 Reviewed-by: Georg Hagen <georg.hagen@madvoxel.com>
This commit is contained in:
@@ -10,6 +10,7 @@
|
||||
#include <string>
|
||||
#include <set>
|
||||
#include <algorithm>
|
||||
#include <array>
|
||||
#include <bit>
|
||||
#include <cassert>
|
||||
#include <cinttypes>
|
||||
|
||||
@@ -98,12 +98,12 @@ namespace OpenVulkano::Math
|
||||
|
||||
[[nodiscard]] bool InBounds(const Math::Vector3f& position) const
|
||||
{
|
||||
return Math::Utils::all(Math::Utils::greaterThanEqual(min, position)) && Math::Utils::all(Math::Utils::lessThanEqual(position, max));
|
||||
return Math::Utils::all(Math::Utils::lessThanEqual(min, position)) && Math::Utils::all(Math::Utils::lessThanEqual(position, max));
|
||||
}
|
||||
|
||||
[[nodiscard]] bool Inside(const Math::Vector3f& position) const
|
||||
{
|
||||
return Math::Utils::all(Math::Utils::greaterThan(min, position)) && Math::Utils::all(Math::Utils::lessThan(position, max));
|
||||
return Math::Utils::all(Math::Utils::lessThan(min, position)) && Math::Utils::all(Math::Utils::lessThan(position, max));
|
||||
}
|
||||
|
||||
[[nodiscard]] bool IsEmpty() const
|
||||
|
||||
@@ -134,9 +134,9 @@ namespace OpenVulkano
|
||||
operator std::string() const { return Format(); }
|
||||
|
||||
ByteSize operator +(const ByteSize other) const { return bytes + other.bytes; }
|
||||
ByteSize operator -(const ByteSize other) const { return bytes + other.bytes; }
|
||||
ByteSize operator -(const ByteSize other) const { return bytes - other.bytes; }
|
||||
ByteSize operator +(const size_t other) const { return bytes + other; }
|
||||
ByteSize operator -(const size_t other) const { return bytes + other; }
|
||||
ByteSize operator -(const size_t other) const { return bytes - other; }
|
||||
ByteSize& operator =(const size_t other) { bytes = other; return *this; }
|
||||
ByteSize& operator =(const ByteSize other) { bytes = other.bytes; return *this; }
|
||||
ByteSize& operator +=(const size_t other) { bytes += other; return *this; }
|
||||
|
||||
@@ -149,7 +149,7 @@ namespace OpenVulkano::Math
|
||||
|
||||
[[nodiscard]] constexpr bool operator !=(DenseVec3 rhs) const
|
||||
{
|
||||
return data == rhs.data;
|
||||
return data != rhs.data;
|
||||
}
|
||||
|
||||
[[nodiscard]] explicit constexpr operator Math::Vector3i() const
|
||||
|
||||
@@ -30,21 +30,21 @@ namespace OpenVulkano::Math
|
||||
|
||||
RGB10A2(TYPE value = 0) : value(value) {}
|
||||
|
||||
template<typename T, typename = std::enable_if_t<std::is_unsigned_v<T> || std::is_signed_v<TYPE>>>
|
||||
template<typename T, typename = std::enable_if_t<std::is_integral_v<TYPE>>>
|
||||
void Set(Vector3<T> vec3)
|
||||
{
|
||||
vec3 &= VALUE_BITMASK;
|
||||
SetUnchecked(vec3);
|
||||
}
|
||||
|
||||
template<typename T, typename = std::enable_if_t<std::is_unsigned_v<T> || std::is_signed_v<TYPE>>>
|
||||
template<typename T, typename = std::enable_if_t<std::is_integral_v<TYPE>>>
|
||||
void Set(Vector3_SIMD<T> vec3)
|
||||
{
|
||||
vec3 &= VALUE_BITMASK;
|
||||
SetUnchecked(vec3);
|
||||
}
|
||||
|
||||
template<typename T, typename = std::enable_if_t<std::is_unsigned_v<T> || std::is_signed_v<TYPE>>>
|
||||
template<typename T, typename = std::enable_if_t<std::is_integral_v<TYPE>>>
|
||||
void Set(Vector4<T> vec4)
|
||||
{
|
||||
vec4 &= VALUE_BITMASK;
|
||||
@@ -69,19 +69,19 @@ namespace OpenVulkano::Math
|
||||
Set(Math::Vector4<TYPE>(vec4));
|
||||
}
|
||||
|
||||
template<typename T, typename = std::enable_if_t<std::is_unsigned_v<T> || std::is_signed_v<TYPE>>>
|
||||
template<typename T, typename = std::enable_if_t<std::is_integral_v<TYPE>>>
|
||||
void const SetUnchecked(Vector3<T>& vec3)
|
||||
{
|
||||
value = vec3.r | vec3.g << 10 | vec3.b << 20 | MAX_ALPHA_VALUE << 30;
|
||||
}
|
||||
|
||||
template<typename T, typename = std::enable_if_t<std::is_unsigned_v<T> || std::is_signed_v<TYPE>>>
|
||||
template<typename T, typename = std::enable_if_t<std::is_integral_v<TYPE>>>
|
||||
void SetUnchecked(const Vector3_SIMD<T>& vec3)
|
||||
{
|
||||
value = vec3.r | vec3.g << 10 | vec3.b << 20 | MAX_ALPHA_VALUE << 30;
|
||||
}
|
||||
|
||||
template<typename T, typename = std::enable_if_t<std::is_unsigned_v<T> || std::is_signed_v<TYPE>>>
|
||||
template<typename T, typename = std::enable_if_t<std::is_integral_v<TYPE>>>
|
||||
void SetUnchecked(const Vector4<T>& vec4)
|
||||
{
|
||||
value = vec4.r | vec4.g << 10 | vec4.b << 20 | vec4.a << 30;
|
||||
|
||||
@@ -18,79 +18,61 @@ namespace OpenVulkano::Math
|
||||
uint64_t timestamp;
|
||||
|
||||
public:
|
||||
explicit Timestamp(uint64_t nanos = 0) : timestamp(nanos) {}
|
||||
explicit Timestamp(double seconds) : timestamp(static_cast<uint64_t>(seconds * SECONDS_TO_NANOS)) {}
|
||||
explicit constexpr Timestamp(uint64_t nanos = 0) : timestamp(nanos) {}
|
||||
explicit constexpr Timestamp(double seconds) : timestamp(static_cast<uint64_t>(seconds * SECONDS_TO_NANOS)) {}
|
||||
|
||||
[[nodiscard]] uint64_t GetNanos() const { return timestamp; }
|
||||
[[nodiscard]] double GetSeconds() const { return timestamp * NANOS_TO_SECONDS; }
|
||||
[[nodiscard]] constexpr uint64_t GetNanos() const { return timestamp; }
|
||||
[[nodiscard]] constexpr double GetSeconds() const { return timestamp * NANOS_TO_SECONDS; }
|
||||
|
||||
Timestamp& operator+=(const Timestamp& rhs)
|
||||
constexpr Timestamp& operator+=(const Timestamp& rhs)
|
||||
{
|
||||
timestamp += rhs.timestamp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Timestamp& operator-=(const Timestamp& rhs)
|
||||
constexpr Timestamp& operator-=(const Timestamp& rhs)
|
||||
{
|
||||
timestamp -= rhs.timestamp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Timestamp& operator =(double time)
|
||||
constexpr Timestamp& operator =(double time)
|
||||
{
|
||||
timestamp = Timestamp(time).timestamp;
|
||||
return *this;
|
||||
}
|
||||
|
||||
Timestamp& operator =(uint64_t time)
|
||||
constexpr Timestamp& operator =(uint64_t time)
|
||||
{
|
||||
timestamp = time;
|
||||
return *this;
|
||||
}
|
||||
|
||||
constexpr inline bool operator==(const Timestamp& rhs) const { return GetNanos() == rhs.GetNanos(); }
|
||||
|
||||
constexpr inline bool operator!=(const Timestamp& rhs) const { return !(*this == rhs); }
|
||||
|
||||
constexpr inline bool operator<(const Timestamp& rhs) const { return GetNanos() < rhs.GetNanos(); }
|
||||
|
||||
constexpr inline bool operator>(const Timestamp& rhs) const { return rhs < *this; }
|
||||
|
||||
constexpr inline bool operator>=(const Timestamp& rhs) const { return !(*this < rhs); }
|
||||
|
||||
constexpr inline bool operator<=(const Timestamp& rhs) const { return !(rhs < *this); }
|
||||
|
||||
constexpr inline Timestamp operator-(const Timestamp& rhs) const
|
||||
{
|
||||
return Timestamp(GetNanos() - rhs.GetNanos());
|
||||
}
|
||||
|
||||
constexpr inline Timestamp operator+(const Timestamp& rhs) const
|
||||
{
|
||||
return Timestamp(GetNanos() + rhs.GetNanos());
|
||||
}
|
||||
|
||||
constexpr inline double operator/(const Timestamp& rhs) const
|
||||
{
|
||||
return GetNanos() / static_cast<double>(rhs.GetNanos());
|
||||
}
|
||||
};
|
||||
|
||||
inline bool operator==(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return lhs.GetNanos() == rhs.GetNanos();
|
||||
}
|
||||
|
||||
inline bool operator!=(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return !(lhs == rhs);
|
||||
}
|
||||
|
||||
inline bool operator<(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return lhs.GetNanos() < rhs.GetNanos();
|
||||
}
|
||||
|
||||
inline bool operator>(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return rhs < lhs;
|
||||
}
|
||||
|
||||
inline bool operator>=(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return !(lhs < rhs);
|
||||
}
|
||||
|
||||
inline bool operator<=(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return !(rhs < lhs);
|
||||
}
|
||||
|
||||
inline Timestamp operator-(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return Timestamp(lhs.GetNanos() - rhs.GetNanos());
|
||||
}
|
||||
|
||||
inline Timestamp operator+(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return Timestamp(lhs.GetNanos() + rhs.GetNanos());
|
||||
}
|
||||
|
||||
inline double operator/(const Timestamp& lhs, const Timestamp& rhs)
|
||||
{
|
||||
return lhs.GetNanos() / static_cast<double>(rhs.GetNanos());
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user