PostGIS  3.7.0dev-r@@SVN_REVISION@@

◆ lw_segment_intersects()

int lw_segment_intersects ( const POINT2D p1,
const POINT2D p2,
const POINT2D q1,
const POINT2D q2 
)

returns the kind of CG_SEGMENT_INTERSECTION_TYPE behavior of lineseg 1 (constructed from p1 and p2) and lineseg 2 (constructed from q1 and q2)

Parameters
p1start point of first straight linesegment
p2end point of first straight linesegment
q1start point of second line segment
q2end point of second line segment
Returns
a CG_SEGMENT_INTERSECTION_TYPE Returns one of SEG_ERROR = -1, SEG_NO_INTERSECTION = 0, SEG_COLINEAR = 1, SEG_CROSS_LEFT = 2, SEG_CROSS_RIGHT = 3,

Definition at line 378 of file lwalgorithm.c.

379 {
380 
381  int pq1, pq2, qp1, qp2;
382 
383  /* No envelope interaction => we are done. */
384  if (!lw_seg_interact(p1, p2, q1, p2))
385  {
386  return SEG_NO_INTERSECTION;
387  }
388 
389  /* Are the start and end points of q on the same side of p? */
390  pq1=lw_segment_side(p1,p2,q1);
391  pq2=lw_segment_side(p1,p2,q2);
392  if ((pq1>0 && pq2>0) || (pq1<0 && pq2<0))
393  {
394  return SEG_NO_INTERSECTION;
395  }
396 
397  /* Are the start and end points of p on the same side of q? */
398  qp1=lw_segment_side(q1,q2,p1);
399  qp2=lw_segment_side(q1,q2,p2);
400  if ( (qp1 > 0.0 && qp2 > 0.0) || (qp1 < 0.0 && qp2 < 0.0) )
401  {
402  return SEG_NO_INTERSECTION;
403  }
404 
405  /* Nobody is on one side or another? Must be colinear. */
406  if ( pq1 == 0.0 && pq2 == 0.0 && qp1 == 0.0 && qp2 == 0.0 )
407  {
408  return SEG_COLINEAR;
409  }
410 
411  /*
412  ** When one end-point touches, the sidedness is determined by the
413  ** location of the other end-point. Only touches by the first point
414  ** will be considered "real" to avoid double counting.
415  */
416  LWDEBUGF(4, "pq1=%d pq2=%d", pq1, pq2);
417  LWDEBUGF(4, "qp1=%d qp2=%d", qp1, qp2);
418 
419  /* Second point of p or q touches, it's not a crossing. */
420  if ( pq2 == 0 || qp2 == 0 )
421  {
422  return SEG_NO_INTERSECTION;
423  }
424 
425  /* First point of p touches, it's a "crossing". */
426  if ( pq1 == 0 )
427  {
428  if ( pq2 > 0 )
429  return SEG_CROSS_RIGHT;
430  else
431  return SEG_CROSS_LEFT;
432  }
433 
434  /* First point of q touches, it's a crossing. */
435  if ( qp1 == 0 )
436  {
437  if ( pq1 < pq2 )
438  return SEG_CROSS_RIGHT;
439  else
440  return SEG_CROSS_LEFT;
441  }
442 
443  /* The segments cross, what direction is the crossing? */
444  if ( pq1 < pq2 )
445  return SEG_CROSS_RIGHT;
446  else
447  return SEG_CROSS_LEFT;
448 
449  /* This should never happen! */
450  return SEG_ERROR;
451 }
@ SEG_NO_INTERSECTION
@ SEG_ERROR
@ SEG_COLINEAR
@ SEG_CROSS_RIGHT
@ SEG_CROSS_LEFT
static int lw_seg_interact(const POINT2D *p1, const POINT2D *p2, const POINT2D *q1, const POINT2D *q2)
Definition: lwalgorithm.c:343
int lw_segment_side(const POINT2D *p1, const POINT2D *p2, const POINT2D *q)
lw_segment_side()
Definition: lwalgorithm.c:70
#define LWDEBUGF(level, msg,...)
Definition: lwgeom_log.h:106

References lw_seg_interact(), lw_segment_side(), LWDEBUGF, SEG_COLINEAR, SEG_CROSS_LEFT, SEG_CROSS_RIGHT, SEG_ERROR, and SEG_NO_INTERSECTION.

Referenced by lwline_crossing_direction(), rect_leaf_node_intersects(), and test_lw_segment_intersects().

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