dihedral: Add documentation

This hopefully clarifies things sufficiently that we don't have
to go through painful fact-finding about square symmetries ever
again.
This commit is contained in:
Matthias Clasen 2024-12-05 15:47:36 -05:00
parent b303991cf6
commit 0eaadb1be7
2 changed files with 72 additions and 0 deletions

View File

@ -3,6 +3,16 @@
#include "gdkdihedralprivate.h"
/*< private >
* gdk_dihedral_get_mat2:
* transform: a dihedral
* @xx: return location for xx component
* @xy: return location for xy component
* @yx: return location for yx component
* @yy: return location for yy component
*
* Gets a 2x2 matrix representing the dihedral transform.
*/
void
gdk_dihedral_get_mat2 (GdkDihedral transform,
float *xx,
@ -51,6 +61,15 @@ gdk_dihedral_get_mat2 (GdkDihedral transform,
*yy = mat[transform][1][1];
}
/*< private >
* gdk_dihedral_combine:
* @first: a dihedral transform
* @second: another dihedral transform
*
* Combines two dihedral transforms.
*
* Returns: the dihedral transform that applies @first, then @second
*/
GdkDihedral
gdk_dihedral_combine (GdkDihedral first,
GdkDihedral second)
@ -59,18 +78,44 @@ gdk_dihedral_combine (GdkDihedral first,
((((first & 3) * (((second & 4) >> 1) + 1)) + second) & 3);
}
/*< private >
* gdk_dihedral_invert:
* @self: a dihedral transform
*
* Inverts a dihedral transform.
*
* Returns: the inverse of @self
*/
GdkDihedral
gdk_dihedral_invert (GdkDihedral self)
{
return ((4 - self) * (((self & 4) >> 1) + 1) & 3) | (self & 4);
}
/*< private >
* gdk_dihedral_swaps_xy:
* @self: a dihedral transform
*
* Returns whether the transform exchanges width and height.
*
* Returns: true if the transform exchanges width and height
*/
gboolean
gdk_dihedral_swaps_xy (GdkDihedral self)
{
return (self & 1) ? TRUE : FALSE;
}
/*< private >
* gdk_dihedral_get_name:
* @self: a dihedral transform
*
* Returns a name for the transform.
*
* This is meant for debug messages.
*
* Returns: the name of the transform
*/
const char *
gdk_dihedral_get_name (GdkDihedral self)
{

View File

@ -21,6 +21,33 @@
G_BEGIN_DECLS
/*< private >
* GdkDihedral:
* @GDK_DIHEDRAL_NORMAL: Identity,
* equivalent to the CSS transform "none"
* @GDK_DIHEDRAL_90: Clockwise rotation by 90°,
* equivalent to the CSS transform "rotate(90deg)"
* @GDK_DIHEDRAL_180: Clockwise rotation by 180°,
* equivalent to the CSS transform "rotate(180deg)"
* @GDK_DIHEDRAL_270: Clockwise rotation by 270°,
* equivalent to the CSS transform "rotate(270deg)"
* @GDK_DIHEDRAL_FLIPPED: Horizontal flip,
* equivalent to the CSS transform "scale(-1, 1)"
* @GDK_DIHEDRAL_FLIPPED_90: Clockwise 90° rotation, followed by a horizontal flip,
* equivalent to the CSS transform "rotate(90deg) scale(-1, 1)"
* @GDK_DIHEDRAL_FLIPPED_180: Clockwise 180° rotation, followed by a horizontal flip,
* equivalent to the CSS transform "rotate(180deg) scale(-1, 1)"
* @GDK_DIHEDRAL_FLIPPED_270: Clockwise 270° rotation, followed by a horizontal flip,
* equivalent to the CSS transform "rotate(270deg) scale(-1, 1)"
*
* The transforms that make up the symmetry group of the square,
* also known as D.
*
* Note that this enumeration is intentionally set up to encode the *inverses*
* of the corresponding wl_output_transform values. E.g. `WL_OUTPUT_TRANSFORM_FLIPPED_90`
* is defined as a horizontal flip, followed by a 90° counterclockwise rotation, which
* is the inverse of @GDK_DIHEDRAL_FLIPPED_90.
*/
typedef enum {
GDK_DIHEDRAL_NORMAL,
GDK_DIHEDRAL_90,