PostGIS 3.7.0dev-r@@SVN_REVISION@@
Loading...
Searching...
No Matches

◆ edge_contains_coplanar_point()

int edge_contains_coplanar_point ( const GEOGRAPHIC_EDGE e,
const GEOGRAPHIC_POINT p 
)

True if the longitude of p is within the range of the longitude of the ends of e.

Definition at line 783 of file lwgeodetic.c.

784{
787 double slon = fabs((e->start).lon) + fabs((e->end).lon);
788 double dlon = fabs(fabs((e->start).lon) - fabs((e->end).lon));
789 double slat = (e->start).lat + (e->end).lat;
790
791 LWDEBUGF(4, "e.start == GPOINT(%.6g %.6g) ", (e->start).lat, (e->start).lon);
792 LWDEBUGF(4, "e.end == GPOINT(%.6g %.6g) ", (e->end).lat, (e->end).lon);
793 LWDEBUGF(4, "p == GPOINT(%.6g %.6g) ", p->lat, p->lon);
794
795 /* Copy values into working registers */
796 g = *e;
797 q = *p;
798
799 /* Vertical plane, we need to do this calculation in latitude */
800 if ( FP_EQUALS( g.start.lon, g.end.lon ) )
801 {
802 LWDEBUG(4, "vertical plane, we need to do this calculation in latitude");
803 /* Supposed to be co-planar... */
804 if ( ! FP_EQUALS( q.lon, g.start.lon ) )
805 return LW_FALSE;
806
807 if ( ( g.start.lat <= q.lat && q.lat <= g.end.lat ) ||
808 ( g.end.lat <= q.lat && q.lat <= g.start.lat ) )
809 {
810 return LW_TRUE;
811 }
812 else
813 {
814 return LW_FALSE;
815 }
816 }
817
818 /* Over the pole, we need normalize latitude and do this calculation in latitude */
819 if ( FP_EQUALS( slon, M_PI ) && ( SIGNUM(g.start.lon) != SIGNUM(g.end.lon) || FP_EQUALS(dlon, M_PI) ) )
820 {
821 LWDEBUG(4, "over the pole...");
822 /* Antipodal, everything (or nothing?) is inside */
823 if ( FP_EQUALS( slat, 0.0 ) )
824 return LW_TRUE;
825
826 /* Point *is* the north pole */
827 if ( slat > 0.0 && FP_EQUALS(q.lat, M_PI_2 ) )
828 return LW_TRUE;
829
830 /* Point *is* the south pole */
831 if ( slat < 0.0 && FP_EQUALS(q.lat, -1.0 * M_PI_2) )
832 return LW_TRUE;
833
834 LWDEBUG(4, "coplanar?...");
835
836 /* Supposed to be co-planar... */
837 if ( ! FP_EQUALS( q.lon, g.start.lon ) )
838 return LW_FALSE;
839
840 LWDEBUG(4, "north or south?...");
841
842 /* Over north pole, test based on south pole */
843 if ( slat > 0.0 )
844 {
845 LWDEBUG(4, "over the north pole...");
846 if ( q.lat > FP_MIN(g.start.lat, g.end.lat) )
847 return LW_TRUE;
848 else
849 return LW_FALSE;
850 }
851 else
852 /* Over south pole, test based on north pole */
853 {
854 LWDEBUG(4, "over the south pole...");
855 if ( q.lat < FP_MAX(g.start.lat, g.end.lat) )
856 return LW_TRUE;
857 else
858 return LW_FALSE;
859 }
860 }
861
862 /* Dateline crossing, flip everything to the opposite hemisphere */
863 else if ( slon > M_PI && ( SIGNUM(g.start.lon) != SIGNUM(g.end.lon) ) )
864 {
865 LWDEBUG(4, "crosses dateline, flip longitudes...");
866 if ( g.start.lon > 0.0 )
867 g.start.lon -= M_PI;
868 else
869 g.start.lon += M_PI;
870 if ( g.end.lon > 0.0 )
871 g.end.lon -= M_PI;
872 else
873 g.end.lon += M_PI;
874
875 if ( q.lon > 0.0 )
876 q.lon -= M_PI;
877 else
878 q.lon += M_PI;
879 }
880
881 if ( ( g.start.lon <= q.lon && q.lon <= g.end.lon ) ||
882 ( g.end.lon <= q.lon && q.lon <= g.start.lon ) )
883 {
884 LWDEBUG(4, "true, this edge contains point");
885 return LW_TRUE;
886 }
887
888 LWDEBUG(4, "false, this edge does not contain point");
889 return LW_FALSE;
890}
#define LW_FALSE
Definition liblwgeom.h:94
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:93
#define SIGNUM(n)
Macro that returns: -1 if n < 0, 1 if n > 0, 0 if n == 0.
#define FP_MAX(A, B)
#define FP_MIN(A, B)
#define FP_EQUALS(A, B)
#define LWDEBUG(level, msg)
Definition lwgeom_log.h:101
#define LWDEBUGF(level, msg,...)
Definition lwgeom_log.h:106
GEOGRAPHIC_POINT start
Definition lwgeodetic.h:64
GEOGRAPHIC_POINT end
Definition lwgeodetic.h:65
Two-point great circle segment from a to b.
Definition lwgeodetic.h:63
Point in spherical coordinates on the world.
Definition lwgeodetic.h:54

References GEOGRAPHIC_EDGE::end, FP_EQUALS, FP_MAX, FP_MIN, GEOGRAPHIC_POINT::lat, GEOGRAPHIC_POINT::lon, LW_FALSE, LW_TRUE, LWDEBUG, LWDEBUGF, SIGNUM, and GEOGRAPHIC_EDGE::start.