aboutsummaryrefslogtreecommitdiff
path: root/Bezier.c
diff options
context:
space:
mode:
authorlecoanet2000-06-21 14:42:19 +0000
committerlecoanet2000-06-21 14:42:19 +0000
commitdb4dc418f59fe5498fddb450a78f677a05cf40ed (patch)
tree67b7dc38dbe779ba788d617bfa44116056db586c /Bezier.c
parent8881ae7cbc5e6e1d3f475c7de2534ce00ae1f2e8 (diff)
downloadtkzinc-db4dc418f59fe5498fddb450a78f677a05cf40ed.zip
tkzinc-db4dc418f59fe5498fddb450a78f677a05cf40ed.tar.gz
tkzinc-db4dc418f59fe5498fddb450a78f677a05cf40ed.tar.bz2
tkzinc-db4dc418f59fe5498fddb450a78f677a05cf40ed.tar.xz
Ajustement des structures de classe pour ajout de la m�thode Part.
Ecriture de la m�thode PickVertex.
Diffstat (limited to 'Bezier.c')
-rw-r--r--Bezier.c61
1 files changed, 57 insertions, 4 deletions
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
};