From 6b78788d049c90dab3aec01d7bb7193f3927dc75 Mon Sep 17 00:00:00 2001 From: Yuqian Yang Date: Sun, 21 Sep 2025 23:40:30 +0800 Subject: HALF WORK! --- test/platform/graphics/CMakeLists.txt | 6 ++++++ test/platform/graphics/GeometryTest.cpp | 32 ++++++++++++++++++++++++++++++++ 2 files changed, 38 insertions(+) create mode 100644 test/platform/graphics/CMakeLists.txt create mode 100644 test/platform/graphics/GeometryTest.cpp (limited to 'test/platform/graphics') diff --git a/test/platform/graphics/CMakeLists.txt b/test/platform/graphics/CMakeLists.txt new file mode 100644 index 00000000..22be21e6 --- /dev/null +++ b/test/platform/graphics/CMakeLists.txt @@ -0,0 +1,6 @@ +add_executable(CruPlatformGraphicsTest + GeometryTest.cpp +) +target_link_libraries(CruPlatformGraphicsTest PRIVATE CruPlatformGraphics CruTestBase) + +cru_catch_discover_tests(CruPlatformGraphicsTest) diff --git a/test/platform/graphics/GeometryTest.cpp b/test/platform/graphics/GeometryTest.cpp new file mode 100644 index 00000000..8a48ddde --- /dev/null +++ b/test/platform/graphics/GeometryTest.cpp @@ -0,0 +1,32 @@ +#include "cru/platform/graphics/Geometry.h" + +#include +#include +#include "catch2/catch_approx.hpp" + +using Catch::Approx; +using cru::platform::graphics::IGeometryBuilder; + +constexpr float margin = 0.000001; + +TEST_CASE("IGeometryBuilder CalculateArcInfo", "[graphics][geometry]") { + auto test = [](float start_x, float start_y, float radius_x, float radius_y, + float angle, bool is_large_arc, bool is_clockwise, float end_x, + float end_y, float expect_center_x, float expect_center_y, + float expect_start_angle, float expect_end_angle) { + auto info = IGeometryBuilder::CalculateArcInfo( + {start_x, start_y}, {radius_x, radius_y}, angle, is_large_arc, + is_clockwise, {end_x, end_y}); + REQUIRE(info.center.x == Approx(expect_center_x).margin(margin)); + REQUIRE(info.center.y == Approx(expect_center_y).margin(margin)); + REQUIRE(info.start_angle == Approx(expect_start_angle).margin(margin)); + REQUIRE(info.end_angle == Approx(expect_end_angle).margin(margin)); + }; + + test(1, 0, 1, 1, 0, false, true, 0, 1, 0, 0, 0, std::numbers::pi / 2); + test(0, 1, 1, 1, 0, false, true, -1, 0, 0, 0, std::numbers::pi / 2, + std::numbers::pi); + test(-1, 0, 1, 1, 0, false, true, 0, -1, 0, 0, std::numbers::pi, + -std::numbers::pi / 2); + test(0, -1, 1, 1, 0, false, true, 1, 0, 0, 0, -std::numbers::pi / 2, 0); +} -- cgit v1.2.3