Add a function to compute the distance between points

This commit is contained in:
Emmanuele Bassi 2012-04-19 12:15:17 +01:00
parent bc914bb8a2
commit d021cc7c02
3 changed files with 46 additions and 0 deletions

View File

@ -472,6 +472,47 @@ clutter_point_equals (const ClutterPoint *a,
return a->x == b->x && a->y == b->y;
}
/**
* clutter_point_distance:
* @a: a #ClutterPoint
* @b: a #ClutterPoint
* @x_distance: (out) (allow-none): return location for the horizontal
* distance between the points
* @y_distance: (out) (allow-none): return location for the vertical
* distance between the points
*
* Computes the distance between two #ClutterPoint.
*
* Return value: the distance between the points.
*
* Since: 1.12
*/
float
clutter_point_distance (const ClutterPoint *a,
const ClutterPoint *b,
float *x_distance,
float *y_distance)
{
float x_d, y_d;
g_return_val_if_fail (a != NULL, 0.f);
g_return_val_if_fail (b != NULL, 0.f);
if (clutter_point_equals (a, b))
return 0.f;
x_d = (a->x - b->x);
y_d = (a->y - b->y);
if (x_distance != NULL)
*x_distance = fabsf (x_d);
if (y_distance != NULL)
*y_distance = fabsf (y_d);
return sqrt ((x_d * x_d) + (y_d * y_d));
}
static gboolean
clutter_point_progress (const GValue *a,
const GValue *b,

View File

@ -139,6 +139,10 @@ ClutterPoint * clutter_point_copy (const ClutterPoint *point);
void clutter_point_free (ClutterPoint *point);
gboolean clutter_point_equals (const ClutterPoint *a,
const ClutterPoint *b);
float clutter_point_distance (const ClutterPoint *a,
const ClutterPoint *b,
float *x_distance,
float *y_distance);
/**
* ClutterSize:

View File

@ -982,6 +982,7 @@ clutter_pipeline_node_new
clutter_pick_mode_get_type
clutter_point_alloc
clutter_point_copy
clutter_point_distance
clutter_point_equals
clutter_point_free
clutter_point_get_type