[clutter] Add a function to compute the distance between points



commit d021cc7c02059126f2e20ce4807baf58161fe447
Author: Emmanuele Bassi <ebassi linux intel com>
Date:   Thu Apr 19 12:15:17 2012 +0100

    Add a function to compute the distance between points

 clutter/clutter-base-types.c |   41 +++++++++++++++++++++++++++++++++++++++++
 clutter/clutter-types.h      |    4 ++++
 clutter/clutter.symbols      |    1 +
 3 files changed, 46 insertions(+), 0 deletions(-)
---
diff --git a/clutter/clutter-base-types.c b/clutter/clutter-base-types.c
index f95beda..90f3812 100644
--- a/clutter/clutter-base-types.c
+++ b/clutter/clutter-base-types.c
@@ -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,
diff --git a/clutter/clutter-types.h b/clutter/clutter-types.h
index 4c5e370..c9c3e0b 100644
--- a/clutter/clutter-types.h
+++ b/clutter/clutter-types.h
@@ -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:
diff --git a/clutter/clutter.symbols b/clutter/clutter.symbols
index 588b022..14f9937 100644
--- a/clutter/clutter.symbols
+++ b/clutter/clutter.symbols
@@ -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



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]