aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorlecoanet2000-06-21 14:42:19 +0000
committerlecoanet2000-06-21 14:42:19 +0000
commitdb4dc418f59fe5498fddb450a78f677a05cf40ed (patch)
tree67b7dc38dbe779ba788d617bfa44116056db586c
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.
-rw-r--r--Bezier.c61
-rw-r--r--generic/Curve.c67
2 files changed, 122 insertions, 6 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
};
diff --git a/generic/Curve.c b/generic/Curve.c
index 54af677..46eaa05 100644
--- a/generic/Curve.c
+++ b/generic/Curve.c
@@ -1568,6 +1568,68 @@ Contour(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)
+{
+ CurveItem cv = (CurveItem) item;
+ int i, j, k, num_points;
+ ZnPoint *points;
+ ZnReal dist=1.0e40, new_dist, dist2;
+
+ *contour = *vertex = *o_vertex = -1;
+
+ if ((cv->line_width > 0) ||
+ ISSET(cv->flags, FILLED_OK) ||
+ ISSET(cv->flags, MARKER_OK)) {
+ /*
+ * Check all contours.
+ */
+ for (i = 0; i < cv->dev_shape.num_contours; i++) {
+ points = cv->dev_shape.contours[i].points;
+ num_points = cv->dev_shape.contours[i].num_points;
+ for (j = 0; j < num_points; j++) {
+ new_dist = hypot(points[j].x - p->x, points[j].y - p->y);
+ if (new_dist < dist) {
+ dist = new_dist;
+ *contour = i;
+ *vertex = j;
+ }
+ }
+ /*
+ * If the closest vertex is in the current contour update
+ * the opposite vertex.
+ */
+ if (i == *contour) {
+ j = (*vertex+1) % num_points;
+ new_dist = LineToPointDist(&points[*vertex], &points[j], p);
+ k = ((unsigned)(*vertex-1)) % num_points;
+ dist2 = LineToPointDist(&points[*vertex], &points[k], p);
+ if (dist2 < new_dist) {
+ *o_vertex = k;
+ }
+ else {
+ *o_vertex = j;
+ }
+ }
+ }
+ }
+}
+
+
+/*
+ **********************************************************************************
+ *
* Exported functions struct --
*
**********************************************************************************
@@ -1575,7 +1637,7 @@ Contour(Item item,
static ItemClassStruct CURVE_ITEM_CLASS = {
sizeof(CurveItemStruct),
False, /* has_fields */
- False, /* has_parts */
+ 0, /* num_parts */
False, /* has_anchors */
"curve",
cv_attrs,
@@ -1592,6 +1654,7 @@ static ItemClassStruct CURVE_ITEM_CLASS = {
NULL, /* DeleteChars */
NULL, /* Cursor */
NULL, /* Index */
+ NULL, /* Part */
NULL, /* Selection */
#ifdef GPC
Contour,
@@ -1603,7 +1666,7 @@ static ItemClassStruct CURVE_ITEM_CLASS = {
Draw,
IsSensitive,
Pick,
- NULL, /* PickVertex */
+ PickVertex, /* PickVertex */
PostScript
};