app: add gimp_canvas_item_transform_distance() and transform_distance_square()
to allow items to measure distances, exactly like the identical GimpDrawTool API.
This commit is contained in:
@ -585,6 +585,63 @@ gimp_canvas_item_transform_xy_f (GimpCanvasItem *item,
|
|||||||
gimp_display_shell_zoom_xy_f (item->private->shell, x, y, tx, ty);
|
gimp_display_shell_zoom_xy_f (item->private->shell, x, y, tx, ty);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_canvas_item_transform_distance:
|
||||||
|
* @item: a #GimpCanvasItem
|
||||||
|
* @x1: start point X in image coordinates
|
||||||
|
* @y1: start point Y in image coordinates
|
||||||
|
* @x2: end point X in image coordinates
|
||||||
|
* @y2: end point Y in image coordinates
|
||||||
|
*
|
||||||
|
* If you just need to compare distances, consider to use
|
||||||
|
* gimp_canvas_item_transform_distance_square() instead.
|
||||||
|
*
|
||||||
|
* Returns: the distance between the given points in display coordinates
|
||||||
|
**/
|
||||||
|
gdouble
|
||||||
|
gimp_canvas_item_transform_distance (GimpCanvasItem *item,
|
||||||
|
gdouble x1,
|
||||||
|
gdouble y1,
|
||||||
|
gdouble x2,
|
||||||
|
gdouble y2)
|
||||||
|
{
|
||||||
|
return sqrt (gimp_canvas_item_transform_distance_square (item,
|
||||||
|
x1, y1, x2, y2));
|
||||||
|
}
|
||||||
|
|
||||||
|
/**
|
||||||
|
* gimp_canvas_item_transform_distance_square:
|
||||||
|
* @item: a #GimpCanvasItem
|
||||||
|
* @x1: start point X in image coordinates
|
||||||
|
* @y1: start point Y in image coordinates
|
||||||
|
* @x2: end point X in image coordinates
|
||||||
|
* @y2: end point Y in image coordinates
|
||||||
|
*
|
||||||
|
* This function is more effective than
|
||||||
|
* gimp_canvas_item_transform_distance() as it doesn't perform a
|
||||||
|
* sqrt(). Use this if you just need to compare distances.
|
||||||
|
*
|
||||||
|
* Returns: the square of the distance between the given points in
|
||||||
|
* display coordinates
|
||||||
|
**/
|
||||||
|
gdouble
|
||||||
|
gimp_canvas_item_transform_distance_square (GimpCanvasItem *item,
|
||||||
|
gdouble x1,
|
||||||
|
gdouble y1,
|
||||||
|
gdouble x2,
|
||||||
|
gdouble y2)
|
||||||
|
{
|
||||||
|
gdouble tx1, ty1;
|
||||||
|
gdouble tx2, ty2;
|
||||||
|
|
||||||
|
g_return_val_if_fail (GIMP_IS_CANVAS_ITEM (item), 0.0);
|
||||||
|
|
||||||
|
gimp_canvas_item_transform_xy_f (item, x1, y1, &tx1, &ty1);
|
||||||
|
gimp_canvas_item_transform_xy_f (item, x2, y2, &tx2, &ty2);
|
||||||
|
|
||||||
|
return SQR (tx2 - tx1) + SQR (ty2 - ty1);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* protected functions */
|
/* protected functions */
|
||||||
|
|
||||||
|
@ -113,6 +113,18 @@ void gimp_canvas_item_transform_xy_f (GimpCanvasItem *item,
|
|||||||
gdouble y,
|
gdouble y,
|
||||||
gdouble *tx,
|
gdouble *tx,
|
||||||
gdouble *ty);
|
gdouble *ty);
|
||||||
|
gdouble gimp_canvas_item_transform_distance
|
||||||
|
(GimpCanvasItem *item,
|
||||||
|
gdouble x1,
|
||||||
|
gdouble y1,
|
||||||
|
gdouble x2,
|
||||||
|
gdouble y2);
|
||||||
|
gdouble gimp_canvas_item_transform_distance_square
|
||||||
|
(GimpCanvasItem *item,
|
||||||
|
gdouble x1,
|
||||||
|
gdouble y1,
|
||||||
|
gdouble x2,
|
||||||
|
gdouble y2);
|
||||||
|
|
||||||
|
|
||||||
/* protected */
|
/* protected */
|
||||||
|
Reference in New Issue
Block a user