From 3a4b17e8b58a2b3d21bb3b6ac6d5e1104d1d9256 Mon Sep 17 00:00:00 2001 From: Jehan Date: Fri, 2 Aug 2019 03:44:56 +0200 Subject: [PATCH] libgimpmath: make GimpVector[23] boxed types. This way, all functions using these types are now introspectable. --- libgimpmath/gimpmathtypes.h | 20 ++++++++++++++ libgimpmath/gimpvector.c | 55 +++++++++++++++++++++++++++++++++++++ 2 files changed, 75 insertions(+) diff --git a/libgimpmath/gimpmathtypes.h b/libgimpmath/gimpmathtypes.h index a6f462892e..559f883047 100644 --- a/libgimpmath/gimpmathtypes.h +++ b/libgimpmath/gimpmathtypes.h @@ -81,6 +81,16 @@ struct _GimpVector2 gdouble x, y; }; +/** + * GIMP_TYPE_VECTOR2: + * + * Boxed type representing a two-dimensional vector. + */ +#define GIMP_TYPE_VECTOR2 (gimp_vector2_get_type ()) + +GType gimp_vector2_get_type (void) G_GNUC_CONST; + + /** * GimpVector3: * @x: the x axis @@ -94,6 +104,16 @@ struct _GimpVector3 gdouble x, y, z; }; +/** + * GIMP_TYPE_VECTOR3: + * + * Boxed type representing a three-dimensional vector. + */ +#define GIMP_TYPE_VECTOR3 (gimp_vector3_get_type ()) + +GType gimp_vector3_get_type (void) G_GNUC_CONST; + + /** * GimpVector4: * @x: the x axis diff --git a/libgimpmath/gimpvector.c b/libgimpmath/gimpvector.c index 5f2b174ca1..d97622b624 100644 --- a/libgimpmath/gimpvector.c +++ b/libgimpmath/gimpvector.c @@ -43,6 +43,12 @@ **/ +static gpointer gimp_vector2_copy (gpointer boxed); +static void gimp_vector2_free (gpointer boxed); +static gpointer gimp_vector3_copy (gpointer boxed); +static void gimp_vector3_free (gpointer boxed); + + /*************************/ /* Some useful constants */ /*************************/ @@ -1127,3 +1133,52 @@ gimp_vector_3d_to_2d (gint sx, *y = (gdouble) sy + (p->y * (gdouble) h); } } + +/* Private functions for boxed type. */ + +static gpointer +gimp_vector2_copy (gpointer boxed) +{ + GimpVector2 *vector = boxed; + GimpVector2 *new_v; + + new_v = g_slice_new (GimpVector2); + new_v->x = vector->x; + new_v->y = vector->y; + + return new_v; +} + +static void +gimp_vector2_free (gpointer boxed) +{ + g_slice_free (GimpVector2, boxed); +} + +G_DEFINE_BOXED_TYPE (GimpVector2, gimp_vector2, + gimp_vector2_copy, + gimp_vector2_free) + +static gpointer +gimp_vector3_copy (gpointer boxed) +{ + GimpVector3 *vector = boxed; + GimpVector3 *new_v; + + new_v = g_slice_new (GimpVector3); + new_v->x = vector->x; + new_v->y = vector->y; + new_v->y = vector->z; + + return new_v; +} + +static void +gimp_vector3_free (gpointer boxed) +{ + g_slice_free (GimpVector3, boxed); +} + +G_DEFINE_BOXED_TYPE (GimpVector3, gimp_vector3, + gimp_vector3_copy, + gimp_vector3_free)