PostGIS  3.0.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 372 of file lwalgorithm.c.

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().

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