2022-01-23 09:11:08 +08:00
|
|
|
#include <SFML/System/Angle.hpp>
|
2018-08-19 07:30:53 +08:00
|
|
|
#include <SFML/System/String.hpp>
|
|
|
|
#include <SFML/System/Time.hpp>
|
2023-04-13 21:50:19 +08:00
|
|
|
#include <SFML/System/Vector2.hpp>
|
|
|
|
#include <SFML/System/Vector3.hpp>
|
2021-12-25 00:16:06 +08:00
|
|
|
|
2023-01-18 12:51:08 +08:00
|
|
|
#include <catch2/catch_approx.hpp>
|
2018-08-19 07:30:53 +08:00
|
|
|
|
2022-07-05 00:20:58 +08:00
|
|
|
#include <SystemUtil.hpp>
|
2024-04-12 08:13:19 +08:00
|
|
|
#include <fstream>
|
2023-04-13 21:50:19 +08:00
|
|
|
#include <iomanip>
|
|
|
|
#include <limits>
|
2022-07-05 00:20:58 +08:00
|
|
|
|
2024-04-12 08:13:19 +08:00
|
|
|
#include <cassert>
|
|
|
|
|
|
|
|
|
2021-12-24 21:31:27 +08:00
|
|
|
namespace sf
|
2018-08-19 07:30:53 +08:00
|
|
|
{
|
2023-04-13 21:50:19 +08:00
|
|
|
void setStreamPrecision(std::ostream& os, int maxDigits10)
|
|
|
|
{
|
|
|
|
os << std::fixed << std::setprecision(maxDigits10);
|
|
|
|
}
|
|
|
|
|
2022-07-05 13:46:34 +08:00
|
|
|
std::ostream& operator<<(std::ostream& os, const Angle& angle)
|
2022-07-05 00:20:58 +08:00
|
|
|
{
|
2023-04-13 21:50:19 +08:00
|
|
|
setStreamPrecision(os, std::numeric_limits<float>::max_digits10);
|
2022-07-05 13:57:04 +08:00
|
|
|
return os << angle.asDegrees() << " deg";
|
2022-07-05 00:20:58 +08:00
|
|
|
}
|
|
|
|
|
2022-07-05 13:46:34 +08:00
|
|
|
std::ostream& operator<<(std::ostream& os, const String& string)
|
2022-07-05 00:20:58 +08:00
|
|
|
{
|
2022-07-05 13:57:04 +08:00
|
|
|
return os << string.toAnsiString();
|
2022-07-05 00:20:58 +08:00
|
|
|
}
|
|
|
|
|
2022-07-05 13:46:34 +08:00
|
|
|
std::ostream& operator<<(std::ostream& os, Time time)
|
2022-07-05 00:20:58 +08:00
|
|
|
{
|
2022-07-05 13:57:04 +08:00
|
|
|
return os << time.asMicroseconds() << "us";
|
2018-08-19 07:30:53 +08:00
|
|
|
}
|
2023-04-13 21:50:19 +08:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
std::ostream& operator<<(std::ostream& os, const Vector2<T>& vector)
|
|
|
|
{
|
|
|
|
setStreamPrecision(os, std::numeric_limits<T>::max_digits10);
|
|
|
|
return os << "(" << vector.x << ", " << vector.y << ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
std::ostream& operator<<(std::ostream& os, const Vector3<T>& vector)
|
|
|
|
{
|
|
|
|
setStreamPrecision(os, std::numeric_limits<T>::max_digits10);
|
|
|
|
return os << "(" << vector.x << ", " << vector.y << ", " << vector.z << ")";
|
|
|
|
}
|
|
|
|
|
|
|
|
template std::ostream& operator<<(std::ostream&, const Vector2<int>&);
|
|
|
|
template std::ostream& operator<<(std::ostream&, const Vector2<unsigned int>&);
|
|
|
|
template std::ostream& operator<<(std::ostream&, const Vector2<float>&);
|
|
|
|
|
|
|
|
template std::ostream& operator<<(std::ostream&, const Vector3<int>&);
|
|
|
|
template std::ostream& operator<<(std::ostream&, const Vector3<unsigned int>&);
|
|
|
|
template std::ostream& operator<<(std::ostream&, const Vector3<float>&);
|
2022-07-05 00:20:58 +08:00
|
|
|
} // namespace sf
|
2021-12-25 00:16:06 +08:00
|
|
|
|
2022-05-03 06:38:33 +08:00
|
|
|
bool operator==(const float& lhs, const Approx<float>& rhs)
|
2022-05-05 01:03:26 +08:00
|
|
|
{
|
2023-01-18 12:51:08 +08:00
|
|
|
return static_cast<double>(lhs) == Catch::Approx(static_cast<double>(rhs.value)).margin(1e-5);
|
2022-05-05 01:03:26 +08:00
|
|
|
}
|
|
|
|
|
2022-05-03 06:38:33 +08:00
|
|
|
bool operator==(const sf::Vector2f& lhs, const Approx<sf::Vector2f>& rhs)
|
2022-02-18 00:22:00 +08:00
|
|
|
{
|
2022-05-03 06:38:33 +08:00
|
|
|
return (lhs - rhs.value).length() == Approx(0.f);
|
2022-02-18 00:22:00 +08:00
|
|
|
}
|
|
|
|
|
2022-05-03 06:38:33 +08:00
|
|
|
bool operator==(const sf::Vector3f& lhs, const Approx<sf::Vector3f>& rhs)
|
2022-02-18 00:22:00 +08:00
|
|
|
{
|
2022-05-03 06:38:33 +08:00
|
|
|
return (lhs - rhs.value).length() == Approx(0.f);
|
2022-02-18 00:22:00 +08:00
|
|
|
}
|
|
|
|
|
2022-05-03 06:38:33 +08:00
|
|
|
bool operator==(const sf::Angle& lhs, const Approx<sf::Angle>& rhs)
|
2022-05-05 01:03:26 +08:00
|
|
|
{
|
2024-05-14 02:30:31 +08:00
|
|
|
return lhs.asRadians() == Approx(rhs.value.asRadians());
|
2022-02-18 00:22:00 +08:00
|
|
|
}
|
2024-04-12 08:13:19 +08:00
|
|
|
|
|
|
|
std::vector<std::byte> loadIntoMemory(const std::filesystem::path& path)
|
|
|
|
{
|
|
|
|
std::ifstream file(path, std::ios::binary | std::ios::ate);
|
|
|
|
assert(file);
|
|
|
|
const auto size = file.tellg();
|
|
|
|
file.seekg(0, std::ios::beg);
|
|
|
|
std::vector<std::byte> buffer(static_cast<std::size_t>(size));
|
2024-04-12 07:38:14 +08:00
|
|
|
[[maybe_unused]] const auto& result = file.read(reinterpret_cast<char*>(buffer.data()),
|
|
|
|
static_cast<std::streamsize>(size));
|
2024-04-12 08:13:19 +08:00
|
|
|
assert(result);
|
|
|
|
return buffer;
|
|
|
|
}
|