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

◆ lwpoly_intersects_line()

int lwpoly_intersects_line ( const LWPOLY lwpoly,
const POINTARRAY line 
)

Checks if any edges of lwpoly intersect with the line formed by the pointarray return LW_TRUE if any intersection between the given polygon and the line.

Definition at line 2581 of file lwgeodetic.c.

2582{
2583 uint32_t i, j, k;
2584 POINT3D pa1, pa2, pb1, pb2;
2585 for (i = 0; i < lwpoly->nrings; i++)
2586 {
2587 for (j = 0; j < lwpoly->rings[i]->npoints - 1; j++)
2588 {
2589 const POINT2D* a1 = getPoint2d_cp(lwpoly->rings[i], j);
2590 const POINT2D* a2 = getPoint2d_cp(lwpoly->rings[i], j+1);
2591
2592 /* Set up our stab line */
2593 ll2cart(a1, &pa1);
2594 ll2cart(a2, &pa2);
2595
2596 for (k = 0; k < line->npoints - 1; k++)
2597 {
2598 const POINT2D* b1 = getPoint2d_cp(line, k);
2599 const POINT2D* b2 = getPoint2d_cp(line, k+1);
2600
2601 /* Set up our stab line */
2602 ll2cart(b1, &pb1);
2603 ll2cart(b2, &pb2);
2604
2605 int inter = edge_intersects(&pa1, &pa2, &pb1, &pb2);
2606
2607 /* ignore same edges */
2608 if (inter & PIR_INTERSECTS
2609 && !(inter & PIR_B_TOUCH_RIGHT || inter & PIR_COLINEAR) )
2610 {
2611 return LW_TRUE;
2612 }
2613 }
2614 }
2615 }
2616
2617 return LW_FALSE;
2618}
#define LW_FALSE
Definition liblwgeom.h:94
#define LW_TRUE
Return types for functions with status returns.
Definition liblwgeom.h:93
void ll2cart(const POINT2D *g, POINT3D *p)
Convert lon/lat coordinates to cartesian coordinates on unit sphere.
Definition lwgeodetic.c:423
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.
#define PIR_COLINEAR
Definition lwgeodetic.h:89
#define PIR_INTERSECTS
Definition lwgeodetic.h:88
#define PIR_B_TOUCH_RIGHT
Definition lwgeodetic.h:92
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.
Definition lwinline.h:97
POINTARRAY ** rings
Definition liblwgeom.h:519
uint32_t nrings
Definition liblwgeom.h:524
uint32_t npoints
Definition liblwgeom.h:427

References edge_intersects(), getPoint2d_cp(), ll2cart(), LW_FALSE, LW_TRUE, POINTARRAY::npoints, LWPOLY::nrings, PIR_B_TOUCH_RIGHT, PIR_COLINEAR, PIR_INTERSECTS, and LWPOLY::rings.

Referenced by lwpoly_covers_lwline(), and lwpoly_covers_lwpoly().

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