PostGIS  2.1.10dev-r@@SVN_REVISION@@
static void test_edge_intersection ( void  )
static

Definition at line 381 of file cu_geodetic.c.

References edge_intersection(), edge_set(), GEOGRAPHIC_EDGE::end, GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, LW_FALSE, LW_TRUE, point_rad2deg(), and GEOGRAPHIC_EDGE::start.

Referenced by geodetic_suite_setup().

382 {
383  GEOGRAPHIC_EDGE e1, e2;
385  int rv;
386 
387  /* Covers case, end-to-end intersection */
388  edge_set(50, -10.999999999999998224, -10.0, 50.0, &e1);
389  edge_set(-10.0, 50.0, -10.272779983831613393, -16.937003313332997578, &e2);
390  rv = edge_intersection(&e1, &e2, &g);
391  CU_ASSERT_EQUAL(rv, LW_TRUE);
392 
393  /* Medford case, very short segment vs very long one */
394  e1.start.lat = 0.74123572595649878103;
395  e1.start.lon = -2.1496353191142714145;
396  e1.end.lat = 0.74123631950116664058;
397  e1.end.lon = -2.1496353248304860273;
398  e2.start.lat = 0.73856343764436815924;
399  e2.start.lon = -2.1461493501950630325;
400  e2.end.lat = 0.70971354024834598651;
401  e2.end.lon = 2.1082194552519770703;
402  rv = edge_intersection(&e1, &e2, &g);
403  CU_ASSERT_EQUAL(rv, LW_FALSE);
404 
405  /* Again, this time with a less exact input edge. */
406  edge_set(-123.165031277506, 42.4696787216231, -123.165031605021, 42.4697127292275, &e1);
407  rv = edge_intersection(&e1, &e2, &g);
408  CU_ASSERT_EQUAL(rv, LW_FALSE);
409 
410  /* Second Medford case, very short segment vs very long one
411  e1.start.lat = 0.73826546728290887156;
412  e1.start.lon = -2.14426380171833042;
413  e1.end.lat = 0.73826545883786642843;
414  e1.end.lon = -2.1442638997530165668;
415  e2.start.lat = 0.73775469118192538165;
416  e2.start.lon = -2.1436035534281718817;
417  e2.end.lat = 0.71021099548296817705;
418  e2.end.lon = 2.1065275171200439353;
419  rv = edge_intersection(e1, e2, &g);
420  CU_ASSERT_EQUAL(rv, LW_FALSE);
421  */
422 
423  /* Intersection at (0 0) */
424  edge_set(-1.0, 0.0, 1.0, 0.0, &e1);
425  edge_set(0.0, -1.0, 0.0, 1.0, &e2);
426  rv = edge_intersection(&e1, &e2, &g);
427  point_rad2deg(&g);
428  CU_ASSERT_DOUBLE_EQUAL(g.lat, 0.0, 0.00001);
429  CU_ASSERT_DOUBLE_EQUAL(g.lon, 0.0, 0.00001);
430  CU_ASSERT_EQUAL(rv, LW_TRUE);
431 
432  /* No intersection at (0 0) */
433  edge_set(-1.0, 0.0, 1.0, 0.0, &e1);
434  edge_set(0.0, -1.0, 0.0, -2.0, &e2);
435  rv = edge_intersection(&e1, &e2, &g);
436  CU_ASSERT_EQUAL(rv, LW_FALSE);
437 
438  /* End touches middle of segment at (0 0) */
439  edge_set(-1.0, 0.0, 1.0, 0.0, &e1);
440  edge_set(0.0, -1.0, 0.0, 0.0, &e2);
441  rv = edge_intersection(&e1, &e2, &g);
442  point_rad2deg(&g);
443 #if 0
444  printf("\n");
445  printf("LINESTRING(%.15g %.15g, %.15g %.15g)\n", e1.start.lon, e1.start.lat, e1.end.lon, e1.end.lat);
446  printf("LINESTRING(%.15g %.15g, %.15g %.15g)\n", e2.start.lon, e2.start.lat, e2.end.lon, e2.end.lat);
447  printf("g = (%.15g %.15g)\n", g.lon, g.lat);
448  printf("rv = %d\n", rv);
449 #endif
450  CU_ASSERT_DOUBLE_EQUAL(g.lon, 0.0, 0.00001);
451  CU_ASSERT_EQUAL(rv, LW_TRUE);
452 
453  /* End touches end of segment at (0 0) */
454  edge_set(0.0, 0.0, 1.0, 0.0, &e1);
455  edge_set(0.0, -1.0, 0.0, 0.0, &e2);
456  rv = edge_intersection(&e1, &e2, &g);
457  point_rad2deg(&g);
458 #if 0
459  printf("\n");
460  printf("LINESTRING(%.15g %.15g, %.15g %.15g)\n", e1.start.lon, e1.start.lat, e1.end.lon, e1.end.lat);
461  printf("LINESTRING(%.15g %.15g, %.15g %.15g)\n", e2.start.lon, e2.start.lat, e2.end.lon, e2.end.lat);
462  printf("g = (%.15g %.15g)\n", g.lon, g.lat);
463  printf("rv = %d\n", rv);
464 #endif
465  CU_ASSERT_DOUBLE_EQUAL(g.lat, 0.0, 0.00001);
466  CU_ASSERT_DOUBLE_EQUAL(g.lon, 0.0, 0.00001);
467  CU_ASSERT_EQUAL(rv, LW_TRUE);
468 
469  /* Intersection at (180 0) */
470  edge_set(-179.0, -1.0, 179.0, 1.0, &e1);
471  edge_set(-179.0, 1.0, 179.0, -1.0, &e2);
472  rv = edge_intersection(&e1, &e2, &g);
473  point_rad2deg(&g);
474  CU_ASSERT_DOUBLE_EQUAL(g.lat, 0.0, 0.00001);
475  CU_ASSERT_DOUBLE_EQUAL(fabs(g.lon), 180.0, 0.00001);
476  CU_ASSERT_EQUAL(rv, LW_TRUE);
477 
478  /* Intersection at (180 0) */
479  edge_set(-170.0, 0.0, 170.0, 0.0, &e1);
480  edge_set(180.0, -10.0, 180.0, 10.0, &e2);
481  rv = edge_intersection(&e1, &e2, &g);
482  point_rad2deg(&g);
483  CU_ASSERT_DOUBLE_EQUAL(g.lat, 0.0, 0.00001);
484  CU_ASSERT_DOUBLE_EQUAL(fabs(g.lon), 180.0, 0.00001);
485  CU_ASSERT_EQUAL(rv, LW_TRUE);
486 
487  /* Intersection at north pole */
488  edge_set(-180.0, 80.0, 0.0, 80.0, &e1);
489  edge_set(90.0, 80.0, -90.0, 80.0, &e2);
490  rv = edge_intersection(&e1, &e2, &g);
491  point_rad2deg(&g);
492  CU_ASSERT_DOUBLE_EQUAL(g.lat, 90.0, 0.00001);
493  CU_ASSERT_EQUAL(rv, LW_TRUE);
494 
495  /* Equal edges return true */
496  edge_set(45.0, 10.0, 50.0, 20.0, &e1);
497  edge_set(45.0, 10.0, 50.0, 20.0, &e2);
498  rv = edge_intersection(&e1, &e2, &g);
499  point_rad2deg(&g);
500  CU_ASSERT_EQUAL(rv, LW_TRUE);
501 
502  /* Parallel edges (same great circle, different end points) return true */
503  edge_set(40.0, 0.0, 70.0, 0.0, &e1);
504  edge_set(60.0, 0.0, 50.0, 0.0, &e2);
505  rv = edge_intersection(&e1, &e2, &g);
506  point_rad2deg(&g);
507  CU_ASSERT_EQUAL(rv, 2); /* Hack, returning 2 as the 'co-linear' value */
508 
509  /* End touches arc at north pole */
510  edge_set(-180.0, 80.0, 0.0, 80.0, &e1);
511  edge_set(90.0, 80.0, -90.0, 90.0, &e2);
512  rv = edge_intersection(&e1, &e2, &g);
513  point_rad2deg(&g);
514 #if 0
515  printf("\n");
516  printf("LINESTRING(%.15g %.15g, %.15g %.15g)\n", e1.start.lon, e1.start.lat, e1.end.lon, e1.end.lat);
517  printf("LINESTRING(%.15g %.15g, %.15g %.15g)\n", e2.start.lon, e2.start.lat, e2.end.lon, e2.end.lat);
518  printf("g = (%.15g %.15g)\n", g.lon, g.lat);
519  printf("rv = %d\n", rv);
520 #endif
521  CU_ASSERT_DOUBLE_EQUAL(g.lat, 90.0, 0.00001);
522  CU_ASSERT_EQUAL(rv, LW_TRUE);
523 
524  /* End touches end at north pole */
525  edge_set(-180.0, 80.0, 0.0, 90.0, &e1);
526  edge_set(90.0, 80.0, -90.0, 90.0, &e2);
527  rv = edge_intersection(&e1, &e2, &g);
528  point_rad2deg(&g);
529 #if 0
530  printf("\n");
531  printf("LINESTRING(%.15g %.15g, %.15g %.15g)\n", e1.start.lon, e1.start.lat, e1.end.lon, e1.end.lat);
532  printf("LINESTRING(%.15g %.15g, %.15g %.15g)\n", e2.start.lon, e2.start.lat, e2.end.lon, e2.end.lat);
533  printf("g = (%.15g %.15g)\n", g.lon, g.lat);
534  printf("rv = %d\n", rv);
535 #endif
536  CU_ASSERT_DOUBLE_EQUAL(g.lat, 90.0, 0.00001);
537  CU_ASSERT_EQUAL(rv, LW_TRUE);
538 
539 }
Two-point great circle segment from a to b.
Definition: lwgeodetic.h:42
static void edge_set(double lon1, double lat1, double lon2, double lat2, GEOGRAPHIC_EDGE *e)
Definition: cu_geodetic.c:327
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:33
#define LW_FALSE
Definition: liblwgeom.h:52
GEOGRAPHIC_POINT start
Definition: lwgeodetic.h:44
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:51
static void point_rad2deg(GEOGRAPHIC_POINT *p)
Convert a point from radians to degrees.
Definition: cu_geodetic.c:58
GEOGRAPHIC_POINT end
Definition: lwgeodetic.h:45
int edge_intersection(const GEOGRAPHIC_EDGE *e1, const GEOGRAPHIC_EDGE *e2, GEOGRAPHIC_POINT *g)
Returns true if an intersection can be calculated, and places it in *g.
Definition: lwgeodetic.c:1074

Here is the call graph for this function:

Here is the caller graph for this function: