From: Paul Ramsey Date: Fri, 2 Nov 2012 19:08:52 +0000 (+0000) Subject: Be a bit more explicit about what we're returning from point-in-ring tests. X-Git-Tag: 2.1.0beta2~426 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=38b913747445b329969cc1499a0db9a272d2587d;p=postgis Be a bit more explicit about what we're returning from point-in-ring tests. git-svn-id: http://svn.osgeo.org/postgis/trunk@10626 b70326c6-7e19-0410-871a-916f4a2858ee --- diff --git a/liblwgeom/cunit/cu_ptarray.c b/liblwgeom/cunit/cu_ptarray.c index 80d3004d5..7ad8ba32f 100644 --- a/liblwgeom/cunit/cu_ptarray.c +++ b/liblwgeom/cunit/cu_ptarray.c @@ -418,49 +418,49 @@ static void test_ptarray_contains_point() pt.x = 0.5; pt.y = 0.5; rv = ptarray_contains_point(pa, &pt); - CU_ASSERT_EQUAL(rv, 1); + CU_ASSERT_EQUAL(rv, LW_INSIDE); /* Point on left edge of square */ pt.x = 0; pt.y = 0.5; rv = ptarray_contains_point(pa, &pt); - CU_ASSERT_EQUAL(rv, 0); + CU_ASSERT_EQUAL(rv, LW_BOUNDARY); /* Point on top edge of square */ pt.x = 0.5; pt.y = 1; rv = ptarray_contains_point(pa, &pt); - CU_ASSERT_EQUAL(rv, 0); + CU_ASSERT_EQUAL(rv, LW_BOUNDARY); /* Point on bottom left corner of square */ pt.x = 0; pt.y = 0; rv = ptarray_contains_point(pa, &pt); - CU_ASSERT_EQUAL(rv, 0); + CU_ASSERT_EQUAL(rv, LW_BOUNDARY); /* Point on top left corner of square */ pt.x = 0; pt.y = 1; rv = ptarray_contains_point(pa, &pt); - CU_ASSERT_EQUAL(rv, 0); + CU_ASSERT_EQUAL(rv, LW_BOUNDARY); /* Point outside top left corner of square */ pt.x = -0.1; pt.y = 1; rv = ptarray_contains_point(pa, &pt); - CU_ASSERT_EQUAL(rv, -1); + CU_ASSERT_EQUAL(rv, LW_OUTSIDE); /* Point outside top left corner of square */ pt.x = 0; pt.y = 1.1; rv = ptarray_contains_point(pa, &pt); - CU_ASSERT_EQUAL(rv, -1); + CU_ASSERT_EQUAL(rv, LW_OUTSIDE); /* Point outside left side of square */ pt.x = -0.2; pt.y = 0.5; rv = ptarray_contains_point(pa, &pt); - CU_ASSERT_EQUAL(rv, -1); + CU_ASSERT_EQUAL(rv, LW_OUTSIDE); lwline_free(lwline); lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0, 1 1, 2 0, 0 0)")); @@ -470,7 +470,7 @@ static void test_ptarray_contains_point() pt.x = 0; pt.y = 1; rv = ptarray_contains_point(pa, &pt); - CU_ASSERT_EQUAL(rv, -1); + CU_ASSERT_EQUAL(rv, LW_OUTSIDE); lwline_free(lwline); lwline = lwgeom_as_lwline(lwgeom_from_text("LINESTRING(0 0, 0 4, 1 4, 2 2, 3 4, 4 4, 4 0, 0 0)")); @@ -480,13 +480,13 @@ static void test_ptarray_contains_point() pt.x = 1; pt.y = 2; rv = ptarray_contains_point(pa, &pt); - CU_ASSERT_EQUAL(rv, 1); + CU_ASSERT_EQUAL(rv, LW_INSIDE); /* Point outside grazing top of triangle */ pt.x = 3; pt.y = 2; rv = ptarray_contains_point(pa, &pt); - CU_ASSERT_EQUAL(rv, 1); + CU_ASSERT_EQUAL(rv, LW_INSIDE); lwline_free(lwline); } @@ -509,31 +509,31 @@ static void test_ptarray_contains_point_arc() pt.x = 0; pt.y = 0; rv = ptarray_contains_point_arc(pa, &pt); - CU_ASSERT_EQUAL(rv, 1); + CU_ASSERT_EQUAL(rv, LW_INSIDE); /* Point in left lobe */ pt.x = -1.1; pt.y = 0.1; rv = ptarray_contains_point_arc(pa, &pt); - CU_ASSERT_EQUAL(rv, 1); + CU_ASSERT_EQUAL(rv, LW_INSIDE); /* Point on boundary of left lobe */ pt.x = -1; pt.y = 0; rv = ptarray_contains_point_arc(pa, &pt); - CU_ASSERT_EQUAL(rv, 1); + CU_ASSERT_EQUAL(rv, LW_INSIDE); /* Point on boundary vertex */ pt.x = -1; pt.y = 1; rv = ptarray_contains_point_arc(pa, &pt); - CU_ASSERT_EQUAL(rv, 0); + CU_ASSERT_EQUAL(rv, LW_BOUNDARY); /* Point outside */ pt.x = -1.5; pt.y = 1.5; rv = ptarray_contains_point_arc(pa, &pt); - CU_ASSERT_EQUAL(rv, -1); + CU_ASSERT_EQUAL(rv, LW_OUTSIDE); /* Two-edge ring made up of semi-circles (really, a circle) */ lwfree(lwline); @@ -545,25 +545,25 @@ static void test_ptarray_contains_point_arc() pt.x = -1.5; pt.y = 1.5; rv = ptarray_contains_point_arc(pa, &pt); - CU_ASSERT_EQUAL(rv, -1); + CU_ASSERT_EQUAL(rv, LW_OUTSIDE); /* Point inside at middle */ pt.x = 0; pt.y = 0; rv = ptarray_contains_point_arc(pa, &pt); - CU_ASSERT_EQUAL(rv, 1); + CU_ASSERT_EQUAL(rv, LW_INSIDE); /* Point inside offset from middle */ pt.x = 0.01; pt.y = 0.01; rv = ptarray_contains_point_arc(pa, &pt); - CU_ASSERT_EQUAL(rv, 1); + CU_ASSERT_EQUAL(rv, LW_INSIDE); /* Point on edge vertex */ pt.x = 0; pt.y = 1; rv = ptarray_contains_point_arc(pa, &pt); - CU_ASSERT_EQUAL(rv, 0); + CU_ASSERT_EQUAL(rv, LW_BOUNDARY); /* One-edge ring, closed circle */ lwfree(lwline); @@ -574,19 +574,19 @@ static void test_ptarray_contains_point_arc() pt.x = 0; pt.y = 0; rv = ptarray_contains_point_arc(pa, &pt); - CU_ASSERT_EQUAL(rv, 1); + CU_ASSERT_EQUAL(rv, LW_INSIDE); /* Point outside */ pt.x = 0; pt.y = 2; rv = ptarray_contains_point_arc(pa, &pt); - CU_ASSERT_EQUAL(rv, -1); + CU_ASSERT_EQUAL(rv, LW_OUTSIDE); /* Point on boundary */ pt.x = 0; pt.y = 1; rv = ptarray_contains_point_arc(pa, &pt); - CU_ASSERT_EQUAL(rv, 0); + CU_ASSERT_EQUAL(rv, LW_BOUNDARY); /* Overshort ring */ lwfree(lwline); diff --git a/liblwgeom/measures.c b/liblwgeom/measures.c index 2bc52dcab..a44de8e61 100644 --- a/liblwgeom/measures.c +++ b/liblwgeom/measures.c @@ -4,6 +4,7 @@ * http://postgis.refractions.net * Copyright 2001-2006 Refractions Research Inc. * Copyright 2010 Nicklas Avén + * Copyright 2012 Paul Ramsey * * This is free software; you can redistribute and/or modify it under * the terms of the GNU General Public Licence. See the COPYING file. @@ -520,7 +521,7 @@ lw_dist2d_point_poly(LWPOINT *point, LWPOLY *poly, DISTPTS *dl) return lw_dist2d_pt_ptarray(&p, poly->rings[0], dl); } /* Return distance to outer ring if not inside it */ - if ( ! pt_in_ring_2d(&p, poly->rings[0]) ) + if ( ptarray_contains_point(poly->rings[0], &p) == LW_OUTSIDE ) { LWDEBUG(3, "first point not inside outer-ring"); return lw_dist2d_pt_ptarray(&p, poly->rings[0], dl); @@ -535,7 +536,7 @@ lw_dist2d_point_poly(LWPOINT *point, LWPOLY *poly, DISTPTS *dl) for (i=1; inrings; i++) { /* Inside a hole. Distance = pt -> ring */ - if ( pt_in_ring_2d(&p, poly->rings[i]) ) + if ( ptarray_contains_point(poly->rings[i], &p) != LW_OUTSIDE ) { LWDEBUG(3, " inside an hole"); return lw_dist2d_pt_ptarray(&p, poly->rings[i], dl); @@ -604,10 +605,10 @@ lw_dist2d_poly_poly(LWPOLY *poly1, LWPOLY *poly2, DISTPTS *dl) /* 2 check if poly1 has first point outside poly2 and vice versa, if so, just check outer rings here it would be possible to handle the information about wich one is inside wich one and only search for the smaller ones in the bigger ones holes.*/ getPoint2d_p(poly1->rings[0], 0, &pt); - if ( !pt_in_ring_2d(&pt, poly2->rings[0])) + if ( ptarray_contains_point(poly2->rings[0], &pt) == LW_OUTSIDE ) { getPoint2d_p(poly2->rings[0], 0, &pt); - if (!pt_in_ring_2d(&pt, poly1->rings[0])) + if ( ptarray_contains_point(poly1->rings[0], &pt) == LW_OUTSIDE ) { return lw_dist2d_ptarray_ptarray(poly1->rings[0], poly2->rings[0],dl); } @@ -618,7 +619,7 @@ lw_dist2d_poly_poly(LWPOLY *poly1, LWPOLY *poly2, DISTPTS *dl) for (i=1; inrings; i++) { /* Inside a hole */ - if ( pt_in_ring_2d(&pt, poly1->rings[i]) ) + if ( ptarray_contains_point(poly1->rings[i], &pt) != LW_OUTSIDE ) { return lw_dist2d_ptarray_ptarray(poly1->rings[i], poly2->rings[0],dl); } @@ -629,7 +630,7 @@ lw_dist2d_poly_poly(LWPOLY *poly1, LWPOLY *poly2, DISTPTS *dl) for (i=1; inrings; i++) { /* Inside a hole */ - if ( pt_in_ring_2d(&pt, poly2->rings[i]) ) + if ( ptarray_contains_point(poly2->rings[i], &pt) != LW_OUTSIDE ) { return lw_dist2d_ptarray_ptarray(poly1->rings[0], poly2->rings[i],dl); } @@ -638,7 +639,7 @@ lw_dist2d_poly_poly(LWPOLY *poly1, LWPOLY *poly2, DISTPTS *dl) /*5 If we have come all the way here we know that the first point of one of them is inside the other ones outer ring and not in holes so we check wich one is inside.*/ getPoint2d_p(poly1->rings[0], 0, &pt); - if ( pt_in_ring_2d(&pt, poly2->rings[0])) + if ( ptarray_contains_point(poly2->rings[0], &pt) != LW_OUTSIDE ) { dl->distance=0.0; dl->p1.x=pt.x; @@ -649,7 +650,7 @@ lw_dist2d_poly_poly(LWPOLY *poly1, LWPOLY *poly2, DISTPTS *dl) } getPoint2d_p(poly2->rings[0], 0, &pt); - if (pt_in_ring_2d(&pt, poly1->rings[0])) + if ( ptarray_contains_point(poly1->rings[0], &pt) != LW_OUTSIDE ) { dl->distance=0.0; dl->p1.x=pt.x; @@ -765,7 +766,7 @@ lw_dist2d_ptarray_poly(POINTARRAY *pa, LWPOLY *poly, DISTPTS *dl) LWDEBUGF(2, "lw_dist2d_ptarray_poly called (%d rings)", poly->nrings); getPoint2d_p(pa, 0, &pt); - if ( !pt_in_ring_2d(&pt, poly->rings[0])) + if ( ptarray_contains_point(poly->rings[0], &pt) == LW_OUTSIDE ) { return lw_dist2d_ptarray_ptarray(pa,poly->rings[0],dl); } @@ -776,7 +777,8 @@ lw_dist2d_ptarray_poly(POINTARRAY *pa, LWPOLY *poly, DISTPTS *dl) LWDEBUGF(3, " distance from ring %d: %f, mindist: %f", i, dl->distance, dl->tolerance); - if (dl->distance<=dl->tolerance && dl->mode == DIST_MIN) return LW_TRUE; /*just a check if the answer is already given*/ + /* just a check if the answer is already given */ + if (dl->distance<=dl->tolerance && dl->mode == DIST_MIN) return LW_TRUE; } /* @@ -800,7 +802,7 @@ lw_dist2d_ptarray_poly(POINTARRAY *pa, LWPOLY *poly, DISTPTS *dl) */ for (i=1; inrings; i++) { - if ( pt_in_ring_2d(&pt, poly->rings[i]) ) + if ( ptarray_contains_point(poly->rings[i], &pt) != LW_OUTSIDE ) { /* * Its inside a hole, then the actual @@ -1734,18 +1736,6 @@ Functions in common for Brute force and new calculation --------------------------------------------------------------------------------------------------------------*/ /** - * pt_in_ring_2d(): crossing number test for a point in a polygon - * input: p = a point, - * pa = vertex points of a ring V[n+1] with V[n]=V[0] - * returns: 0 = outside, 1 = inside - * - * Our polygons have first and last point the same, - * - */ - - -/** - lw_dist2d_comp from p to line A->B This one is now sending every occation to lw_dist2d_pt_pt Before it was handling occations where r was between 0 and 1 internally diff --git a/liblwgeom/ptarray.c b/liblwgeom/ptarray.c index fe8ea7976..4877edc31 100644 --- a/liblwgeom/ptarray.c +++ b/liblwgeom/ptarray.c @@ -737,7 +737,7 @@ ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt) */ if ( (side == 0) && lw_pt_in_seg(pt, seg1, seg2) ) { - return 0; + return LW_BOUNDARY; } /* @@ -766,11 +766,11 @@ ptarray_contains_point(const POINTARRAY *pa, const POINT2D *pt) /* Outside */ if (wn == 0) { - return -1; + return LW_OUTSIDE; } /* Inside */ - return 1; + return LW_INSIDE; } /**