PostGIS  2.5.7dev-r@@SVN_REVISION@@

◆ lwline_covers_lwline()

int lwline_covers_lwline ( const LWLINE lwline1,
const LWLINE lwline2 
)

Check if first and last point of line2 are covered by line1 and then each point in between has to be one line1 in the exact same order return LW_TRUE if all edge points of line2 are on line1.

Definition at line 2786 of file lwgeodetic.c.

2787 {
2788  uint32_t i, j;
2789  GEOGRAPHIC_EDGE e1, e2;
2790  GEOGRAPHIC_POINT p1, p2;
2791  int start = LW_FALSE;
2792  int changed = LW_FALSE;
2793 
2794  /* first point on line */
2795  if ( ! lwline_covers_lwpoint(lwline1, lwline_get_lwpoint(lwline2, 0)))
2796  {
2797  LWDEBUG(4,"returning false, first point of line2 is not covered by line1");
2798  return LW_FALSE;
2799  }
2800 
2801  /* last point on line */
2802  if ( ! lwline_covers_lwpoint(lwline1, lwline_get_lwpoint(lwline2, lwline2->points->npoints - 1)))
2803  {
2804  LWDEBUG(4,"returning false, last point of line2 is not covered by line1");
2805  return LW_FALSE;
2806  }
2807 
2808  j = 0;
2809  i = 0;
2810  while (i < lwline1->points->npoints - 1 && j < lwline2->points->npoints - 1)
2811  {
2812  changed = LW_FALSE;
2813  const POINT2D* a1 = getPoint2d_cp(lwline1->points, i);
2814  const POINT2D* a2 = getPoint2d_cp(lwline1->points, i+1);
2815  const POINT2D* b1 = getPoint2d_cp(lwline2->points, j);
2816  const POINT2D* b2 = getPoint2d_cp(lwline2->points, j+1);
2817 
2818  geographic_point_init(a1->x, a1->y, &(e1.start));
2819  geographic_point_init(a2->x, a2->y, &(e1.end));
2820  geographic_point_init(b1->x, b1->y, &p2);
2821 
2822  /* we already know, that the last point is on line1, so we're done */
2823  if ( j == lwline2->points->npoints - 1)
2824  {
2825  return LW_TRUE;
2826  }
2827  else if (start == LW_TRUE)
2828  {
2829  /* point is on current line1 edge, check next point in line2 */
2830  if ( edge_contains_point(&e1, &p2)) {
2831  j++;
2832  changed = LW_TRUE;
2833  }
2834 
2835  geographic_point_init(a1->x, a1->y, &(e2.start));
2836  geographic_point_init(a2->x, b2->y, &(e2.end));
2837  geographic_point_init(a1->x, a1->y, &p1);
2838 
2839  /* point is on current line2 edge, check next point in line1 */
2840  if ( edge_contains_point(&e2, &p1)) {
2841  i++;
2842  changed = LW_TRUE;
2843  }
2844 
2845  /* no edge progressed -> point left one line */
2846  if ( changed == LW_FALSE )
2847  {
2848  LWDEBUG(4,"returning false, found point not covered by both lines");
2849  return LW_FALSE;
2850  }
2851  else
2852  {
2853  continue;
2854  }
2855  }
2856 
2857  /* find first edge to cover line2 */
2858  if (edge_contains_point(&e1, &p2))
2859  {
2860  start = LW_TRUE;
2861  }
2862 
2863  /* next line1 edge */
2864  i++;
2865  }
2866 
2867  /* no uncovered point found */
2868  return LW_TRUE;
2869 }
#define LW_FALSE
Definition: liblwgeom.h:77
#define LW_TRUE
Return types for functions with status returns.
Definition: liblwgeom.h:76
const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition: lwgeom_api.c:374
LWPOINT * lwline_get_lwpoint(const LWLINE *line, uint32_t where)
Returns freshly allocated LWPOINT that corresponds to the index where.
Definition: lwline.c:318
int lwline_covers_lwpoint(const LWLINE *lwline, const LWPOINT *lwpoint)
return LW_TRUE if any of the line segments covers the point
Definition: lwgeodetic.c:2757
void geographic_point_init(double lon, double lat, GEOGRAPHIC_POINT *g)
Initialize a geographic point.
Definition: lwgeodetic.c:180
int edge_contains_point(const GEOGRAPHIC_EDGE *e, const GEOGRAPHIC_POINT *p)
Returns true if the point p is on the minor edge defined by the end points of e.
Definition: lwgeodetic.c:1034
#define LWDEBUG(level, msg)
Definition: lwgeom_log.h:83
GEOGRAPHIC_POINT start
Definition: lwgeodetic.h:63
GEOGRAPHIC_POINT end
Definition: lwgeodetic.h:64
Two-point great circle segment from a to b.
Definition: lwgeodetic.h:62
Point in spherical coordinates on the world.
Definition: lwgeodetic.h:53
POINTARRAY * points
Definition: liblwgeom.h:425
double y
Definition: liblwgeom.h:331
double x
Definition: liblwgeom.h:331
uint32_t npoints
Definition: liblwgeom.h:374
unsigned int uint32_t
Definition: uthash.h:78

References edge_contains_point(), GEOGRAPHIC_EDGE::end, geographic_point_init(), getPoint2d_cp(), LW_FALSE, LW_TRUE, LWDEBUG, lwline_covers_lwpoint(), lwline_get_lwpoint(), POINTARRAY::npoints, LWLINE::points, GEOGRAPHIC_EDGE::start, POINT2D::x, and POINT2D::y.

Referenced by lwgeom_covers_lwgeom_sphere().

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