[gimp/metadata-browser] transformtool: Pick move operation anywhere inside polygon



commit 5421ea295aec6f4ee73c5b63824bfc38cdc634c4
Author: Mikael Magnusson <mikachu src gnome org>
Date:   Tue Aug 14 21:15:12 2012 +0200

    transformtool: Pick move operation anywhere inside polygon

 app/tools/gimpunifiedtransformtool.c |   28 ++++++++++++++++++++++++++++
 1 files changed, 28 insertions(+), 0 deletions(-)
---
diff --git a/app/tools/gimpunifiedtransformtool.c b/app/tools/gimpunifiedtransformtool.c
index 3949430..26a9ed1 100644
--- a/app/tools/gimpunifiedtransformtool.c
+++ b/app/tools/gimpunifiedtransformtool.c
@@ -135,6 +135,25 @@ gimp_unified_transform_tool_init (GimpUnifiedTransformTool *unified_tool)
   tr_tool->use_handles = TRUE;
 }
 
+static gboolean
+point_is_inside_polygon (gint n, gdouble *x, gdouble *y, gdouble px, gdouble py)
+{
+  int i, j;
+  gboolean odd = FALSE;
+
+  for (i = 0, j = n - 1; i < n; j = i++)
+    {
+      if ((y[i] < py && y[j] >= py) ||
+          (y[j] < py && y[i] >= py))
+        {
+          if (x[i] + (py - y[i]) / (y[j] - y[i]) * (x[j] - x[i]) < px)
+            odd = !odd;
+        }
+    }
+
+  return odd;
+}
+
 static TransformAction
 gimp_unified_transform_tool_pick_function (GimpTransformTool *tr_tool,
                                            const GimpCoords  *coords,
@@ -150,6 +169,15 @@ gimp_unified_transform_tool_pick_function (GimpTransformTool *tr_tool,
       }
   }
 
+  /* points passed in clockwise order */
+  if (point_is_inside_polygon (4, 
+                               (gdouble[4]){ tr_tool->tx1, tr_tool->tx2, 
+                                             tr_tool->tx4, tr_tool->tx3 },
+                               (gdouble[4]){ tr_tool->ty1, tr_tool->ty2,
+                                             tr_tool->ty4, tr_tool->ty3 },
+                               coords->x, coords->y))
+      return TRANSFORM_HANDLE_CENTER;
+
   return TRANSFORM_HANDLE_NONE;
 }
 



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