[gimp/soc-2010-cage-2] GimpCageConfig: add 2 method to check if a point is inside the cage. Second one is commented, for te



commit eabbabb571bb14bb4c4922b675a467e5b6291cee
Author: Michael Muré <batolettre gmail com>
Date:   Wed Aug 11 20:11:49 2010 +0200

    GimpCageConfig: add 2 method to check if a point is inside the cage.
    Second one is commented, for test.

 app/gegl/gimpcageconfig.c |   63 +++++++++++++++++++++++++++++++++++++++++++++
 app/gegl/gimpcageconfig.h |   14 ++++++++++
 2 files changed, 77 insertions(+), 0 deletions(-)
---
diff --git a/app/gegl/gimpcageconfig.c b/app/gegl/gimpcageconfig.c
index cac44c0..9813879 100644
--- a/app/gegl/gimpcageconfig.c
+++ b/app/gegl/gimpcageconfig.c
@@ -401,3 +401,66 @@ gimp_cage_config_compute_scaling_factor (GimpCageConfig *gcc)
 
   print_cage (gcc);
 }
+
+gboolean
+gimp_cage_config_point_inside (GimpCageConfig *gcc,
+                               gfloat          x,
+                               gfloat          y)
+{
+  gint i, j;
+  gboolean inside = FALSE;
+  GimpVector2 *cv = gcc->cage_vertices;
+  
+  g_return_val_if_fail (GIMP_IS_CAGE_CONFIG (gcc), FALSE);
+  
+  for (i = 0, j = gcc->cage_vertice_number - 1; i < gcc->cage_vertice_number; j = i++)
+  {
+    if ((((cv[i].y <= y) && (y < cv[j].y))
+        || ((cv[j].y <= y) && (y < cv[i].y)))
+        && (x < (cv[j].x - cv[i].x) * (y - cv[i].y) / (cv[j].y - cv[i].y) + cv[i].x))
+    {
+      inside = !inside;
+    }
+  }
+  
+  return inside;
+}
+
+
+/*static inline gint
+gimp_cage_config_is_left (GimpVector2 *p0, GimpVector2 *p1, GimpVector2 *p2)
+{
+  return ( (p1->x - p0->x) * (p2->y - p0->y) - (p2->x - p0->x) * (p1->y - p0->y) );
+}
+
+gboolean
+gimp_cage_config_point_inside (GimpCageConfig *gcc,
+                               gfloat          x,
+                               gfloat          y)
+{
+  gint wn = 0;
+  gint i;
+  gint cvn = gcc->cage_vertice_number;
+  GimpVector2 *cv = gcc->cage_vertices;
+  GimpVector2 p = {x, y};
+  
+  for (i = 0; i < gcc->cage_vertice_number; i++)
+  {
+    if (cv[i].y <= y)
+    {
+      if ((cv[(i+1) % cvn].y > y) && gimp_cage_config_is_left (&cv[i], &cv[(i+1) % cvn], &p) > 0)
+      {
+        wn++;
+      }
+    }
+    else
+    {
+      if ((cv[(i+1) % cvn].y <= y) && gimp_cage_config_is_left (&cv[i], &cv[(i+1) % cvn], &p) < 0)
+      {
+        wn--;
+      }
+    }
+  }
+  
+  return (wn > 0);
+}*/
diff --git a/app/gegl/gimpcageconfig.h b/app/gegl/gimpcageconfig.h
index 6fa9ed9..6d85d3c 100644
--- a/app/gegl/gimpcageconfig.h
+++ b/app/gegl/gimpcageconfig.h
@@ -149,4 +149,18 @@ void          gimp_cage_config_reverse_cage_if_needed (GimpCageConfig  *gcc);
  */
 void          gimp_cage_config_reverse_cage           (GimpCageConfig *gcc);
 
+
+/**
+ * gimp_cage_config_point_inside:
+ * @gcc: the cage config
+ * @x: x coordinate of the point to test
+ * @y: y coordinate of the point to test
+ * 
+ * Check if the given point is inside the cage. This test is done in the regard of the topological inside of the cage.
+ * 
+ * Returns: TRUE if the point is inside, FALSE if not.
+ */
+gboolean      gimp_cage_config_point_inside           (GimpCageConfig *gcc,
+                                                       gfloat          x,
+                                                       gfloat          y);
 #endif /* __GIMP_CAGE_CONFIG_H__ */



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