From 60651650603a1977becef7c5cfa6cc14b99ca89f Mon Sep 17 00:00:00 2001 From: Benjamin Otte Date: Wed, 10 Jul 2024 08:31:53 +0200 Subject: [PATCH] Add gdk_dihedral_swaps_xy This function determines if a dihedral transform swaps x and y. --- gdk/gdkdihedral.c | 5 +++++ gdk/gdkdihedralprivate.h | 1 + gsk/gskroundedrect.c | 2 +- testsuite/gdk/dihedral.c | 14 ++++++++++++++ 4 files changed, 21 insertions(+), 1 deletion(-) diff --git a/gdk/gdkdihedral.c b/gdk/gdkdihedral.c index f9286a9e61..6628e6fc60 100644 --- a/gdk/gdkdihedral.c +++ b/gdk/gdkdihedral.c @@ -65,3 +65,8 @@ gdk_dihedral_invert (GdkDihedral self) return ((4 - self) * (((self & 4) >> 1) + 1) & 3) | (self & 4); } +gboolean +gdk_dihedral_swaps_xy (GdkDihedral self) +{ + return (self & 1) ? TRUE : FALSE; +} diff --git a/gdk/gdkdihedralprivate.h b/gdk/gdkdihedralprivate.h index 699775d8c2..472cd74a1a 100644 --- a/gdk/gdkdihedralprivate.h +++ b/gdk/gdkdihedralprivate.h @@ -41,6 +41,7 @@ void gdk_dihedral_get_mat2 (GdkDihedral GdkDihedral gdk_dihedral_combine (GdkDihedral first, GdkDihedral second); GdkDihedral gdk_dihedral_invert (GdkDihedral self); +gboolean gdk_dihedral_swaps_xy (GdkDihedral self); G_END_DECLS diff --git a/gsk/gskroundedrect.c b/gsk/gskroundedrect.c index 7306bb5d0f..df2b1af370 100644 --- a/gsk/gskroundedrect.c +++ b/gsk/gskroundedrect.c @@ -331,7 +331,7 @@ gsk_rounded_rect_dihedral (GskRoundedRect *dest, gsk_rect_dihedral (&src->bounds, dihedral, &dest->bounds); - if (dihedral & 1) + if (gdk_dihedral_swaps_xy (dihedral)) { for (i = 0; i < 4; i++) { diff --git a/testsuite/gdk/dihedral.c b/testsuite/gdk/dihedral.c index f7e715aa79..580af8f997 100644 --- a/testsuite/gdk/dihedral.c +++ b/testsuite/gdk/dihedral.c @@ -64,12 +64,26 @@ test_inversions (void) g_assert_cmpint (gdk_dihedral_invert (GDK_DIHEDRAL_FLIPPED_270), ==, GDK_DIHEDRAL_FLIPPED_270); } +static void +test_swaps (void) +{ + g_assert_false (gdk_dihedral_swaps_xy (GDK_DIHEDRAL_NORMAL)); + g_assert_true (gdk_dihedral_swaps_xy (GDK_DIHEDRAL_90)); + g_assert_false (gdk_dihedral_swaps_xy (GDK_DIHEDRAL_180)); + g_assert_true (gdk_dihedral_swaps_xy (GDK_DIHEDRAL_270)); + g_assert_false (gdk_dihedral_swaps_xy (GDK_DIHEDRAL_FLIPPED)); + g_assert_true (gdk_dihedral_swaps_xy (GDK_DIHEDRAL_FLIPPED_90)); + g_assert_false (gdk_dihedral_swaps_xy (GDK_DIHEDRAL_FLIPPED_180)); + g_assert_true (gdk_dihedral_swaps_xy (GDK_DIHEDRAL_FLIPPED_270)); +} + int main (int argc, char *argv[]) { gtk_test_init (&argc, &argv, NULL); g_test_add_func ("/dihedral/inversions", test_inversions); + g_test_add_func ("/dihedral/swaps", test_swaps); g_test_add_func ("/dihedral/combinations", test_combinations); g_test_add_func ("/dihedral/invariants", test_invariants);