libgimpmath: make GimpVector[23] boxed types.

This way, all functions using these types are now introspectable.
This commit is contained in:
Jehan 2019-08-02 03:44:56 +02:00
parent 0411c7ef97
commit 3a4b17e8b5
2 changed files with 75 additions and 0 deletions

View file

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

View file

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