diff options
author | Yuqian Yang <crupest@crupest.life> | 2025-09-21 23:40:30 +0800 |
---|---|---|
committer | Yuqian Yang <crupest@crupest.life> | 2025-09-21 23:43:31 +0800 |
commit | 6b78788d049c90dab3aec01d7bb7193f3927dc75 (patch) | |
tree | 977cfe754ccafb94e3e6743937d9132d2184df2f /test | |
parent | e31b0b8b37ae52e9402dc351e5fb0f361d30d0e0 (diff) | |
download | cru-geo-arc.tar.gz cru-geo-arc.tar.bz2 cru-geo-arc.zip |
HALF WORK!geo-arc
Diffstat (limited to 'test')
-rw-r--r-- | test/platform/CMakeLists.txt | 2 | ||||
-rw-r--r-- | test/platform/graphics/CMakeLists.txt | 6 | ||||
-rw-r--r-- | test/platform/graphics/GeometryTest.cpp | 32 |
3 files changed, 40 insertions, 0 deletions
diff --git a/test/platform/CMakeLists.txt b/test/platform/CMakeLists.txt index 394aa247..6a00ff21 100644 --- a/test/platform/CMakeLists.txt +++ b/test/platform/CMakeLists.txt @@ -4,6 +4,8 @@ add_executable(CruPlatformBaseTest ) target_link_libraries(CruPlatformBaseTest PRIVATE CruPlatformBase CruTestBase) +add_subdirectory(graphics) + if (WIN32) add_subdirectory(graphics/direct2d) endif() 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 <catch2/catch_test_macros.hpp> +#include <numbers> +#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); +} |