PostGIS  2.3.8dev-r@@SVN_REVISION@@

◆ test_edge_intersects()

static void test_edge_intersects ( void  )
static

Definition at line 583 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().

584 {
585  POINT3D A1, A2, B1, B2;
587  int rv;
588 
589  /* Covers case, end-to-end intersection */
590  line2pts("LINESTRING(50 -10.999999999999998224, -10.0 50.0)", &A1, &A2);
591  line2pts("LINESTRING(-10.0 50.0, -10.272779983831613393 -16.937003313332997578)", &B1, &B2);
592  rv = edge_intersects(&A1, &A2, &B1, &B2);
593  CU_ASSERT(rv & PIR_INTERSECTS);
594 
595  /* Medford case, very short segment vs very long one */
596  g.lat = 0.74123572595649878103;
597  g.lon = -2.1496353191142714145;
598  geog2cart(&g, &A1);
599  g.lat = 0.74123631950116664058;
600  g.lon = -2.1496353248304860273;
601  geog2cart(&g, &A2);
602  g.lat = 0.73856343764436815924;
603  g.lon = -2.1461493501950630325;
604  geog2cart(&g, &B1);
605  g.lat = 0.70971354024834598651;
606  g.lon = 2.1082194552519770703;
607  geog2cart(&g, &B2);
608  rv = edge_intersects(&A1, &A2, &B1, &B2);
609  CU_ASSERT(rv == 0);
610 
611  /* Second Medford case, very short segment vs very long one */
612  g.lat = 0.73826546728290887156;
613  g.lon = -2.14426380171833042;
614  geog2cart(&g, &A1);
615  g.lat = 0.73826545883786642843;
616  g.lon = -2.1442638997530165668;
617  geog2cart(&g, &A2);
618  g.lat = 0.73775469118192538165;
619  g.lon = -2.1436035534281718817;
620  geog2cart(&g, &B1);
621  g.lat = 0.71021099548296817705;
622  g.lon = 2.1065275171200439353;
623  geog2cart(&g, &B2);
624  rv = edge_intersects(&A1, &A2, &B1, &B2);
625  CU_ASSERT(rv == PIR_INTERSECTS);
626 
627  /* Again, this time with a less exact input edge. */
628  line2pts("LINESTRING(-123.165031277506 42.4696787216231, -123.165031605021 42.4697127292275)", &A1, &A2);
629  rv = edge_intersects(&A1, &A2, &B1, &B2);
630  CU_ASSERT(rv == 0);
631 
632  /* Intersection at (0 0) */
633  line2pts("LINESTRING(-1.0 0.0, 1.0 0.0)", &A1, &A2);
634  line2pts("LINESTRING(0.0 -1.0, 0.0 1.0)", &B1, &B2);
635  rv = edge_intersects(&A1, &A2, &B1, &B2);
636  CU_ASSERT(rv == PIR_INTERSECTS);
637 
638  /* No intersection at (0 0) */
639  line2pts("LINESTRING(-1.0 0.0, 1.0 0.0)", &A1, &A2);
640  line2pts("LINESTRING(0.0 -1.0, 0.0 -2.0)", &B1, &B2);
641  rv = edge_intersects(&A1, &A2, &B1, &B2);
642  CU_ASSERT(rv == 0);
643 
644  /* End touches middle of segment at (0 0) */
645  line2pts("LINESTRING(-1.0 0.0, 1.0 0.0)", &A1, &A2);
646  line2pts("LINESTRING(0.0 -1.0, 0.0 0.0)", &B1, &B2);
647  rv = edge_intersects(&A1, &A2, &B1, &B2);
648  CU_ASSERT(rv == (PIR_INTERSECTS|PIR_B_TOUCH_RIGHT) );
649 
650  /* End touches end of segment at (0 0) */
651  line2pts("LINESTRING(0.0 0.0, 1.0 0.0)", &A1, &A2);
652  line2pts("LINESTRING(0.0 -1.0, 0.0 0.0)", &B1, &B2);
653  rv = edge_intersects(&A1, &A2, &B1, &B2);
655 
656  /* Intersection at (180 0) */
657  line2pts("LINESTRING(-179.0 -1.0, 179.0 1.0)", &A1, &A2);
658  line2pts("LINESTRING(-179.0 1.0, 179.0 -1.0)", &B1, &B2);
659  rv = edge_intersects(&A1, &A2, &B1, &B2);
660  CU_ASSERT(rv == PIR_INTERSECTS);
661 
662  /* Intersection at (180 0) */
663  line2pts("LINESTRING(-170.0 0.0, 170.0 0.0)", &A1, &A2);
664  line2pts("LINESTRING(180.0 -10.0, 180.0 10.0)", &B1, &B2);
665  rv = edge_intersects(&A1, &A2, &B1, &B2);
666  CU_ASSERT(rv == PIR_INTERSECTS);
667 
668  /* Intersection at north pole */
669  line2pts("LINESTRING(-180.0 80.0, 0.0 80.0)", &A1, &A2);
670  line2pts("LINESTRING(90.0 80.0, -90.0 80.0)", &B1, &B2);
671  rv = edge_intersects(&A1, &A2, &B1, &B2);
672  CU_ASSERT(rv == PIR_INTERSECTS);
673 
674  /* Equal edges return true */
675  line2pts("LINESTRING(45.0 10.0, 50.0 20.0)", &A1, &A2);
676  line2pts("LINESTRING(45.0 10.0, 50.0 20.0)", &B1, &B2);
677  rv = edge_intersects(&A1, &A2, &B1, &B2);
678  CU_ASSERT(rv & PIR_INTERSECTS);
679 
680  /* Parallel edges (same great circle, different end points) return true */
681  line2pts("LINESTRING(40.0 0.0, 70.0 0.0)", &A1, &A2);
682  line2pts("LINESTRING(60.0 0.0, 50.0 0.0)", &B1, &B2);
683  rv = edge_intersects(&A1, &A2, &B1, &B2);
684  CU_ASSERT(rv == (PIR_INTERSECTS|PIR_COLINEAR) );
685 
686  /* End touches arc at north pole */
687  line2pts("LINESTRING(-180.0 80.0, 0.0 80.0)", &A1, &A2);
688  line2pts("LINESTRING(90.0 80.0, -90.0 90.0)", &B1, &B2);
689  rv = edge_intersects(&A1, &A2, &B1, &B2);
690  CU_ASSERT(rv == (PIR_INTERSECTS|PIR_B_TOUCH_LEFT) );
691 
692  /* End touches end at north pole */
693  line2pts("LINESTRING(-180.0 80.0, 0.0 90.0)", &A1, &A2);
694  line2pts("LINESTRING(90.0 80.0, -90.0 90.0)", &B1, &B2);
695  rv = edge_intersects(&A1, &A2, &B1, &B2);
697 
698  /* Antipodal straddles. Great circles cross but at opposite */
699  /* sides of the globe */
700  /* #2534 */
701  /* http://www.gcmap.com/mapui?P=60N+90E-20S+90E%0D%0A0N+0E-90.04868865037885W+57.44011727050777S%0D%0A&MS=wls&DU=mi */
702  line2pts("LINESTRING(90.0 60.0, 90.0 -20.0)", &A1, &A2);
703  line2pts("LINESTRING(0.0 0.0, -90.04868865037885 -57.44011727050777)", &B1, &B2);
704  rv = edge_intersects(&A1, &A2, &B1, &B2);
705  CU_ASSERT(rv == 0);
706 
707  line2pts("LINESTRING(-5 0, 5 0)", &A1, &A2);
708  line2pts("LINESTRING(179 -5, 179 5)", &B1, &B2);
709  rv = edge_intersects(&A1, &A2, &B1, &B2);
710  CU_ASSERT(rv == 0);
711 
712  line2pts("LINESTRING(175 -85, 175 85)", &A1, &A2);
713  line2pts("LINESTRING(65 0, -105 0)", &B1, &B2);
714  rv = edge_intersects(&A1, &A2, &B1, &B2);
715  CU_ASSERT(rv == 0);
716 
717  line2pts("LINESTRING(175 -85, 175 85)", &A1, &A2);
718  line2pts("LINESTRING(45 0, -125 0)", &B1, &B2);
719  rv = edge_intersects(&A1, &A2, &B1, &B2);
720  CU_ASSERT(rv == 0);
721 
722 }
#define PIR_B_TOUCH_RIGHT
Definition: lwgeodetic.h:86
#define PIR_A_TOUCH_RIGHT
Definition: lwgeodetic.h:84
static void line2pts(const char *wkt, POINT3D *A1, POINT3D *A2)
Definition: cu_geodetic.c:561
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:47
void geog2cart(const GEOGRAPHIC_POINT *g, POINT3D *p)
Convert spherical coordinates to cartesion coordinates on unit sphere.
Definition: lwgeodetic.c:369
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:3110
#define PIR_B_TOUCH_LEFT
Definition: lwgeodetic.h:87
#define PIR_COLINEAR
Definition: lwgeodetic.h:83
#define PIR_INTERSECTS
Definition: lwgeodetic.h:82
Here is the call graph for this function:
Here is the caller graph for this function: