PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ test_edge_intersects()

static void test_edge_intersects ( void  )
static

Definition at line 583 of file cu_geodetic.c.

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

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().

Here is the call graph for this function:
Here is the caller graph for this function: