PostGIS  3.2.2dev-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 381 of file lwalgorithm.c.

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

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: