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

Definition at line 563 of file cu_geodetic.c.

References edge_intersects(), geog2cart(), GEOGRAPHIC_POINT::lat, line2pts(), GEOGRAPHIC_POINT::lon, PIR_A_TOUCH_RIGHT, PIR_B_TOUCH_LEFT, PIR_B_TOUCH_RIGHT, PIR_COLINEAR, and PIR_INTERSECTS.

Referenced by geodetic_suite_setup().

564 {
565  POINT3D A1, A2, B1, B2;
567  int rv;
568 
569  /* Covers case, end-to-end intersection */
570  line2pts("LINESTRING(50 -10.999999999999998224, -10.0 50.0)", &A1, &A2);
571  line2pts("LINESTRING(-10.0 50.0, -10.272779983831613393 -16.937003313332997578)", &B1, &B2);
572  rv = edge_intersects(&A1, &A2, &B1, &B2);
573  CU_ASSERT(rv & PIR_INTERSECTS);
574 
575  /* Medford case, very short segment vs very long one */
576  g.lat = 0.74123572595649878103;
577  g.lon = -2.1496353191142714145;
578  geog2cart(&g, &A1);
579  g.lat = 0.74123631950116664058;
580  g.lon = -2.1496353248304860273;
581  geog2cart(&g, &A2);
582  g.lat = 0.73856343764436815924;
583  g.lon = -2.1461493501950630325;
584  geog2cart(&g, &B1);
585  g.lat = 0.70971354024834598651;
586  g.lon = 2.1082194552519770703;
587  geog2cart(&g, &B2);
588  rv = edge_intersects(&A1, &A2, &B1, &B2);
589  CU_ASSERT(rv == 0);
590 
591  /* Second Medford case, very short segment vs very long one */
592  g.lat = 0.73826546728290887156;
593  g.lon = -2.14426380171833042;
594  geog2cart(&g, &A1);
595  g.lat = 0.73826545883786642843;
596  g.lon = -2.1442638997530165668;
597  geog2cart(&g, &A2);
598  g.lat = 0.73775469118192538165;
599  g.lon = -2.1436035534281718817;
600  geog2cart(&g, &B1);
601  g.lat = 0.71021099548296817705;
602  g.lon = 2.1065275171200439353;
603  geog2cart(&g, &B2);
604  rv = edge_intersects(&A1, &A2, &B1, &B2);
605  CU_ASSERT(rv == PIR_INTERSECTS);
606 
607  /* Again, this time with a less exact input edge. */
608  line2pts("LINESTRING(-123.165031277506 42.4696787216231, -123.165031605021 42.4697127292275)", &A1, &A2);
609  rv = edge_intersects(&A1, &A2, &B1, &B2);
610  CU_ASSERT(rv == 0);
611 
612  /* Intersection at (0 0) */
613  line2pts("LINESTRING(-1.0 0.0, 1.0 0.0)", &A1, &A2);
614  line2pts("LINESTRING(0.0 -1.0, 0.0 1.0)", &B1, &B2);
615  rv = edge_intersects(&A1, &A2, &B1, &B2);
616  CU_ASSERT(rv == PIR_INTERSECTS);
617 
618  /* No intersection at (0 0) */
619  line2pts("LINESTRING(-1.0 0.0, 1.0 0.0)", &A1, &A2);
620  line2pts("LINESTRING(0.0 -1.0, 0.0 -2.0)", &B1, &B2);
621  rv = edge_intersects(&A1, &A2, &B1, &B2);
622  CU_ASSERT(rv == 0);
623 
624  /* End touches middle of segment at (0 0) */
625  line2pts("LINESTRING(-1.0 0.0, 1.0 0.0)", &A1, &A2);
626  line2pts("LINESTRING(0.0 -1.0, 0.0 0.0)", &B1, &B2);
627  rv = edge_intersects(&A1, &A2, &B1, &B2);
628  CU_ASSERT(rv == (PIR_INTERSECTS|PIR_B_TOUCH_RIGHT) );
629 
630  /* End touches end of segment at (0 0) */
631  line2pts("LINESTRING(0.0 0.0, 1.0 0.0)", &A1, &A2);
632  line2pts("LINESTRING(0.0 -1.0, 0.0 0.0)", &B1, &B2);
633  rv = edge_intersects(&A1, &A2, &B1, &B2);
635 
636  /* Intersection at (180 0) */
637  line2pts("LINESTRING(-179.0 -1.0, 179.0 1.0)", &A1, &A2);
638  line2pts("LINESTRING(-179.0 1.0, 179.0 -1.0)", &B1, &B2);
639  rv = edge_intersects(&A1, &A2, &B1, &B2);
640  CU_ASSERT(rv == PIR_INTERSECTS);
641 
642  /* Intersection at (180 0) */
643  line2pts("LINESTRING(-170.0 0.0, 170.0 0.0)", &A1, &A2);
644  line2pts("LINESTRING(180.0 -10.0, 180.0 10.0)", &B1, &B2);
645  rv = edge_intersects(&A1, &A2, &B1, &B2);
646  CU_ASSERT(rv == PIR_INTERSECTS);
647 
648  /* Intersection at north pole */
649  line2pts("LINESTRING(-180.0 80.0, 0.0 80.0)", &A1, &A2);
650  line2pts("LINESTRING(90.0 80.0, -90.0 80.0)", &B1, &B2);
651  rv = edge_intersects(&A1, &A2, &B1, &B2);
652  CU_ASSERT(rv == PIR_INTERSECTS);
653 
654  /* Equal edges return true */
655  line2pts("LINESTRING(45.0 10.0, 50.0 20.0)", &A1, &A2);
656  line2pts("LINESTRING(45.0 10.0, 50.0 20.0)", &B1, &B2);
657  rv = edge_intersects(&A1, &A2, &B1, &B2);
658  CU_ASSERT(rv & PIR_INTERSECTS);
659 
660  /* Parallel edges (same great circle, different end points) return true */
661  line2pts("LINESTRING(40.0 0.0, 70.0 0.0)", &A1, &A2);
662  line2pts("LINESTRING(60.0 0.0, 50.0 0.0)", &B1, &B2);
663  rv = edge_intersects(&A1, &A2, &B1, &B2);
664  CU_ASSERT(rv == (PIR_INTERSECTS|PIR_COLINEAR) );
665 
666  /* End touches arc at north pole */
667  line2pts("LINESTRING(-180.0 80.0, 0.0 80.0)", &A1, &A2);
668  line2pts("LINESTRING(90.0 80.0, -90.0 90.0)", &B1, &B2);
669  rv = edge_intersects(&A1, &A2, &B1, &B2);
670  CU_ASSERT(rv == (PIR_INTERSECTS|PIR_B_TOUCH_LEFT) );
671 
672  /* End touches end at north pole */
673  line2pts("LINESTRING(-180.0 80.0, 0.0 90.0)", &A1, &A2);
674  line2pts("LINESTRING(90.0 80.0, -90.0 90.0)", &B1, &B2);
675  rv = edge_intersects(&A1, &A2, &B1, &B2);
677 
678  /* Antipodal straddles. Great circles cross but at opposite */
679  /* sides of the globe */
680  /* #2534 */
681  /* http://www.gcmap.com/mapui?P=60N+90E-20S+90E%0D%0A0N+0E-90.04868865037885W+57.44011727050777S%0D%0A&MS=wls&DU=mi */
682  line2pts("LINESTRING(90.0 60.0, 90.0 -20.0)", &A1, &A2);
683  line2pts("LINESTRING(0.0 0.0, -90.04868865037885 -57.44011727050777)", &B1, &B2);
684  rv = edge_intersects(&A1, &A2, &B1, &B2);
685  CU_ASSERT(rv == 0);
686 
687  line2pts("LINESTRING(-5 0, 5 0)", &A1, &A2);
688  line2pts("LINESTRING(179 -5, 179 5)", &B1, &B2);
689  rv = edge_intersects(&A1, &A2, &B1, &B2);
690  CU_ASSERT(rv == 0);
691 
692  line2pts("LINESTRING(175 -85, 175 85)", &A1, &A2);
693  line2pts("LINESTRING(65 0, -105 0)", &B1, &B2);
694  rv = edge_intersects(&A1, &A2, &B1, &B2);
695  CU_ASSERT(rv == 0);
696 
697  line2pts("LINESTRING(175 -85, 175 85)", &A1, &A2);
698  line2pts("LINESTRING(45 0, -125 0)", &B1, &B2);
699  rv = edge_intersects(&A1, &A2, &B1, &B2);
700  CU_ASSERT(rv == 0);
701 
702 }
#define PIR_B_TOUCH_RIGHT
Definition: lwgeodetic.h:77
#define PIR_A_TOUCH_RIGHT
Definition: lwgeodetic.h:75
static void line2pts(const char *wkt, POINT3D *A1, POINT3D *A2)
Definition: cu_geodetic.c:541
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:33
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesion coordinates on unit sphere.
Definition: lwgeodetic.c:355
int edge_intersects(const POINT3D *A1, const POINT3D *A2, const POINT3D *B1, const POINT3D *B2)
Returns non-zero if edges A and B interact.
Definition: lwgeodetic.c:3096
#define PIR_B_TOUCH_LEFT
Definition: lwgeodetic.h:78
#define PIR_COLINEAR
Definition: lwgeodetic.h:74
#define PIR_INTERSECTS
Definition: lwgeodetic.h:73

Here is the call graph for this function:

Here is the caller graph for this function: