From ad4f06c133dc0475ef6a98cac0fa97f6e0527bf1 Mon Sep 17 00:00:00 2001 From: crupest Date: Tue, 24 May 2022 23:14:45 +0800 Subject: ... --- test/platform/graphics/cairo/BaseTest.cpp | 40 +++++++++++++++++++++++++++++++ 1 file changed, 40 insertions(+) create mode 100644 test/platform/graphics/cairo/BaseTest.cpp (limited to 'test/platform/graphics/cairo/BaseTest.cpp') diff --git a/test/platform/graphics/cairo/BaseTest.cpp b/test/platform/graphics/cairo/BaseTest.cpp new file mode 100644 index 00000000..29e53ff0 --- /dev/null +++ b/test/platform/graphics/cairo/BaseTest.cpp @@ -0,0 +1,40 @@ +#include "cru/platform/graphics/cairo/Base.h" + +#include +#include +#include "catch2/catch_approx.hpp" + +using Catch::Approx; + +TEST_CASE("Cairo Matrix Convert", "[matrix]") { + using namespace cru::platform; + using namespace cru::platform::graphics; + using namespace cru::platform::graphics::cairo; + + SECTION("Cairo to cru should work") { + cairo_matrix_t cairo_matrix; + cairo_matrix_init_identity(&cairo_matrix); + cairo_matrix_scale(&cairo_matrix, 2, 2); + cairo_matrix_rotate(&cairo_matrix, 1); + cairo_matrix_translate(&cairo_matrix, 10, 10); + auto cru_matrix = Convert(cairo_matrix); + Point original_point(3, 5); + double cairo_point_x = original_point.x, cairo_point_y = original_point.y; + cairo_matrix_transform_point(&cairo_matrix, &cairo_point_x, &cairo_point_y); + Point cru_point = cru_matrix.TransformPoint(original_point); + REQUIRE(Approx(cru_point.x) == cairo_point_x); + REQUIRE(Approx(cru_point.y) == cairo_point_y); + } + + SECTION("Cru to cairo should work") { + auto cru_matrix = Matrix::Identity() * Matrix::Scale(2, 2) * + Matrix::Rotation(60) * Matrix::Translation(10, 10); + cairo_matrix_t cairo_matrix = Convert(cru_matrix); + Point original_point(3, 5); + double cairo_point_x = original_point.x, cairo_point_y = original_point.y; + cairo_matrix_transform_point(&cairo_matrix, &cairo_point_x, &cairo_point_y); + Point cru_point = cru_matrix.TransformPoint(original_point); + REQUIRE(Approx(cru_point.x) == cairo_point_x); + REQUIRE(Approx(cru_point.y) == cairo_point_y); + } +} -- cgit v1.2.3