PostGIS  2.2.7dev-r@@SVN_REVISION@@
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 357 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_tree_intersects_tree(), and test_lw_segment_intersects().

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

Here is the call graph for this function:

Here is the caller graph for this function: