From db4dc418f59fe5498fddb450a78f677a05cf40ed Mon Sep 17 00:00:00 2001 From: lecoanet Date: Wed, 21 Jun 2000 14:42:19 +0000 Subject: Ajustement des structures de classe pour ajout de la m�thode Part. Ecriture de la m�thode PickVertex. --- Bezier.c | 61 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++---- 1 file changed, 57 insertions(+), 4 deletions(-) (limited to 'Bezier.c') diff --git a/Bezier.c b/Bezier.c index 0de6af5..7bba1d5 100644 --- a/Bezier.c +++ b/Bezier.c @@ -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 }; -- cgit v1.1