From 6e869eb5e6ff1686a865d2a334ed1f6a2d7915b1 Mon Sep 17 00:00:00 2001 From: lecoanet Date: Mon, 9 Dec 2002 14:38:04 +0000 Subject: * Adaptation de POLY_CONTOUR et POLY_SET pour tenir compte de cw. * Reprise du code de TestCCW pir qu'il fonctionne mieux. --- generic/Geo.c | 36 +++++++++++++++++++++++++++--------- 1 file changed, 27 insertions(+), 9 deletions(-) (limited to 'generic/Geo.c') diff --git a/generic/Geo.c b/generic/Geo.c index 2039e77..8cd2edf 100644 --- a/generic/Geo.c +++ b/generic/Geo.c @@ -46,17 +46,20 @@ void POLY_INIT(ZnPoly *poly) { poly->num_contours = 0; + poly->contours = NULL; } void POLY_CONTOUR1(ZnPoly *poly, ZnPoint *pts, - int num_pts) + int num_pts, + ZnBool cw) { poly->num_contours = 1; poly->contours = &poly->contour1; poly->contour1.num_points = num_pts; poly->contour1.points = pts; + poly->contour1.cw = cw; } void @@ -65,7 +68,8 @@ POLY_SET(ZnPoly *poly1, { POLY_FREE(poly1); if (poly2->num_contours == 1) { - POLY_CONTOUR1(poly1, poly2->contours[0].points, poly2->contours[0].num_points); + POLY_CONTOUR1(poly1, poly2->contours[0].points, poly2->contours[0].num_points, + poly2->contours[0].cw); if (poly2->contours != &poly2->contour1) { ZnFree(poly2->contours); } @@ -534,7 +538,7 @@ ZnBool TestCCW(ZnPoint *points, int num_points) { - ZnPoint *p, *p_p, *p_n, min; + ZnPoint *p, *p_p=NULL, *p_n=NULL, min; ZnReal xprod; int i, min_index; @@ -563,12 +567,26 @@ TestCCW(ZnPoint *points, p = &points[min_index]; /*printf("min index %d, prev %d, next %d\n", min_index, (min_index+(num_points-1))%num_points, (min_index+1)%num_points);*/ - p_p = &points[(min_index+(num_points-1))%num_points]; /* min_index-1 */ - p_n = &points[(min_index+1)%num_points]; - xprod = ((p_p->x*p->y - p_p->y*p->x) + - (p_p->y*p_n->x - p_p->x*p_n->y) + - (p->x*p_n->y - p->y*p_n->x)); - return (xprod <= 0.0); /* Should be >= 0 but X11 has Y axis reverted. */ + /*printf("lower point index %d %d %d\n", + (min_index+(num_points-1))%num_points, min_index, (min_index+1)%num_points);*/ + /* + * Try to find preceding and following points that are not + * the same as the base point. + */ + for (i = 1; i < num_points; i++) { + p_p = &points[(min_index+(num_points-i))%num_points]; /* min_index-1 */ + if ((p_p->x != p->x) || (p_p->y != p->y)) { + break; + } + } + for (i = 1; i < num_points; i++) { + p_n = &points[(min_index+i)%num_points]; + if ((p_p->x != p->x) || (p_p->y != p->y)) { + break; + } + } + xprod = ((p->x - p_p->x) * (p_n->y - p->y)) - ((p->y - p_p->y) * (p_n->x - p->x)); + return (xprod < 0.0); /* Should be > 0 but X11 has Y axis reverted. */ } -- cgit v1.1