From aeb6614d329edc6042b50f3ace790d5283d98815 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Fri, 12 Jan 2001 16:37:43 +0000 Subject: -closed est � false par d�faut. Le premier et le dernier point d'une curve non -closed sont conserv�s m�me s'ils sont identiques. --- generic/Curve.c | 62 +++++++++++++++++++++++---------------------------------- 1 file changed, 25 insertions(+), 37 deletions(-) diff --git a/generic/Curve.c b/generic/Curve.c index 8b43a36..efed448 100644 --- a/generic/Curve.c +++ b/generic/Curve.c @@ -224,7 +224,7 @@ Init(Item item, SET(item->flags, SENSITIVE_BIT); SET(item->flags, COMPOSE_ROTATION_BIT); SET(item->flags, COMPOSE_SCALE_BIT); - SET(cv->flags, CLOSED_BIT); + CLEAR(cv->flags, CLOSED_BIT); SET(cv->flags, REDUCED_BIT); item->priority = DEFAULT_CURVE_PRIORITY; @@ -689,21 +689,18 @@ ComputeCoordinates(Item item, c1 = cv->shape.contours; c2 = cv->dev_shape.contours; for (i = 0; i < cv->shape.num_contours; i++, c1++, c2++) { - /* - * Drop the last point of a contour if it is the same as - * the first. - */ - if ((c1->points[0].x == c1->points[c1->num_points-1].x) && - (c1->points[0].y == c1->points[c1->num_points-1].y) && - (c1->num_points != 1)) { - c1->num_points--; - } c2->num_points = c1->num_points; /* - * The device array is always one point larger to accomodate - * the outline end point when CLOSED is specified. + * Add a point at the end of the contour to close it + * if needed. */ - c2->points = (ZnPoint *) ZnMalloc((c1->num_points+1)*sizeof(ZnPoint)); + if (ISSET(cv->flags, CLOSED_BIT) && + ((c2->points[0].x != c2->points[c2->num_points-1].x) || + (c2->points[0].y != c2->points[c2->num_points-1].y)) && + (c2->num_points != 1)) { + c2->num_points++; + } + c2->points = (ZnPoint *) ZnMalloc((c2->num_points)*sizeof(ZnPoint)); /*printf("CC: \"%d\" num_points %d\n", item->id, c1->num_points);*/ } @@ -714,8 +711,11 @@ ComputeCoordinates(Item item, c2 = cv->dev_shape.contours; for (j = 0; j < num_contours; j++, c1++, c2++) { ZnTransformPoints(wi->current_transfo, c1->points, c2->points, c1->num_points); - if (ISSET(cv->flags, CLOSED_BIT)) { - c2->points[c2->num_points] = c2->points[0]; + /* + * Close the curve if needed. + */ + if (c1->num_points != c2->num_points) { + c2->points[c2->num_points-1] = c2->points[0]; } } @@ -729,10 +729,10 @@ ComputeCoordinates(Item item, #ifdef LIBART ArtVpath *vpath; - c1 = cv->dev_shape.contours; - vpath = (ArtVpath *) ZnMalloc((c1->num_points+2) * sizeof(ArtVpath)); - points = c1->points; - for (i = 0; i < c1->num_points; i++, points++) { + c2 = cv->dev_shape.contours; + vpath = (ArtVpath *) ZnMalloc((c2->num_points+2) * sizeof(ArtVpath)); + points = c2->points; + for (i = 0; i < c2->num_points; i++, points++) { vpath[i].code = ART_LINETO; vpath[i].x = points->x; vpath[i].y = points->y; @@ -937,13 +937,11 @@ ToArea(Item item, if (!first_done) { first_done = True; if (ISCLEAR(cv->flags, RELIEF_OK)) { - result = PolylineInBBox(points, - ISSET(cv->flags, CLOSED_BIT)?num_points+1:num_points, + result = PolylineInBBox(points, num_points, cv->line_width, cv->cap_style, cv->join_style, area); } else { - result = PolygonReliefInBBox(points, - ISSET(cv->flags, CLOSED_BIT)?num_points+1:num_points, + result = PolygonReliefInBBox(points, num_points, (cv->dev_shape.cw[0]^cv->shape.holes[0])?-cv->line_width:cv->line_width, area); } if (result == 0) { @@ -952,13 +950,11 @@ ToArea(Item item, } else { if (ISCLEAR(cv->flags, RELIEF_OK)) { - result2 = PolylineInBBox(points, - ISSET(cv->flags, CLOSED_BIT)?num_points+1:num_points, + result2 = PolylineInBBox(points, num_points, cv->line_width, cv->cap_style, cv->join_style, area); } else { - result2 = PolygonReliefInBBox(points, - ISSET(cv->flags, CLOSED_BIT)?num_points+1:num_points, + result2 = PolygonReliefInBBox(points, num_points, (cv->dev_shape.cw[0]^cv->shape.holes[0])?-cv->line_width:cv->line_width, area); } if (result2 != result) { @@ -1125,9 +1121,6 @@ Draw(Item item) for (j = 0; j < cv->dev_shape.num_contours; j++) { num_points = cv->dev_shape.contours[j].num_points; points = cv->dev_shape.contours[j].points; - if (ISSET(cv->flags, CLOSED_BIT)) { - num_points++; - } /*printf("Draw: num_points %d %g@%g %g@%g, cw %d\n", num_points, points[0].x, points[0].y, points[num_points-1].x, points[num_points-1].y, @@ -1157,9 +1150,6 @@ Draw(Item item) for (j = 0; j < cv->dev_shape.num_contours; j++) { num2 = num_points = cv->dev_shape.contours[j].num_points; points = cv->dev_shape.contours[j].points; - if (ISSET(cv->flags, CLOSED_BIT)) { - num_points++; - } ZnListAssertSize(wi->work_xpts, num_points); xpoints = (XPoint *) ZnListArray(wi->work_xpts); for (i = 0; i < num2; i++) { @@ -1365,8 +1355,7 @@ Pick(Item item, points = cv->dev_shape.contours[i].points; num_points = cv->dev_shape.contours[i].num_points; if (ISCLEAR(cv->flags, RELIEF_OK)) { - new_dist = PolylineToPointDist(points, - ISSET(cv->flags, CLOSED_BIT)?num_points+1:num_points, + new_dist = PolylineToPointDist(points, num_points, cv->line_width, cv->cap_style, cv->join_style, p); if (new_dist < dist) { dist = new_dist; @@ -1376,8 +1365,7 @@ Pick(Item item, } } else { - new_dist = PolygonReliefToPointDist(points, - ISSET(cv->flags, CLOSED_BIT)?num_points+1:num_points, + new_dist = PolygonReliefToPointDist(points, num_points, (cv->dev_shape.cw[0]^cv->shape.holes[0])?-cv->line_width:cv->line_width, p); if (new_dist < dist) { dist = new_dist; -- cgit v1.1