transformtool: Pick move operation anywhere inside polygon

This commit is contained in:
Mikael Magnusson 2012-08-14 21:15:12 +02:00
parent a0d79634ed
commit c37619ade7
1 changed files with 28 additions and 0 deletions

View File

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