Merge pull request 'Extensions updates + tests' (#154) from extensions into master
Reviewed-on: https://git.madvoxel.net/OpenVulkano/OpenVulkano/pulls/154 Reviewed-by: Georg Hagen <georg.hagen@madvoxel.com>
This commit is contained in:
@@ -6,6 +6,7 @@
|
|||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include "Base/UUID.hpp"
|
||||||
#include "Math/Math.hpp"
|
#include "Math/Math.hpp"
|
||||||
#include "Math/AABB.hpp"
|
#include "Math/AABB.hpp"
|
||||||
#include "Math/Pose.hpp"
|
#include "Math/Pose.hpp"
|
||||||
@@ -56,7 +57,7 @@ namespace c4
|
|||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
size_t to_chars(ryml::substr buf, const OpenVulkano::Math::Pose<T>& pose)
|
size_t to_chars(ryml::substr buf, const OpenVulkano::Math::Pose<T>& pose)
|
||||||
{ return ryml::format(buf, "({},{},{}),({},{},{},{})", pose.m_position.x, pose.m_position.y, pose.m_position.z, pose.m_orientation.x, pose.m_orientation.y, pose.m_orientation.z, pose.m_orientation.w); }
|
{ return ryml::format(buf, "({},{},{}),({},{},{},{})", pose.GetPosition().x, pose.GetPosition().y, pose.GetPosition().z, pose.GetOrientation().x, pose.GetOrientation().y, pose.GetOrientation().z, pose.GetOrientation().w); }
|
||||||
|
|
||||||
template<class T>
|
template<class T>
|
||||||
bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Vector2<T>* v)
|
bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Vector2<T>* v)
|
||||||
@@ -127,7 +128,18 @@ namespace c4
|
|||||||
template<class T>
|
template<class T>
|
||||||
bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Pose<T>* pose)
|
bool from_chars(ryml::csubstr buf, OpenVulkano::Math::Pose<T>* pose)
|
||||||
{
|
{
|
||||||
size_t ret = ryml::unformat(buf, "({},{},{}),({},{},{},{})", pose->m_position.x, pose->m_position.y, pose->m_position.z, pose->m_orientation.x, pose->m_orientation.y, pose->m_orientation.z, pose->m_orientation.w);
|
size_t ret = ryml::unformat(buf, "({},{},{}),({},{},{},{})", pose->GetPosition().x, pose->GetPosition().y, pose->GetPosition().z, pose->GetOrientation().x, pose->GetOrientation().y, pose->GetOrientation().z, pose->GetOrientation().w);
|
||||||
return ret != ryml::yml::npos;
|
return ret != ryml::yml::npos;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline size_t to_chars(ryml::substr buf, const OpenVulkano::UUID& uuid)
|
||||||
|
{
|
||||||
|
return ryml::format(buf, "{}", uuid.string());
|
||||||
|
}
|
||||||
|
|
||||||
|
inline bool from_chars(ryml::csubstr buf, OpenVulkano::UUID* uuid)
|
||||||
|
{
|
||||||
|
uuid->assign(buf.str);
|
||||||
|
return true;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
@@ -71,4 +71,179 @@ namespace YAML
|
|||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct convert<OpenVulkano::Math::Vector2<T>>
|
||||||
|
{
|
||||||
|
static Node encode(const OpenVulkano::Math::Vector2<T>& v)
|
||||||
|
{
|
||||||
|
return Node(fmt::format("({},{})", v.x, v.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool decode(const Node& node, OpenVulkano::Math::Vector2<T>& v)
|
||||||
|
{
|
||||||
|
if (node.IsScalar())
|
||||||
|
{
|
||||||
|
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "({},{})", v.x, v.y);
|
||||||
|
return ret != c4::csubstr::npos;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct convert<OpenVulkano::Math::Vector3<T>>
|
||||||
|
{
|
||||||
|
static Node encode(const OpenVulkano::Math::Vector3<T>& v)
|
||||||
|
{
|
||||||
|
return Node(fmt::format("({},{},{})", v.x, v.y, v.z));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool decode(const Node& node, OpenVulkano::Math::Vector3<T>& v)
|
||||||
|
{
|
||||||
|
if (node.IsScalar())
|
||||||
|
{
|
||||||
|
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "({},{},{})", v.x, v.y, v.z);
|
||||||
|
return ret != c4::csubstr::npos;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct convert<OpenVulkano::Math::Vector4<T>>
|
||||||
|
{
|
||||||
|
static Node encode(const OpenVulkano::Math::Vector4<T>& v)
|
||||||
|
{
|
||||||
|
return Node(fmt::format("({},{},{},{})", v.x, v.y, v.z, v.w));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool decode(const Node& node, OpenVulkano::Math::Vector4<T>& v)
|
||||||
|
{
|
||||||
|
if (node.IsScalar())
|
||||||
|
{
|
||||||
|
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "({},{},{},{})", v.x, v.y, v.z, v.w);
|
||||||
|
return ret != c4::csubstr::npos;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct convert<OpenVulkano::Math::Vector2_SIMD<T>>
|
||||||
|
{
|
||||||
|
static Node encode(const OpenVulkano::Math::Vector2_SIMD<T>& v)
|
||||||
|
{
|
||||||
|
return Node(fmt::format("({},{})", v.x, v.y));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool decode(const Node& node, OpenVulkano::Math::Vector2_SIMD<T>& v)
|
||||||
|
{
|
||||||
|
if (node.IsScalar())
|
||||||
|
{
|
||||||
|
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "({},{})", v.x, v.y);
|
||||||
|
return ret != c4::csubstr::npos;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct convert<OpenVulkano::Math::Vector3_SIMD<T>>
|
||||||
|
{
|
||||||
|
static Node encode(const OpenVulkano::Math::Vector3_SIMD<T>& v)
|
||||||
|
{
|
||||||
|
return Node(fmt::format("({},{},{})", v.x, v.y, v.z));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool decode(const Node& node, OpenVulkano::Math::Vector3_SIMD<T>& v)
|
||||||
|
{
|
||||||
|
if (node.IsScalar())
|
||||||
|
{
|
||||||
|
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()), "({},{},{})", v.x, v.y, v.z);
|
||||||
|
return ret != c4::csubstr::npos;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct convert<OpenVulkano::Math::Matrix3<T>>
|
||||||
|
{
|
||||||
|
static Node encode(const OpenVulkano::Math::Matrix3<T>& mat)
|
||||||
|
{
|
||||||
|
return Node(fmt::format("(({},{},{}),({},{},{}),({},{},{}))",
|
||||||
|
mat[0][0], mat[0][1], mat[0][2],
|
||||||
|
mat[1][0], mat[1][1], mat[1][2],
|
||||||
|
mat[2][0], mat[2][1], mat[2][2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool decode(const Node& node, OpenVulkano::Math::Matrix3<T>& mat)
|
||||||
|
{
|
||||||
|
if (node.IsScalar())
|
||||||
|
{
|
||||||
|
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()),
|
||||||
|
"(({},{},{}),({},{},{}),({},{},{}))",
|
||||||
|
mat[0][0], mat[0][1], mat[0][2],
|
||||||
|
mat[1][0], mat[1][1], mat[1][2],
|
||||||
|
mat[2][0], mat[2][1], mat[2][2]);
|
||||||
|
return ret != c4::csubstr::npos;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct convert<OpenVulkano::Math::Matrix3_SIMD<T>>
|
||||||
|
{
|
||||||
|
static Node encode(const OpenVulkano::Math::Matrix3_SIMD<T>& mat)
|
||||||
|
{
|
||||||
|
return Node(fmt::format("(({},{},{}),({},{},{}),({},{},{}))",
|
||||||
|
mat[0][0], mat[0][1], mat[0][2],
|
||||||
|
mat[1][0], mat[1][1], mat[1][2],
|
||||||
|
mat[2][0], mat[2][1], mat[2][2]));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool decode(const Node& node, OpenVulkano::Math::Matrix3_SIMD<T>& mat)
|
||||||
|
{
|
||||||
|
if (node.IsScalar())
|
||||||
|
{
|
||||||
|
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()),
|
||||||
|
"(({},{},{}),({},{},{}),({},{},{}))",
|
||||||
|
mat[0][0], mat[0][1], mat[0][2],
|
||||||
|
mat[1][0], mat[1][1], mat[1][2],
|
||||||
|
mat[2][0], mat[2][1], mat[2][2]);
|
||||||
|
return ret != c4::csubstr::npos;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
|
|
||||||
|
template<typename T>
|
||||||
|
struct convert<OpenVulkano::Math::Matrix4<T>>
|
||||||
|
{
|
||||||
|
static Node encode(const OpenVulkano::Math::Matrix4<T>& mat)
|
||||||
|
{
|
||||||
|
return Node(fmt::format("(({},{},{},{}),({},{},{},{}),({},{},{},{}),({},{},{},{}))",
|
||||||
|
mat[0][0], mat[0][1], mat[0][2], mat[0][3],
|
||||||
|
mat[1][0], mat[1][1], mat[1][2], mat[1][3],
|
||||||
|
mat[2][0], mat[2][1], mat[2][2], mat[2][3],
|
||||||
|
mat[3][0], mat[3][1], mat[3][2], mat[3][3]));
|
||||||
|
}
|
||||||
|
|
||||||
|
static bool decode(const Node& node, OpenVulkano::Math::Matrix4<T>& mat)
|
||||||
|
{
|
||||||
|
if (node.IsScalar())
|
||||||
|
{
|
||||||
|
size_t ret = c4::unformat(c4::to_csubstr(node.Scalar().c_str()),
|
||||||
|
"(({},{},{},{}),({},{},{},{}),({},{},{},{}),({},{},{},{}))",
|
||||||
|
mat[0][0], mat[0][1], mat[0][2], mat[0][3],
|
||||||
|
mat[1][0], mat[1][1], mat[1][2], mat[1][3],
|
||||||
|
mat[2][0], mat[2][1], mat[2][2], mat[2][3],
|
||||||
|
mat[3][0], mat[3][1], mat[3][2], mat[3][3]);
|
||||||
|
return ret != c4::csubstr::npos;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
174
tests/Extensions/RymlConverters.cpp
Normal file
174
tests/Extensions/RymlConverters.cpp
Normal file
@@ -0,0 +1,174 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <catch2/catch_all.hpp>
|
||||||
|
|
||||||
|
#include "Extensions/RymlConverters.hpp"
|
||||||
|
|
||||||
|
using namespace OpenVulkano;
|
||||||
|
using namespace OpenVulkano::Math;
|
||||||
|
using namespace c4;
|
||||||
|
|
||||||
|
TEST_CASE("Vector2 to_chars and from_chars", "[RymlConverters]")
|
||||||
|
{
|
||||||
|
Vector2<float> vec2 { 1.1f, 2.2f };
|
||||||
|
char buffer[20] = {};
|
||||||
|
|
||||||
|
size_t written = to_chars(ryml::substr(buffer), vec2);
|
||||||
|
REQUIRE(written != ryml::yml::npos);
|
||||||
|
REQUIRE(std::string(buffer) == "(1.1,2.2)");
|
||||||
|
|
||||||
|
Vector2<float> parsed_vec2;
|
||||||
|
REQUIRE(from_chars("(1.1,2.2)", &parsed_vec2));
|
||||||
|
REQUIRE(parsed_vec2.x == 1.1f);
|
||||||
|
REQUIRE(parsed_vec2.y == 2.2f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Vector3 to_chars and from_chars", "[RymlConverters]")
|
||||||
|
{
|
||||||
|
Vector3<float> vec3 { 1.1f, 2.2f, 3.3f };
|
||||||
|
char buffer[30] = {};
|
||||||
|
|
||||||
|
size_t written = to_chars(ryml::substr(buffer), vec3);
|
||||||
|
REQUIRE(written != ryml::yml::npos);
|
||||||
|
REQUIRE(std::string(buffer) == "(1.1,2.2,3.3)");
|
||||||
|
|
||||||
|
Vector3<float> parsed_vec3;
|
||||||
|
REQUIRE(from_chars("(1.1,2.2,3.3)", &parsed_vec3));
|
||||||
|
REQUIRE(parsed_vec3.x == 1.1f);
|
||||||
|
REQUIRE(parsed_vec3.y == 2.2f);
|
||||||
|
REQUIRE(parsed_vec3.z == 3.3f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Vector4 to_chars and from_chars", "[RymlConverters]")
|
||||||
|
{
|
||||||
|
Vector4<float> vec4 { 1.1f, 2.2f, 3.3f, 4.4f };
|
||||||
|
char buffer[30] = {};
|
||||||
|
|
||||||
|
size_t written = to_chars(ryml::substr(buffer), vec4);
|
||||||
|
REQUIRE(written != ryml::yml::npos);
|
||||||
|
REQUIRE(std::string(buffer) == "(1.1,2.2,3.3,4.4)");
|
||||||
|
|
||||||
|
Vector4<float> parsed_vec4;
|
||||||
|
REQUIRE(from_chars("(1.1,2.2,3.3,4.4)", &parsed_vec4));
|
||||||
|
REQUIRE(parsed_vec4.x == 1.1f);
|
||||||
|
REQUIRE(parsed_vec4.y == 2.2f);
|
||||||
|
REQUIRE(parsed_vec4.z == 3.3f);
|
||||||
|
REQUIRE(parsed_vec4.w == 4.4f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Matrix3 to_chars and from_chars", "[RymlConverters]")
|
||||||
|
{
|
||||||
|
Matrix3<float> mat3 { { 1.1f, 2.2f, 3.3f }, { 4.4f, 5.5f, 6.6f }, { 7.7f, 8.8f, 9.9f } };
|
||||||
|
char buffer[100] = {};
|
||||||
|
|
||||||
|
size_t written = to_chars(ryml::substr(buffer), mat3);
|
||||||
|
REQUIRE(written != ryml::yml::npos);
|
||||||
|
REQUIRE(std::string(buffer) == "(1.1,4.4,7.7),(2.2,5.5,8.8),(3.3,6.6,9.9)");
|
||||||
|
|
||||||
|
Matrix3<float> parsed_mat3;
|
||||||
|
REQUIRE(from_chars("(1.1,4.4,7.7),(2.2,5.5,8.8),(3.3,6.6,9.9)", &parsed_mat3));
|
||||||
|
REQUIRE(parsed_mat3[0][0] == 1.1f);
|
||||||
|
REQUIRE(parsed_mat3[0][1] == 2.2f);
|
||||||
|
REQUIRE(parsed_mat3[0][2] == 3.3f);
|
||||||
|
REQUIRE(parsed_mat3[1][0] == 4.4f);
|
||||||
|
REQUIRE(parsed_mat3[1][1] == 5.5f);
|
||||||
|
REQUIRE(parsed_mat3[1][2] == 6.6f);
|
||||||
|
REQUIRE(parsed_mat3[2][0] == 7.7f);
|
||||||
|
REQUIRE(parsed_mat3[2][1] == 8.8f);
|
||||||
|
REQUIRE(parsed_mat3[2][2] == 9.9f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Matrix4 to_chars and from_chars", "[RymlConverters]")
|
||||||
|
{
|
||||||
|
Matrix4<float> mat4 { { 1.1f, 2.2f, 3.3f, 4.4f },
|
||||||
|
{ 5.5f, 6.6f, 7.7f, 8.8f },
|
||||||
|
{ 9.9f, 10.10f, 11.11f, 12.12f },
|
||||||
|
{ 13.13f, 14.14f, 15.15f, 16.16f } };
|
||||||
|
char buffer[200] = {};
|
||||||
|
|
||||||
|
size_t written = to_chars(ryml::substr(buffer), mat4);
|
||||||
|
REQUIRE(written != ryml::yml::npos);
|
||||||
|
REQUIRE(std::string(buffer) == "(1.1,5.5,9.9,13.13),(2.2,6.6,10.1,14.14),(3.3,7.7,11.11,15.15),(4.4,8.8,12.12,16.16)");
|
||||||
|
|
||||||
|
Matrix4<float> parsed_mat4;
|
||||||
|
REQUIRE(from_chars("(1.1,5.5,9.9,13.13),(2.2,6.6,10.1,14.14),(3.3,7.7,11.11,15.15),(4.4,8.8,12.12,16.16)", &parsed_mat4));
|
||||||
|
|
||||||
|
REQUIRE(parsed_mat4[0][0] == 1.1f);
|
||||||
|
REQUIRE(parsed_mat4[0][1] == 2.2f);
|
||||||
|
REQUIRE(parsed_mat4[0][2] == 3.3f);
|
||||||
|
REQUIRE(parsed_mat4[0][3] == 4.4f);
|
||||||
|
|
||||||
|
REQUIRE(parsed_mat4[1][0] == 5.5f);
|
||||||
|
REQUIRE(parsed_mat4[1][1] == 6.6f);
|
||||||
|
REQUIRE(parsed_mat4[1][2] == 7.7f);
|
||||||
|
REQUIRE(parsed_mat4[1][3] == 8.8f);
|
||||||
|
|
||||||
|
REQUIRE(parsed_mat4[2][0] == 9.9f);
|
||||||
|
REQUIRE(parsed_mat4[2][1] == 10.10f);
|
||||||
|
REQUIRE(parsed_mat4[2][2] == 11.11f);
|
||||||
|
REQUIRE(parsed_mat4[2][3] == 12.12f);
|
||||||
|
|
||||||
|
REQUIRE(parsed_mat4[3][0] == 13.13f);
|
||||||
|
REQUIRE(parsed_mat4[3][1] == 14.14f);
|
||||||
|
REQUIRE(parsed_mat4[3][2] == 15.15f);
|
||||||
|
REQUIRE(parsed_mat4[3][3] == 16.16f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("AABB to_chars and from_chars", "[RymlConverters]")
|
||||||
|
{
|
||||||
|
AABB bbox { Vector3<float> { 1.0f, 2.0f, 3.0f }, Vector3<float> { 4.0f, 5.0f, 6.0f } };
|
||||||
|
char buffer[50] = {};
|
||||||
|
|
||||||
|
size_t written = to_chars(ryml::substr(buffer), bbox);
|
||||||
|
REQUIRE(written != ryml::yml::npos);
|
||||||
|
REQUIRE(std::string(buffer) == "(1,2,3),(4,5,6)");
|
||||||
|
|
||||||
|
AABB parsed_bbox;
|
||||||
|
REQUIRE(from_chars("(1,2,3),(4,5,6)", &parsed_bbox));
|
||||||
|
REQUIRE(parsed_bbox.min.x == 1.0f);
|
||||||
|
REQUIRE(parsed_bbox.min.y == 2.0f);
|
||||||
|
REQUIRE(parsed_bbox.min.z == 3.0f);
|
||||||
|
REQUIRE(parsed_bbox.max.x == 4.0f);
|
||||||
|
REQUIRE(parsed_bbox.max.y == 5.0f);
|
||||||
|
REQUIRE(parsed_bbox.max.z == 6.0f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Pose to_chars and from_chars", "[RymlConverters]")
|
||||||
|
{
|
||||||
|
Pose<float> pose;
|
||||||
|
pose.SetPosition(Vector3<float> { 1.1f, 2.2f, 3.3f });
|
||||||
|
pose.SetOrientation(QuaternionF(7.7f, 4.4f, 5.5f, 6.6f));
|
||||||
|
char buffer[70] = {};
|
||||||
|
|
||||||
|
size_t written = to_chars(ryml::substr(buffer), pose);
|
||||||
|
REQUIRE(written != ryml::yml::npos);
|
||||||
|
REQUIRE(std::string(buffer) == "(1.1,2.2,3.3),(4.4,5.5,6.6,7.7)");
|
||||||
|
|
||||||
|
Pose<float> parsed_pose;
|
||||||
|
REQUIRE(from_chars("(1.1,2.2,3.3),(4.4,5.5,6.6,7.7)", &parsed_pose));
|
||||||
|
REQUIRE(parsed_pose.GetPosition().x == 1.1f);
|
||||||
|
REQUIRE(parsed_pose.GetPosition().y == 2.2f);
|
||||||
|
REQUIRE(parsed_pose.GetPosition().z == 3.3f);
|
||||||
|
REQUIRE(parsed_pose.GetOrientation().x == 4.4f);
|
||||||
|
REQUIRE(parsed_pose.GetOrientation().y == 5.5f);
|
||||||
|
REQUIRE(parsed_pose.GetOrientation().z == 6.6f);
|
||||||
|
REQUIRE(parsed_pose.GetOrientation().w == 7.7f);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("UUID to_chars and from_chars", "[RymlConverters]")
|
||||||
|
{
|
||||||
|
UUID uuid("123e4567-e89b-12d3-a456-426655440000");
|
||||||
|
char buffer[40] = {};
|
||||||
|
|
||||||
|
size_t written = to_chars(ryml::substr(buffer), uuid);
|
||||||
|
REQUIRE(written != ryml::yml::npos);
|
||||||
|
REQUIRE(std::string(buffer) == "123e4567-e89b-12d3-a456-426655440000");
|
||||||
|
|
||||||
|
UUID parsed_uuid;
|
||||||
|
REQUIRE(from_chars("123e4567-e89b-12d3-a456-426655440000", &parsed_uuid));
|
||||||
|
REQUIRE(parsed_uuid.string() == uuid.string());
|
||||||
|
}
|
||||||
167
tests/Extensions/YamlCppConverters.cpp
Normal file
167
tests/Extensions/YamlCppConverters.cpp
Normal file
@@ -0,0 +1,167 @@
|
|||||||
|
/*
|
||||||
|
* This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
* file, You can obtain one at https://mozilla.org/MPL/2.0/.
|
||||||
|
*/
|
||||||
|
|
||||||
|
#include <catch2/catch_all.hpp>
|
||||||
|
|
||||||
|
#include "Extensions/YamlCppConverters.hpp"
|
||||||
|
#include "Math/Math.hpp"
|
||||||
|
|
||||||
|
using namespace OpenVulkano;
|
||||||
|
using namespace OpenVulkano::Math;
|
||||||
|
|
||||||
|
TEST_CASE("UUID encoding and decoding", "[YamlCppConverters]")
|
||||||
|
{
|
||||||
|
UUID uuid("123e4567-e89b-12d3-a456-426614174000");
|
||||||
|
YAML::Node node = YAML::convert<UUID>::encode(uuid);
|
||||||
|
REQUIRE(node.IsScalar());
|
||||||
|
REQUIRE(node.as<std::string>() == uuid.string());
|
||||||
|
|
||||||
|
UUID decoded_uuid;
|
||||||
|
REQUIRE(YAML::convert<UUID>::decode(node, decoded_uuid));
|
||||||
|
REQUIRE(decoded_uuid == uuid);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("AABB encoding and decoding", "[YamlCppConverters]")
|
||||||
|
{
|
||||||
|
Math::AABB bbox { { 1.0f, 2.0f, 3.0f }, { 4.0f, 5.0f, 6.0f } };
|
||||||
|
YAML::Node node = YAML::convert<Math::AABB>::encode(bbox);
|
||||||
|
REQUIRE(node.IsScalar());
|
||||||
|
|
||||||
|
Math::AABB decoded_bbox;
|
||||||
|
REQUIRE(YAML::convert<Math::AABB>::decode(node, decoded_bbox));
|
||||||
|
REQUIRE(decoded_bbox.min == bbox.min);
|
||||||
|
REQUIRE(decoded_bbox.max == bbox.max);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("PoseF encoding and decoding", "[YamlCppConverters]")
|
||||||
|
{
|
||||||
|
Math::PoseF pose;
|
||||||
|
pose.SetPosition({1.0f, 2.0f, 3.0f});
|
||||||
|
pose.SetOrientation({1.0f, 2.0f, 3.0f, 1.0f});
|
||||||
|
YAML::Node node = YAML::convert<Math::PoseF>::encode(pose);
|
||||||
|
REQUIRE(node.IsScalar());
|
||||||
|
|
||||||
|
Math::PoseF decoded_pose;
|
||||||
|
REQUIRE(YAML::convert<Math::PoseF>::decode(node, decoded_pose));
|
||||||
|
REQUIRE(decoded_pose.GetPosition() == pose.GetPosition());
|
||||||
|
REQUIRE(decoded_pose.GetOrientation() == pose.GetOrientation());
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Vector2 encoding and decoding", "[YamlCppConverters]")
|
||||||
|
{
|
||||||
|
Math::Vector2<float> vec { 1.0f, 2.0f };
|
||||||
|
YAML::Node node = YAML::convert<Math::Vector2<float>>::encode(vec);
|
||||||
|
REQUIRE(node.IsScalar());
|
||||||
|
|
||||||
|
Math::Vector2<float> decoded_vec;
|
||||||
|
REQUIRE(YAML::convert<Math::Vector2<float>>::decode(node, decoded_vec));
|
||||||
|
REQUIRE(decoded_vec == vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Vector3 encoding and decoding", "[YamlCppConverters]")
|
||||||
|
{
|
||||||
|
Math::Vector3<float> vec { 1.0f, 2.0f, 3.0f };
|
||||||
|
YAML::Node node = YAML::convert<Math::Vector3<float>>::encode(vec);
|
||||||
|
REQUIRE(node.IsScalar());
|
||||||
|
|
||||||
|
Math::Vector3<float> decoded_vec;
|
||||||
|
REQUIRE(YAML::convert<Math::Vector3<float>>::decode(node, decoded_vec));
|
||||||
|
REQUIRE(decoded_vec == vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Vector4 encoding and decoding", "[YamlCppConverters]")
|
||||||
|
{
|
||||||
|
Math::Vector4<float> vec { 1.0f, 2.0f, 3.0f, 4.0f };
|
||||||
|
YAML::Node node = YAML::convert<Math::Vector4<float>>::encode(vec);
|
||||||
|
REQUIRE(node.IsScalar());
|
||||||
|
|
||||||
|
Math::Vector4<float> decoded_vec;
|
||||||
|
REQUIRE(YAML::convert<Math::Vector4<float>>::decode(node, decoded_vec));
|
||||||
|
REQUIRE(decoded_vec == vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Matrix3 encoding and decoding", "[YamlCppConverters]")
|
||||||
|
{
|
||||||
|
Math::Matrix3<float> mat { { 1.0f, 2.0f, 3.0f }, { 4.0f, 5.0f, 6.0f }, { 7.0f, 8.0f, 9.0f } };
|
||||||
|
YAML::Node node = YAML::convert<Math::Matrix3<float>>::encode(mat);
|
||||||
|
REQUIRE(node.IsScalar());
|
||||||
|
|
||||||
|
Math::Matrix3<float> decoded_mat;
|
||||||
|
REQUIRE(YAML::convert<Math::Matrix3<float>>::decode(node, decoded_mat));
|
||||||
|
REQUIRE(decoded_mat == mat);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Matrix4 encoding and decoding", "[YamlCppConverters]")
|
||||||
|
{
|
||||||
|
Math::Matrix4<float> mat { { 1.0f, 2.0f, 3.0f, 4.0f },
|
||||||
|
{ 5.0f, 6.0f, 7.0f, 8.0f },
|
||||||
|
{ 9.0f, 10.0f, 11.0f, 12.0f },
|
||||||
|
{ 13.0f, 14.0f, 15.0f, 16.0f } };
|
||||||
|
YAML::Node node = YAML::convert<Math::Matrix4<float>>::encode(mat);
|
||||||
|
REQUIRE(node.IsScalar());
|
||||||
|
|
||||||
|
Math::Matrix4<float> decoded_mat;
|
||||||
|
REQUIRE(YAML::convert<Math::Matrix4<float>>::decode(node, decoded_mat));
|
||||||
|
REQUIRE(decoded_mat == mat);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Vector2_SIMD encoding and decoding", "[YamlCppConverters]")
|
||||||
|
{
|
||||||
|
Math::Vector2_SIMD<float> vec { 1.0f, 2.0f };
|
||||||
|
YAML::Node node = YAML::convert<Math::Vector2_SIMD<float>>::encode(vec);
|
||||||
|
REQUIRE(node.IsScalar());
|
||||||
|
|
||||||
|
Math::Vector2_SIMD<float> decoded_vec;
|
||||||
|
REQUIRE(YAML::convert<Math::Vector2_SIMD<float>>::decode(node, decoded_vec));
|
||||||
|
REQUIRE(decoded_vec == vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Vector3_SIMD encoding and decoding", "[YamlCppConverters]")
|
||||||
|
{
|
||||||
|
Math::Vector3_SIMD<float> vec { 1.0f, 2.0f, 3.0f };
|
||||||
|
YAML::Node node = YAML::convert<Math::Vector3_SIMD<float>>::encode(vec);
|
||||||
|
REQUIRE(node.IsScalar());
|
||||||
|
|
||||||
|
Math::Vector3_SIMD<float> decoded_vec;
|
||||||
|
REQUIRE(YAML::convert<Math::Vector3_SIMD<float>>::decode(node, decoded_vec));
|
||||||
|
REQUIRE(decoded_vec == vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Vector4_SIMD encoding and decoding", "[YamlCppConverters]")
|
||||||
|
{
|
||||||
|
Math::Vector4_SIMD<float> vec { 1.0f, 2.0f, 3.0f, 4.0f };
|
||||||
|
YAML::Node node = YAML::convert<Math::Vector4_SIMD<float>>::encode(vec);
|
||||||
|
REQUIRE(node.IsScalar());
|
||||||
|
|
||||||
|
Math::Vector4_SIMD<float> decoded_vec;
|
||||||
|
REQUIRE(YAML::convert<Math::Vector4_SIMD<float>>::decode(node, decoded_vec));
|
||||||
|
REQUIRE(decoded_vec == vec);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Matrix3_SIMD encoding and decoding", "[YamlCppConverters]")
|
||||||
|
{
|
||||||
|
Math::Matrix3_SIMD<float> mat { { 1.0f, 2.0f, 3.0f }, { 4.0f, 5.0f, 6.0f }, { 7.0f, 8.0f, 9.0f } };
|
||||||
|
YAML::Node node = YAML::convert<Math::Matrix3_SIMD<float>>::encode(mat);
|
||||||
|
REQUIRE(node.IsScalar());
|
||||||
|
|
||||||
|
Math::Matrix3_SIMD<float> decoded_mat;
|
||||||
|
REQUIRE(YAML::convert<Math::Matrix3_SIMD<float>>::decode(node, decoded_mat));
|
||||||
|
REQUIRE(decoded_mat == mat);
|
||||||
|
}
|
||||||
|
|
||||||
|
TEST_CASE("Matrix4_SIMD encoding and decoding", "[YamlCppConverters]")
|
||||||
|
{
|
||||||
|
Math::Matrix4_SIMD<float> mat { { 1.0f, 2.0f, 3.0f, 4.0f },
|
||||||
|
{ 5.0f, 6.0f, 7.0f, 8.0f },
|
||||||
|
{ 9.0f, 10.0f, 11.0f, 12.0f },
|
||||||
|
{ 13.0f, 14.0f, 15.0f, 16.0f } };
|
||||||
|
YAML::Node node = YAML::convert<Math::Matrix4_SIMD<float>>::encode(mat);
|
||||||
|
REQUIRE(node.IsScalar());
|
||||||
|
|
||||||
|
Math::Matrix4_SIMD<float> decoded_mat;
|
||||||
|
REQUIRE(YAML::convert<Math::Matrix4_SIMD<float>>::decode(node, decoded_mat));
|
||||||
|
REQUIRE(decoded_mat == mat);
|
||||||
|
}
|
||||||
Reference in New Issue
Block a user