PostGIS  2.1.10dev-r@@SVN_REVISION@@
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 784 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.

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