PostGIS  2.4.9dev-r@@SVN_REVISION@@

◆ 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 831 of file lwgeodetic.c.

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.

832 {
833  GEOGRAPHIC_EDGE g;
835  double slon = fabs((e->start).lon) + fabs((e->end).lon);
836  double dlon = fabs(fabs((e->start).lon) - fabs((e->end).lon));
837  double slat = (e->start).lat + (e->end).lat;
838 
839  LWDEBUGF(4, "e.start == GPOINT(%.6g %.6g) ", (e->start).lat, (e->start).lon);
840  LWDEBUGF(4, "e.end == GPOINT(%.6g %.6g) ", (e->end).lat, (e->end).lon);
841  LWDEBUGF(4, "p == GPOINT(%.6g %.6g) ", p->lat, p->lon);
842 
843  /* Copy values into working registers */
844  g = *e;
845  q = *p;
846 
847  /* Vertical plane, we need to do this calculation in latitude */
848  if ( FP_EQUALS( g.start.lon, g.end.lon ) )
849  {
850  LWDEBUG(4, "vertical plane, we need to do this calculation in latitude");
851  /* Supposed to be co-planar... */
852  if ( ! FP_EQUALS( q.lon, g.start.lon ) )
853  return LW_FALSE;
854 
855  if ( ( g.start.lat <= q.lat && q.lat <= g.end.lat ) ||
856  ( g.end.lat <= q.lat && q.lat <= g.start.lat ) )
857  {
858  return LW_TRUE;
859  }
860  else
861  {
862  return LW_FALSE;
863  }
864  }
865 
866  /* Over the pole, we need normalize latitude and do this calculation in latitude */
867  if ( FP_EQUALS( slon, M_PI ) && ( SIGNUM(g.start.lon) != SIGNUM(g.end.lon) || FP_EQUALS(dlon, M_PI) ) )
868  {
869  LWDEBUG(4, "over the pole...");
870  /* Antipodal, everything (or nothing?) is inside */
871  if ( FP_EQUALS( slat, 0.0 ) )
872  return LW_TRUE;
873 
874  /* Point *is* the north pole */
875  if ( slat > 0.0 && FP_EQUALS(q.lat, M_PI_2 ) )
876  return LW_TRUE;
877 
878  /* Point *is* the south pole */
879  if ( slat < 0.0 && FP_EQUALS(q.lat, -1.0 * M_PI_2) )
880  return LW_TRUE;
881 
882  LWDEBUG(4, "coplanar?...");
883 
884  /* Supposed to be co-planar... */
885  if ( ! FP_EQUALS( q.lon, g.start.lon ) )
886  return LW_FALSE;
887 
888  LWDEBUG(4, "north or south?...");
889 
890  /* Over north pole, test based on south pole */
891  if ( slat > 0.0 )
892  {
893  LWDEBUG(4, "over the north pole...");
894  if ( q.lat > FP_MIN(g.start.lat, g.end.lat) )
895  return LW_TRUE;
896  else
897  return LW_FALSE;
898  }
899  else
900  /* Over south pole, test based on north pole */
901  {
902  LWDEBUG(4, "over the south pole...");
903  if ( q.lat < FP_MAX(g.start.lat, g.end.lat) )
904  return LW_TRUE;
905  else
906  return LW_FALSE;
907  }
908  }
909 
910  /* Dateline crossing, flip everything to the opposite hemisphere */
911  else if ( slon > M_PI && ( SIGNUM(g.start.lon) != SIGNUM(g.end.lon) ) )
912  {
913  LWDEBUG(4, "crosses dateline, flip longitudes...");
914  if ( g.start.lon > 0.0 )
915  g.start.lon -= M_PI;
916  else
917  g.start.lon += M_PI;
918  if ( g.end.lon > 0.0 )
919  g.end.lon -= M_PI;
920  else
921  g.end.lon += M_PI;
922 
923  if ( q.lon > 0.0 )
924  q.lon -= M_PI;
925  else
926  q.lon += M_PI;
927  }
928 
929  if ( ( g.start.lon <= q.lon && q.lon <= g.end.lon ) ||
930  ( g.end.lon <= q.lon && q.lon <= g.start.lon ) )
931  {
932  LWDEBUG(4, "true, this edge contains point");
933  return LW_TRUE;
934  }
935 
936  LWDEBUG(4, "false, this edge does not contain point");
937  return LW_FALSE;
938 }
Two-point great circle segment from a to b.
Definition: lwgeodetic.h:61
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
#define FP_MIN(A, B)
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:52
#define LW_FALSE
Definition: liblwgeom.h:77
GEOGRAPHIC_POINT start
Definition: lwgeodetic.h:63
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
GEOGRAPHIC_POINT end
Definition: lwgeodetic.h:64
#define FP_EQUALS(A, B)
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:88
#define SIGNUM(n)
Macro that returns: -1 if n < 0, 1 if n > 0, 0 if n == 0.
#define FP_MAX(A, B)