diff options
Diffstat (limited to 'Bezier.c')
-rw-r--r-- | Bezier.c | 61 |
1 files changed, 57 insertions, 4 deletions
@@ -1087,15 +1087,67 @@ Coords(Item item, /* ********************************************************************************** * + * PickVertex -- + * Return in 'vertex' the vertex closest to p and in 'o_vertex' the + * opposite vertex on the closest edge, if such an edge exists or -1 + * in the other case. + * + ********************************************************************************** + */ +static void +PickVertex(Item item, + ZnPoint *p, + int *contour, + int *vertex, + int *o_vertex) +{ + BezierItem bz = (BezierItem) item; + int i, k, num_points; + ZnPoint *points; + ZnReal dist=1.0e40, new_dist, dist2; + + *contour = *vertex = *o_vertex = -1; + + if ((bz->line_width > 0) || ISSET(bz->flags, FILLED_OK)) { + points = (ZnPoint *) ZnListArray(bz->dev_points); + num_points = ZnListSize(bz->dev_points); + for (i = 0; i < num_points; i++) { + new_dist = hypot(points[i].x - p->x, points[i].y - p->y); + if (new_dist < dist) { + dist = new_dist; + *contour = 0; + *vertex = i; + } + } + /* + * Update the opposite vertex. + */ + i = (*vertex+1) % num_points; + new_dist = LineToPointDist(&points[*vertex], &points[i], p); + k = ((unsigned)(*vertex-1)) % num_points; + dist2 = LineToPointDist(&points[*vertex], &points[k], p); + if (dist2 < new_dist) { + *o_vertex = k; + } + else { + *o_vertex = i; + } + } +} + + +/* + ********************************************************************************** + * * Exported functions struct -- * ********************************************************************************** */ static ItemClassStruct BEZIER_ITEM_CLASS = { sizeof(BezierItemStruct), - False, - False, - False, + False, /* has_fields */ + 0, /* num_parts */ + False, /* has_anchors */ "bezier", bz_attrs, Init, @@ -1111,6 +1163,7 @@ static ItemClassStruct BEZIER_ITEM_CLASS = { NULL, /* DeleteChars */ NULL, /* Cursor */ NULL, /* Index */ + NULL, /* Part */ NULL, /* Selection */ NULL, /* Contour */ ComputeCoordinates, @@ -1118,7 +1171,7 @@ static ItemClassStruct BEZIER_ITEM_CLASS = { Draw, IsSensitive, Pick, - NULL, /* PickVertex */ + PickVertex, /* PickVertex */ PostScript }; |