Add gdk_dihedral_swaps_xy

This function determines if a dihedral transform swaps x and y.
This commit is contained in:
Benjamin Otte 2024-07-10 08:31:53 +02:00
parent 61c22d1c72
commit 6065165060
4 changed files with 21 additions and 1 deletions

View File

@ -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;
}

View File

@ -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

View File

@ -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++)
{

View File

@ -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);