line2pts("LINESTRING(50 -10.999999999999998224, -10.0 50.0)", &A1, &A2);
line2pts("LINESTRING(-10.0 50.0, -10.272779983831613393 -16.937003313332997578)", &B1, &B2);
rv = edge_intersects(&A1, &A2, &B1, &B2);
- CU_ASSERT(rv > 0);
+ CU_ASSERT(rv & PIR_INTERSECTS);
/* Medford case, very short segment vs very long one */
g.lat = 0.74123572595649878103;
g.lon = 2.1065275171200439353;
geog2cart(&g, &B2);
rv = edge_intersects(&A1, &A2, &B1, &B2);
- CU_ASSERT_EQUAL(rv, 1);
+ CU_ASSERT(rv == PIR_INTERSECTS);
/* Again, this time with a less exact input edge. */
line2pts("LINESTRING(-123.165031277506 42.4696787216231, -123.165031605021 42.4697127292275)", &A1, &A2);
line2pts("LINESTRING(-1.0 0.0, 1.0 0.0)", &A1, &A2);
line2pts("LINESTRING(0.0 -1.0, 0.0 1.0)", &B1, &B2);
rv = edge_intersects(&A1, &A2, &B1, &B2);
- CU_ASSERT_EQUAL(rv, PIR_INTERSECTS);
+ CU_ASSERT(rv == PIR_INTERSECTS);
/* No intersection at (0 0) */
line2pts("LINESTRING(-1.0 0.0, 1.0 0.0)", &A1, &A2);
line2pts("LINESTRING(0.0 -1.0, 0.0 -2.0)", &B1, &B2);
rv = edge_intersects(&A1, &A2, &B1, &B2);
- CU_ASSERT_EQUAL(rv, 0);
+ CU_ASSERT(rv == 0);
/* End touches middle of segment at (0 0) */
line2pts("LINESTRING(-1.0 0.0, 1.0 0.0)", &A1, &A2);
line2pts("LINESTRING(0.0 -1.0, 0.0 0.0)", &B1, &B2);
rv = edge_intersects(&A1, &A2, &B1, &B2);
- printf("\nEnd touches middle of segment: %d\n", rv);
- CU_ASSERT_EQUAL(rv, PIR_INTERSECTS|PIR_B_TOUCH_RIGHT);
+ CU_ASSERT(rv == (PIR_INTERSECTS|PIR_B_TOUCH_RIGHT) );
/* End touches end of segment at (0 0) */
line2pts("LINESTRING(0.0 0.0, 1.0 0.0)", &A1, &A2);
line2pts("LINESTRING(0.0 -1.0, 0.0 0.0)", &B1, &B2);
rv = edge_intersects(&A1, &A2, &B1, &B2);
- printf("End touches end of segment: %d\n", rv);
- CU_ASSERT_EQUAL(rv, PIR_INTERSECTS|PIR_B_TOUCH_RIGHT|PIR_A_TOUCH_RIGHT);
+ CU_ASSERT(rv == (PIR_INTERSECTS|PIR_B_TOUCH_RIGHT|PIR_A_TOUCH_RIGHT) );
/* Intersection at (180 0) */
line2pts("LINESTRING(-179.0 -1.0, 179.0 1.0)", &A1, &A2);
line2pts("LINESTRING(-179.0 1.0, 179.0 -1.0)", &B1, &B2);
rv = edge_intersects(&A1, &A2, &B1, &B2);
- CU_ASSERT_EQUAL(rv, PIR_INTERSECTS);
+ CU_ASSERT(rv == PIR_INTERSECTS);
/* Intersection at (180 0) */
line2pts("LINESTRING(-170.0 0.0, 170.0 0.0)", &A1, &A2);
line2pts("LINESTRING(180.0 -10.0, 180.0 10.0)", &B1, &B2);
rv = edge_intersects(&A1, &A2, &B1, &B2);
- CU_ASSERT_EQUAL(rv, PIR_INTERSECTS);
+ CU_ASSERT(rv == PIR_INTERSECTS);
/* Intersection at north pole */
line2pts("LINESTRING(-180.0 80.0, 0.0 80.0)", &A1, &A2);
line2pts("LINESTRING(90.0 80.0, -90.0 80.0)", &B1, &B2);
rv = edge_intersects(&A1, &A2, &B1, &B2);
- CU_ASSERT_EQUAL(rv, PIR_INTERSECTS);
+ CU_ASSERT(rv == PIR_INTERSECTS);
/* Equal edges return true */
line2pts("LINESTRING(45.0 10.0, 50.0 20.0)", &A1, &A2);
line2pts("LINESTRING(40.0 0.0, 70.0 0.0)", &A1, &A2);
line2pts("LINESTRING(60.0 0.0, 50.0 0.0)", &B1, &B2);
rv = edge_intersects(&A1, &A2, &B1, &B2);
- CU_ASSERT_EQUAL(rv, PIR_INTERSECTS|PIR_COLINEAR);
+ CU_ASSERT(rv == (PIR_INTERSECTS|PIR_COLINEAR) );
/* End touches arc at north pole */
line2pts("LINESTRING(-180.0 80.0, 0.0 80.0)", &A1, &A2);
line2pts("LINESTRING(90.0 80.0, -90.0 90.0)", &B1, &B2);
rv = edge_intersects(&A1, &A2, &B1, &B2);
- printf("End touches arc at north pole: %d\n", rv);
- CU_ASSERT_EQUAL(rv, PIR_INTERSECTS|PIR_B_TOUCH_LEFT);
+ CU_ASSERT(rv == (PIR_INTERSECTS|PIR_B_TOUCH_LEFT) );
/* End touches end at north pole */
line2pts("LINESTRING(-180.0 80.0, 0.0 90.0)", &A1, &A2);
line2pts("LINESTRING(90.0 80.0, -90.0 90.0)", &B1, &B2);
rv = edge_intersects(&A1, &A2, &B1, &B2);
- printf("End touches end at north pole: %d\n", rv);
- CU_ASSERT_EQUAL(rv, PIR_INTERSECTS|PIR_B_TOUCH_LEFT|PIR_A_TOUCH_RIGHT);
+ CU_ASSERT(rv == (PIR_INTERSECTS|PIR_B_TOUCH_LEFT|PIR_A_TOUCH_RIGHT) );
}
if ( a1_side == 0 )
{
/* Touches at A1, A2 is on what side? */
- rv |= (a2_side < 0 ? PIR_A_TOUCH_LEFT : PIR_A_TOUCH_RIGHT);
+ rv |= (a2_side < 0 ? PIR_A_TOUCH_RIGHT : PIR_A_TOUCH_LEFT);
}
else if ( a2_side == 0 )
{
/* Touches at A2, A1 is on what side? */
- rv |= (a1_side < 0 ? PIR_A_TOUCH_LEFT : PIR_A_TOUCH_RIGHT);
+ rv |= (a1_side < 0 ? PIR_A_TOUCH_RIGHT : PIR_A_TOUCH_LEFT);
}
/* B touches A */
if ( b1_side == 0 )
{
/* Touches at B1, B2 is on what side? */
- rv |= (b2_side < 0 ? PIR_B_TOUCH_LEFT : PIR_B_TOUCH_RIGHT);
+ rv |= (b2_side < 0 ? PIR_B_TOUCH_RIGHT : PIR_B_TOUCH_LEFT);
}
else if ( b2_side == 0 )
{
/* Touches at B2, B1 is on what side? */
- rv |= (b1_side < 0 ? PIR_B_TOUCH_LEFT : PIR_B_TOUCH_RIGHT);
+ rv |= (b1_side < 0 ? PIR_B_TOUCH_RIGHT : PIR_B_TOUCH_LEFT);
}
return rv;
{
/* If the stabline is touching the edge, that implies the test point */
/* is on the edge, so we're done, the point is in (on) the ring. */
- if ( (inter & PIR_A_TOUCH_LEFT) || (inter & PIR_A_TOUCH_RIGHT) )
+ if ( (inter & PIR_A_TOUCH_RIGHT) || (inter & PIR_A_TOUCH_LEFT) )
{
return LW_TRUE;
}
/* It's a touching interaction, disregard all the left-side ones. */
/* It's a co-linear intersection, ignore those. */
- if ( inter & PIR_B_TOUCH_LEFT || inter & PIR_COLINEAR )
+ if ( inter & PIR_B_TOUCH_RIGHT || inter & PIR_COLINEAR )
{
/* Do nothing, to avoid double counts. */
LWDEBUGF(4," edge (%d) crossed, disregarding to avoid double count", i, count);
/* To avoid double counting crossings-at-a-vertex, */
/* always ignore crossings at "lower" ends of edges*/
- if ( inter & PIR_B_TOUCH_LEFT || inter & PIR_COLINEAR )
+ if ( inter & PIR_B_TOUCH_RIGHT || inter & PIR_COLINEAR )
{
LWDEBUG(3," rejecting stab line grazing by left-side edge");
return 0;
else
{
GEOGRAPHIC_EDGE e1, e2;
- GEOGRAPHIC_POINT g1;
+ GEOGRAPHIC_POINT g;
+ POINT3D A1, A2, B1, B2;
geographic_point_init(n1->p1->x, n1->p1->y, &(e1.start));
geographic_point_init(n1->p2->x, n1->p2->y, &(e1.end));
geographic_point_init(n2->p1->x, n2->p1->y, &(e2.start));
geographic_point_init(n2->p2->x, n2->p2->y, &(e2.end));
- if ( edge_intersection(&e1, &e2, &g1) )
+ geog2cart(&(e1.start), &A1);
+ geog2cart(&(e1.end), &A2);
+ geog2cart(&(e2.start), &B1);
+ geog2cart(&(e2.end), &B2);
+ if ( edge_intersects(&A1, &A2, &B1, &B2) )
{
d = 0.0;
- close1 = close2 = g1;
+ edge_intersection(&e1, &e2, &g);
+ close1 = close2 = g;
}
else
{