From b81a3088c57d384f67f4498cca29c9797eff33a8 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Mon, 4 Nov 2024 17:03:46 +0200 Subject: [PATCH 1/3] RymlConverters for various pieces of math + tests --- openVulkanoCpp/Extensions/RymlConverters.hpp | 137 ++++++++++ openVulkanoCpp/Math/RGB565.hpp | 6 +- tests/Extensions/RymlConverters.cpp | 270 +++++++++++++++++++ 3 files changed, 410 insertions(+), 3 deletions(-) diff --git a/openVulkanoCpp/Extensions/RymlConverters.hpp b/openVulkanoCpp/Extensions/RymlConverters.hpp index 268d9cc..29748dc 100644 --- a/openVulkanoCpp/Extensions/RymlConverters.hpp +++ b/openVulkanoCpp/Extensions/RymlConverters.hpp @@ -10,6 +10,13 @@ #include "Math/Math.hpp" #include "Math/AABB.hpp" #include "Math/Pose.hpp" +#include "Math/DenseVector3i.hpp" +#include "Math/Int24.hpp" +#include "Math/Range.hpp" +#include "Math/RGB10A2.hpp" +#include "Math/RGB565.hpp" +#include "Math/RGBA5551.hpp" +#include "Math/Timestamp.hpp" #include #include #include @@ -142,4 +149,134 @@ namespace c4 uuid->assign(buf.str); return true; } + + template + inline size_t to_chars( + ryml::substr buf, + const OpenVulkano::Math::DenseVector3i& vec) + { + return ryml::format(buf, "({},{},{})", vec.X(), vec.Y(), vec.Z()); + } + + template + inline bool + from_chars(ryml::csubstr buf, + OpenVulkano::Math::DenseVector3i* vec) + { + int x, y, z; + size_t ret = ryml::unformat(buf, "({},{},{})", x, y, z); + if (ret != ryml::yml::npos) + { + *vec = DenseVector3i(x, y, z); + return true; + } + return false; + } + + size_t to_chars(c4::substr buf, const OpenVulkano::int24& value) + { + int intValue = static_cast(value); + return ryml::format(buf, "{}", intValue); + } + + bool from_chars(c4::csubstr buf, OpenVulkano::int24* value) + { + int intValue; + size_t ret = ryml::unformat(buf, "{}", intValue); + if (ret != ryml::yml::npos) + { + *value = OpenVulkano::int24(intValue); + return true; + } + return false; + } + + template size_t to_chars(c4::substr buf, const OpenVulkano::Math::Range& range) + { + return ryml::format(buf, "[{},{}]", range.GetMin(), range.GetMax()); + } + + template bool from_chars(c4::csubstr buf, OpenVulkano::Math::Range* range) + { + T minVal, maxVal; + size_t ret = ryml::unformat(buf, "[{},{}]", minVal, maxVal); + if (ret != ryml::yml::npos) + { + *range = Range(minVal, maxVal); + return true; + } + return false; + } + + template size_t to_chars(c4::substr buf, const OpenVulkano::Math::RGB10A2& color) + { + return ryml::format(buf, "[{},{},{},{}]", color.r, color.g, color.b, color.a); + } + + template bool from_chars(c4::csubstr buf, OpenVulkano::Math::RGB10A2* color) + { + T r, g, b, a; + size_t ret = ryml::unformat(buf, "[{},{},{},{}]", r, g, b, a); + if (ret != ryml::yml::npos) + { + color->r = r; + color->g = g; + color->b = b; + color->a = a; + return true; + } + return false; + } + + size_t to_chars(ryml::substr buf, const OpenVulkano::Math::RGB565& rgb) + { + return ryml::format(buf, "[{},{},{}]", rgb.r, rgb.g, rgb.b); + } + + bool from_chars(ryml::csubstr buf, OpenVulkano::Math::RGB565* rgb) + { + int r, g, b; + size_t ret = ryml::unformat (buf, "[{},{},{}]", r, g, b); + rgb->r = r; + rgb->g = g; + rgb->b = b; + return ret != ryml::yml::npos; + } + + size_t to_chars(c4::substr buf, const OpenVulkano::Math::RGBA5551& color) + { + return ryml::format(buf, "[{},{},{},{}]", color.r, color.g, color.b, color.a); + } + + bool from_chars(c4::csubstr buf, OpenVulkano::Math::RGBA5551* color) + { + int r, g, b, a; + size_t ret = ryml::unformat(buf, "[{},{},{},{}]", r, g, b, a); + if (ret != ryml::yml::npos) + { + color->r = r; + color->g = g; + color->b = b; + color->a = a; + return true; + } + return false; + } + + size_t to_chars(c4::substr buf, const OpenVulkano::Math::Timestamp& ts) + { + return ryml::format(buf, "{}", ts.GetNanos()); + } + + bool from_chars(c4::csubstr buf, OpenVulkano::Math::Timestamp* ts) + { + uint64_t nanos; + size_t ret = ryml::unformat(buf, "{}", nanos); + if (ret != ryml::yml::npos) + { + *ts = OpenVulkano::Math::Timestamp(nanos); + return true; + } + return false; + } } \ No newline at end of file diff --git a/openVulkanoCpp/Math/RGB565.hpp b/openVulkanoCpp/Math/RGB565.hpp index 7b1977e..f4aacd6 100644 --- a/openVulkanoCpp/Math/RGB565.hpp +++ b/openVulkanoCpp/Math/RGB565.hpp @@ -80,9 +80,9 @@ namespace OpenVulkano::Math { } - uint8_t GetR() { return Unmake5(r); } - uint8_t GetG() { return Unmake6(g); } - uint8_t GetB() { return Unmake5(b); } + uint8_t GetR() const { return Unmake5(r); } + uint8_t GetG() const { return Unmake6(g); } + uint8_t GetB() const { return Unmake5(b); } template, bool> = true> Math::Vector3 Get3() diff --git a/tests/Extensions/RymlConverters.cpp b/tests/Extensions/RymlConverters.cpp index 7d8ae03..f49d97c 100644 --- a/tests/Extensions/RymlConverters.cpp +++ b/tests/Extensions/RymlConverters.cpp @@ -172,3 +172,273 @@ TEST_CASE("UUID to_chars and from_chars", "[RymlConverters]") REQUIRE(from_chars("123e4567-e89b-12d3-a456-426655440000", &parsed_uuid)); REQUIRE(parsed_uuid.string() == uuid.string()); } + +TEST_CASE("DenseVector3i to_chars and from_chars", "[RymlConverters]") +{ + using MyDenseVector3i = DenseVector3i; + MyDenseVector3i vec(12, -5, 7); + char buffer[64]; + + size_t len = to_chars(ryml::substr(buffer, sizeof(buffer)), vec); + REQUIRE(len > 0); + + std::string expected = "(12,-5,7)"; + REQUIRE(std::string(buffer, len) == expected); + + std::string serialized = "(12,-5,7)"; + MyDenseVector3i deserialized_vec(0, 0, 0); + + bool success = from_chars(ryml::csubstr(serialized.c_str(), serialized.size()), &deserialized_vec); + REQUIRE(success); + + REQUIRE(deserialized_vec.X() == 12); + REQUIRE(deserialized_vec.Y() == -5); + REQUIRE(deserialized_vec.Z() == 7); + + len = to_chars(ryml::substr(buffer, sizeof(buffer)), vec); + + MyDenseVector3i roundtrip_vec(0, 0, 0); + success = from_chars(ryml::csubstr(buffer, len), &roundtrip_vec); + REQUIRE(success); + + REQUIRE(roundtrip_vec.X() == vec.X()); + REQUIRE(roundtrip_vec.Y() == vec.Y()); + REQUIRE(roundtrip_vec.Z() == vec.Z()); +} + +TEST_CASE("int24 to_chars and from_chars", "[RymlConverters]") +{ + char buffer[20]; + int24 originalValue = 1234567; + c4::substr buf(buffer); + + size_t written = to_chars(buf, originalValue); + REQUIRE(written > 0); + REQUIRE(std::string(buffer, written) == "1234567"); + + { + int24 parsedValue; + c4::csubstr buf("1234567"); + bool success = from_chars(buf, &parsedValue); + REQUIRE(success); + REQUIRE(static_cast(parsedValue) == 1234567); + } + + originalValue = -7654321; + written = to_chars(buf, originalValue); + REQUIRE(written > 0); + REQUIRE(std::string(buffer, written) == "-7654321"); + + { + int24 parsedValue; + c4::csubstr buf("-7654321"); + bool success = from_chars(buf, &parsedValue); + REQUIRE(success); + REQUIRE(static_cast(parsedValue) == -7654321); + } +} + +TEST_CASE("Range serialization and deserialization", "[RymlConverters]") +{ + char buffer[30]; + c4::substr buf(buffer); + + SECTION("Serialization") + { + Range range(5, 15); + size_t written = to_chars(buf, range); + REQUIRE(written > 0); + REQUIRE(std::string(buffer, written) == "[5,15]"); + } + + SECTION("Deserialization") + { + Range range; + c4::csubstr buf("[5, 15]"); + bool success = from_chars(buf, &range); + REQUIRE(success); + REQUIRE(range.GetMin() == 5); + REQUIRE(range.GetMax() == 15); + } + + SECTION("Negative Range") + { + Range range(-10, -2); + size_t written = to_chars(buf, range); + REQUIRE(written > 0); + REQUIRE(std::string(buffer, written) == "[-10,-2]"); + + Range parsedRange; + c4::csubstr negBuf("[-10,-2]"); + bool success = from_chars(negBuf, &parsedRange); + REQUIRE(success); + REQUIRE(parsedRange.GetMin() == -10); + REQUIRE(parsedRange.GetMax() == -2); + } + + SECTION("Floating Point Range") + { + Range range(1.5, 3.75); + size_t written = to_chars(buf, range); + REQUIRE(written > 0); + REQUIRE(std::string(buffer, written) == "[1.5,3.75]"); + + Range parsedRange; + c4::csubstr floatBuf("[1.5,3.75]"); + bool success = from_chars(floatBuf, &parsedRange); + REQUIRE(success); + REQUIRE(parsedRange.GetMin() == 1.5); + REQUIRE(parsedRange.GetMax() == 3.75); + } +} + +TEST_CASE("RGB10A2 serialization and deserialization", "[RymlConverters]") +{ + char buffer[50]; + c4::substr buf(buffer); + + SECTION("Serialization") + { + RGB10A2 color(0); + color.r = 512; + color.g = 768; + color.b = 256; + color.a = 3; + + size_t written = to_chars(buf, color); + REQUIRE(written > 0); + REQUIRE(std::string(buffer, written) == "[512,768,256,3]"); + } + + SECTION("Deserialization") + { + RGB10A2 color; + c4::csubstr buf("[512,768,256,3]"); + bool success = from_chars(buf, &color); + REQUIRE(success); + REQUIRE(color.r == 512); + REQUIRE(color.g == 768); + REQUIRE(color.b == 256); + REQUIRE(color.a == 3); + } + + SECTION("Boundary Values") + { + RGB10A2 color; + color.r = RGB10A2::MAX_VALUE; + color.g = RGB10A2::MAX_VALUE; + color.b = RGB10A2::MAX_VALUE; + color.a = RGB10A2::MAX_ALPHA_VALUE; + + size_t written = to_chars(buf, color); + REQUIRE(written > 0); + REQUIRE(std::string(buffer, written) + == "[" + std::to_string(RGB10A2::MAX_VALUE) + "," + + std::to_string(RGB10A2::MAX_VALUE) + "," + std::to_string(RGB10A2::MAX_VALUE) + + "," + std::to_string(RGB10A2::MAX_ALPHA_VALUE) + "]"); + + RGB10A2 parsedColor; + c4::csubstr boundaryBuf(buffer, written); + bool success = from_chars(boundaryBuf, &parsedColor); + REQUIRE(success); + REQUIRE(parsedColor.r == RGB10A2::MAX_VALUE); + REQUIRE(parsedColor.g == RGB10A2::MAX_VALUE); + REQUIRE(parsedColor.b == RGB10A2::MAX_VALUE); + REQUIRE(parsedColor.a == RGB10A2::MAX_ALPHA_VALUE); + } + + SECTION("Negative Values (Signed Type)") + { + RGB10A2 color; + color.r = -512; + color.g = -256; + color.b = -128; + color.a = -1; + + size_t written = to_chars(buf, color); + REQUIRE(written > 0); + REQUIRE(std::string(buffer, written) == "[-512,-256,-128,-1]"); + + RGB10A2 parsedColor; + c4::csubstr negBuf(buffer, written); + bool success = from_chars(negBuf, &parsedColor); + REQUIRE(success); + REQUIRE(parsedColor.r == -512); + REQUIRE(parsedColor.g == -256); + REQUIRE(parsedColor.b == -128); + REQUIRE(parsedColor.a == -1); + } +} + +TEST_CASE("RGB565 Serialization and Deserialization", "[RymlConverters]") +{ + Vector3 color { 255, 128, 64 }; + RGB565 rgb(color); + + char buffer[50]; + c4::substr buf(buffer); + size_t written = to_chars(buffer, rgb); + REQUIRE(written > 0); + + RGB565 rgbDeserialized; + bool success = from_chars(buffer, &rgbDeserialized); + REQUIRE(success); + + REQUIRE(rgb.GetR() == rgbDeserialized.GetR()); + REQUIRE(rgb.GetG() == rgbDeserialized.GetG()); + REQUIRE(rgb.GetB() == rgbDeserialized.GetB()); +} + +TEST_CASE("RGBA5551 serialization and deserialization", "[RymlConverters]") +{ + char buffer[50]; + c4::substr buf(buffer); + + SECTION("Serialization") + { + RGBA5551 color; + color.r = 31; + color.g = 31; + color.b = 31; + color.a = 1; + + size_t written = to_chars(buf, color); + REQUIRE(written > 0); + REQUIRE(std::string(buffer, written) == "[31,31,31,1]"); + } + + SECTION("Deserialization") + { + RGBA5551 color; + c4::csubstr buf("[31,31,31,1]"); + bool success = from_chars(buf, &color); + REQUIRE(success); + REQUIRE(color.r == 31); + REQUIRE(color.g == 31); + REQUIRE(color.b == 31); + REQUIRE(color.a == 1); + } +} + +TEST_CASE("Timestamp serialization and deserialization", "[RymlConverters]") +{ + char buffer[50]; + c4::substr buf(buffer); + + SECTION("Serialization") + { + Timestamp ts((uint64_t)123); + size_t written = to_chars(buf, ts); + REQUIRE(written > 0); + REQUIRE(std::string(buffer, written) == "123"); + } + + SECTION("Deserialization") + { + Timestamp ts; + c4::csubstr buf("123"); + bool success = from_chars(buf, &ts); + REQUIRE(success); + REQUIRE(ts.GetNanos() == 123); + } +} \ No newline at end of file From 596de3cd2eeb32ca8d292c0409f46526acd31eaa Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Mon, 4 Nov 2024 17:04:19 +0200 Subject: [PATCH 2/3] YamlCppConverters for various pieces of math + tests --- .../Extensions/YamlCppConverters.hpp | 164 ++++++++++++++++- tests/Extensions/YamlCppConverters.cpp | 165 +++++++++++++----- 2 files changed, 287 insertions(+), 42 deletions(-) diff --git a/openVulkanoCpp/Extensions/YamlCppConverters.hpp b/openVulkanoCpp/Extensions/YamlCppConverters.hpp index 0286a12..58ffbd9 100644 --- a/openVulkanoCpp/Extensions/YamlCppConverters.hpp +++ b/openVulkanoCpp/Extensions/YamlCppConverters.hpp @@ -9,6 +9,13 @@ #include "Base/UUID.hpp" #include "Math/AABB.hpp" #include "Math/Pose.hpp" +#include "Math/DenseVector3i.hpp" +#include "Math/Int24.hpp" +#include "Math/Range.hpp" +#include "Math/RGB10A2.hpp" +#include "Math/RGB565.hpp" +#include "Math/RGBA5551.hpp" +#include "Math/Timestamp.hpp" #include #include #include @@ -246,4 +253,159 @@ namespace YAML return false; } }; -} + + template + struct convert> + { + static Node encode(const OpenVulkano::Math::DenseVector3i& v) + { + return Node(fmt::format("({},{},{})", v.X(), v.Y(), v.Z())); + } + + static bool decode(const Node& node, OpenVulkano::Math::DenseVector3i& v) + { + if (node.IsScalar()) + { + int x, y, z; + size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "({},{},{})", x, y, z); + v = OpenVulkano::Math::DenseVector3i(x, y, z); + return ret != c4::csubstr::npos; + } + return false; + } + }; + + template<> + struct convert + { + static Node encode(const OpenVulkano::int24& v) + { + return Node(fmt::format("{}", static_cast(v))); + } + + static bool decode(const Node& node, OpenVulkano::int24& v) + { + if (node.IsScalar()) + { + int value; + size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "{}", value); + v = value; + return ret != c4::csubstr::npos; + } + return false; + } + }; + + template + struct convert> + { + static Node encode(const OpenVulkano::Math::Range& r) + { + return Node(fmt::format("[{},{}]", r.GetMin(), r.GetMax())); + } + + static bool decode(const Node& node, OpenVulkano::Math::Range& r) + { + if (node.IsScalar()) + { + T minVal, maxVal; + size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "[{},{}]", minVal, maxVal); + r = OpenVulkano::Math::Range(minVal, maxVal); + return ret != c4::csubstr::npos; + } + return false; + } + }; + + template + struct convert> + { + static Node encode(const OpenVulkano::Math::RGB10A2& c) + { + return Node(fmt::format("[{},{},{},{}]", c.r, c.g, c.b, c.a)); + } + + static bool decode(const Node& node, OpenVulkano::Math::RGB10A2& c) + { + if (node.IsScalar()) + { + T r, g, b, a; + size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "[{},{},{},{}]", r, g, b, a); + c.r = r; + c.g = g; + c.b = b; + c.a = a; + return ret != c4::csubstr::npos; + } + return false; + } + }; + + template<> + struct convert + { + static Node encode(const OpenVulkano::Math::RGB565& c) + { + return Node(fmt::format("[{},{},{}]", c.r, c.g, c.b)); + } + + static bool decode(const Node& node, OpenVulkano::Math::RGB565& c) + { + if (node.IsScalar()) + { + int r, g, b; + size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "[{},{},{}]", r, g, b); + c.r = r; + c.g = g; + c.b = b; + return ret != c4::csubstr::npos; + } + return false; + } + }; + + template<> + struct convert + { + static Node encode(const OpenVulkano::Math::RGBA5551& c) + { + return Node(fmt::format("[{},{},{},{}]", c.r, c.g, c.b, c.a)); + } + + static bool decode(const Node& node, OpenVulkano::Math::RGBA5551& c) + { + if (node.IsScalar()) + { + int r, g, b, a; + size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "[{},{},{},{}]", r, g, b, a); + c.r = r; + c.g = g; + c.b = b; + c.a = a; + return ret != c4::csubstr::npos; + } + return false; + } + }; + + template<> + struct convert + { + static Node encode(const OpenVulkano::Math::Timestamp& ts) + { + return Node(fmt::format("{}", ts.GetNanos())); + } + + static bool decode(const Node& node, OpenVulkano::Math::Timestamp& ts) + { + if (node.IsScalar()) + { + uint64_t nanos; + size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "{}", nanos); + ts = OpenVulkano::Math::Timestamp(nanos); + return ret != c4::csubstr::npos; + } + return false; + } + }; +} \ No newline at end of file diff --git a/tests/Extensions/YamlCppConverters.cpp b/tests/Extensions/YamlCppConverters.cpp index 5d0b257..dab631f 100644 --- a/tests/Extensions/YamlCppConverters.cpp +++ b/tests/Extensions/YamlCppConverters.cpp @@ -19,9 +19,9 @@ TEST_CASE("UUID encoding and decoding", "[YamlCppConverters]") REQUIRE(node.IsScalar()); REQUIRE(node.as() == uuid.string()); - UUID decoded_uuid; - REQUIRE(YAML::convert::decode(node, decoded_uuid)); - REQUIRE(decoded_uuid == uuid); + UUID decodedUuid; + REQUIRE(YAML::convert::decode(node, decodedUuid)); + REQUIRE(decodedUuid == uuid); } TEST_CASE("AABB encoding and decoding", "[YamlCppConverters]") @@ -30,10 +30,10 @@ TEST_CASE("AABB encoding and decoding", "[YamlCppConverters]") YAML::Node node = YAML::convert::encode(bbox); REQUIRE(node.IsScalar()); - Math::AABB decoded_bbox; - REQUIRE(YAML::convert::decode(node, decoded_bbox)); - REQUIRE(decoded_bbox.min == bbox.min); - REQUIRE(decoded_bbox.max == bbox.max); + Math::AABB decodedBbox; + REQUIRE(YAML::convert::decode(node, decodedBbox)); + REQUIRE(decodedBbox.min == bbox.min); + REQUIRE(decodedBbox.max == bbox.max); } TEST_CASE("PoseF encoding and decoding", "[YamlCppConverters]") @@ -44,10 +44,10 @@ TEST_CASE("PoseF encoding and decoding", "[YamlCppConverters]") YAML::Node node = YAML::convert::encode(pose); REQUIRE(node.IsScalar()); - Math::PoseF decoded_pose; - REQUIRE(YAML::convert::decode(node, decoded_pose)); - REQUIRE(decoded_pose.GetPosition() == pose.GetPosition()); - REQUIRE(decoded_pose.GetOrientation() == pose.GetOrientation()); + Math::PoseF decodedPose; + REQUIRE(YAML::convert::decode(node, decodedPose)); + REQUIRE(decodedPose.GetPosition() == pose.GetPosition()); + REQUIRE(decodedPose.GetOrientation() == pose.GetOrientation()); } TEST_CASE("Vector2 encoding and decoding", "[YamlCppConverters]") @@ -56,9 +56,9 @@ TEST_CASE("Vector2 encoding and decoding", "[YamlCppConverters]") YAML::Node node = YAML::convert>::encode(vec); REQUIRE(node.IsScalar()); - Math::Vector2 decoded_vec; - REQUIRE(YAML::convert>::decode(node, decoded_vec)); - REQUIRE(decoded_vec == vec); + Math::Vector2 decodedVec; + REQUIRE(YAML::convert>::decode(node, decodedVec)); + REQUIRE(decodedVec == vec); } TEST_CASE("Vector3 encoding and decoding", "[YamlCppConverters]") @@ -67,9 +67,9 @@ TEST_CASE("Vector3 encoding and decoding", "[YamlCppConverters]") YAML::Node node = YAML::convert>::encode(vec); REQUIRE(node.IsScalar()); - Math::Vector3 decoded_vec; - REQUIRE(YAML::convert>::decode(node, decoded_vec)); - REQUIRE(decoded_vec == vec); + Math::Vector3 decodedVec; + REQUIRE(YAML::convert>::decode(node, decodedVec)); + REQUIRE(decodedVec == vec); } TEST_CASE("Vector4 encoding and decoding", "[YamlCppConverters]") @@ -78,9 +78,9 @@ TEST_CASE("Vector4 encoding and decoding", "[YamlCppConverters]") YAML::Node node = YAML::convert>::encode(vec); REQUIRE(node.IsScalar()); - Math::Vector4 decoded_vec; - REQUIRE(YAML::convert>::decode(node, decoded_vec)); - REQUIRE(decoded_vec == vec); + Math::Vector4 decodedVec; + REQUIRE(YAML::convert>::decode(node, decodedVec)); + REQUIRE(decodedVec == vec); } TEST_CASE("Matrix3 encoding and decoding", "[YamlCppConverters]") @@ -89,9 +89,9 @@ TEST_CASE("Matrix3 encoding and decoding", "[YamlCppConverters]") YAML::Node node = YAML::convert>::encode(mat); REQUIRE(node.IsScalar()); - Math::Matrix3 decoded_mat; - REQUIRE(YAML::convert>::decode(node, decoded_mat)); - REQUIRE(decoded_mat == mat); + Math::Matrix3 decodedMat; + REQUIRE(YAML::convert>::decode(node, decodedMat)); + REQUIRE(decodedMat == mat); } TEST_CASE("Matrix4 encoding and decoding", "[YamlCppConverters]") @@ -103,9 +103,9 @@ TEST_CASE("Matrix4 encoding and decoding", "[YamlCppConverters]") YAML::Node node = YAML::convert>::encode(mat); REQUIRE(node.IsScalar()); - Math::Matrix4 decoded_mat; - REQUIRE(YAML::convert>::decode(node, decoded_mat)); - REQUIRE(decoded_mat == mat); + Math::Matrix4 decodedMat; + REQUIRE(YAML::convert>::decode(node, decodedMat)); + REQUIRE(decodedMat == mat); } TEST_CASE("Vector2_SIMD encoding and decoding", "[YamlCppConverters]") @@ -114,9 +114,9 @@ TEST_CASE("Vector2_SIMD encoding and decoding", "[YamlCppConverters]") YAML::Node node = YAML::convert>::encode(vec); REQUIRE(node.IsScalar()); - Math::Vector2_SIMD decoded_vec; - REQUIRE(YAML::convert>::decode(node, decoded_vec)); - REQUIRE(decoded_vec == vec); + Math::Vector2_SIMD decodedVec; + REQUIRE(YAML::convert>::decode(node, decodedVec)); + REQUIRE(decodedVec == vec); } TEST_CASE("Vector3_SIMD encoding and decoding", "[YamlCppConverters]") @@ -125,9 +125,9 @@ TEST_CASE("Vector3_SIMD encoding and decoding", "[YamlCppConverters]") YAML::Node node = YAML::convert>::encode(vec); REQUIRE(node.IsScalar()); - Math::Vector3_SIMD decoded_vec; - REQUIRE(YAML::convert>::decode(node, decoded_vec)); - REQUIRE(decoded_vec == vec); + Math::Vector3_SIMD decodedVec; + REQUIRE(YAML::convert>::decode(node, decodedVec)); + REQUIRE(decodedVec == vec); } TEST_CASE("Vector4_SIMD encoding and decoding", "[YamlCppConverters]") @@ -136,9 +136,9 @@ TEST_CASE("Vector4_SIMD encoding and decoding", "[YamlCppConverters]") YAML::Node node = YAML::convert>::encode(vec); REQUIRE(node.IsScalar()); - Math::Vector4_SIMD decoded_vec; - REQUIRE(YAML::convert>::decode(node, decoded_vec)); - REQUIRE(decoded_vec == vec); + Math::Vector4_SIMD decodedVec; + REQUIRE(YAML::convert>::decode(node, decodedVec)); + REQUIRE(decodedVec == vec); } TEST_CASE("Matrix3_SIMD encoding and decoding", "[YamlCppConverters]") @@ -147,9 +147,9 @@ TEST_CASE("Matrix3_SIMD encoding and decoding", "[YamlCppConverters]") YAML::Node node = YAML::convert>::encode(mat); REQUIRE(node.IsScalar()); - Math::Matrix3_SIMD decoded_mat; - REQUIRE(YAML::convert>::decode(node, decoded_mat)); - REQUIRE(decoded_mat == mat); + Math::Matrix3_SIMD decodedMat; + REQUIRE(YAML::convert>::decode(node, decodedMat)); + REQUIRE(decodedMat == mat); } TEST_CASE("Matrix4_SIMD encoding and decoding", "[YamlCppConverters]") @@ -161,7 +161,90 @@ TEST_CASE("Matrix4_SIMD encoding and decoding", "[YamlCppConverters]") YAML::Node node = YAML::convert>::encode(mat); REQUIRE(node.IsScalar()); - Math::Matrix4_SIMD decoded_mat; - REQUIRE(YAML::convert>::decode(node, decoded_mat)); - REQUIRE(decoded_mat == mat); + Math::Matrix4_SIMD decodedMat; + REQUIRE(YAML::convert>::decode(node, decodedMat)); + REQUIRE(decodedMat == mat); } + +TEST_CASE("DenseVector3i encoding and decoding", "[YamlCppConverters]") +{ + OpenVulkano::Math::DenseVector3i vec { 1, 2, 3 }; + YAML::Node node = YAML::convert>::encode(vec); + REQUIRE(node.IsScalar()); + + OpenVulkano::Math::DenseVector3i decodedVec(0, 0, 0); + REQUIRE(YAML::convert>::decode(node, decodedVec)); + REQUIRE(decodedVec == vec); +} + +TEST_CASE("int24 encoding and decoding", "[YamlCppConverters]") +{ + OpenVulkano::int24 value(42); + YAML::Node node = YAML::convert::encode(value); + REQUIRE(node.IsScalar()); + + OpenVulkano::int24 decodedValue; + REQUIRE(YAML::convert::decode(node, decodedValue)); + REQUIRE(decodedValue == value); +} + +TEST_CASE("Range encoding and decoding", "[YamlCppConverters]") +{ + OpenVulkano::Math::Range range(10, 20); + YAML::Node node = YAML::convert>::encode(range); + REQUIRE(node.IsScalar()); + + OpenVulkano::Math::Range decodedRange; + REQUIRE(YAML::convert>::decode(node, decodedRange)); + REQUIRE(decodedRange.GetMin() == range.GetMin()); + REQUIRE(decodedRange.GetMax() == range.GetMax()); +} + +TEST_CASE("RGB10A2 encoding and decoding", "[YamlCppConverters]") +{ + OpenVulkano::Math::RGB10A2 color; + color.Set(OpenVulkano::Math::Vector4i(1023, 512, 256, 3)); + + YAML::Node node = YAML::convert>::encode(color); + REQUIRE(node.IsScalar()); + + OpenVulkano::Math::RGB10A2 decodedColor; + REQUIRE(YAML::convert>::decode(node, decodedColor)); + REQUIRE(decodedColor == color); +} + +TEST_CASE("RGB565 encoding and decoding", "[YamlCppConverters]") +{ + OpenVulkano::Math::RGB565 color; + color.Set(OpenVulkano::Math::Vector3i(31, 63, 31)); + + YAML::Node node = YAML::convert::encode(color); + REQUIRE(node.IsScalar()); + + OpenVulkano::Math::RGB565 decodedColor; + REQUIRE(YAML::convert::decode(node, decodedColor)); + REQUIRE(decodedColor == color); +} + +TEST_CASE("RGBA5551 encoding and decoding", "[YamlCppConverters]") +{ + OpenVulkano::Math::RGBA5551 color(OpenVulkano::Math::Vector4i(31, 31, 31, 1)); + + YAML::Node node = YAML::convert::encode(color); + REQUIRE(node.IsScalar()); + + OpenVulkano::Math::RGBA5551 decodedColor; + REQUIRE(YAML::convert::decode(node, decodedColor)); + REQUIRE(decodedColor == color); +} + +TEST_CASE("Timestamp encoding and decoding", "[YamlCppConverters]") +{ + OpenVulkano::Math::Timestamp timestamp(uint64_t(1234567890)); + YAML::Node node = YAML::convert::encode(timestamp); + REQUIRE(node.IsScalar()); + + OpenVulkano::Math::Timestamp decodedTimestamp; + REQUIRE(YAML::convert::decode(node, decodedTimestamp)); + REQUIRE(decodedTimestamp == timestamp); +} \ No newline at end of file From 73250e0b377819a3c243341bc07eb3863b75db08 Mon Sep 17 00:00:00 2001 From: Vladyslav Baranovskyi Date: Thu, 7 Nov 2024 14:53:52 +0200 Subject: [PATCH 3/3] Using DenseVector and Range properly, deleted unused code from RGB565 test --- openVulkanoCpp/Extensions/RymlConverters.hpp | 4 ++-- tests/RGB565.cpp | 4 ---- 2 files changed, 2 insertions(+), 6 deletions(-) diff --git a/openVulkanoCpp/Extensions/RymlConverters.hpp b/openVulkanoCpp/Extensions/RymlConverters.hpp index 29748dc..fac9ec4 100644 --- a/openVulkanoCpp/Extensions/RymlConverters.hpp +++ b/openVulkanoCpp/Extensions/RymlConverters.hpp @@ -167,7 +167,7 @@ namespace c4 size_t ret = ryml::unformat(buf, "({},{},{})", x, y, z); if (ret != ryml::yml::npos) { - *vec = DenseVector3i(x, y, z); + *vec = OpenVulkano::Math::DenseVector3i(x, y, z); return true; } return false; @@ -202,7 +202,7 @@ namespace c4 size_t ret = ryml::unformat(buf, "[{},{}]", minVal, maxVal); if (ret != ryml::yml::npos) { - *range = Range(minVal, maxVal); + *range = OpenVulkano::Math::Range(minVal, maxVal); return true; } return false; diff --git a/tests/RGB565.cpp b/tests/RGB565.cpp index f2642d1..54be00d 100644 --- a/tests/RGB565.cpp +++ b/tests/RGB565.cpp @@ -184,10 +184,6 @@ TEST_CASE("test_rgb565_operators", "[RGB565]") rgb1 -= delta; - uint8_t r = rgb1.GetR(); - uint8_t g = rgb1.GetG(); - uint8_t b = rgb1.GetB(); - REQUIRE(rgb1.GetR() == 82); REQUIRE(rgb1.GetG() == 24); REQUIRE(rgb1.GetB() == 0); // Expect to clamp here