Given two lines, characterize how (and if) they cross each other.
478{
479 uint32_t i = 0, j = 0;
480 const POINT2D *p1, *p2, *q1, *q2;
482 int cross_left = 0;
483 int cross_right = 0;
484 int first_cross = 0;
485 int this_cross = 0;
486#if POSTGIS_DEBUG_LEVEL >= 4
487 char *geom_ewkt;
488#endif
489
492
493
494 if ( pa1->npoints < 2 || pa2->npoints < 2 )
496
497
500
501
502#if POSTGIS_DEBUG_LEVEL >= 4
509#endif
510
511
513
514 for ( i = 1; i < pa2->npoints; i++ )
515 {
516
517
519
520
522
523 for ( j = 1; j < pa1->npoints; j++ )
524 {
525
526
528
530
531 LWDEBUGF(4,
"i=%d, j=%d (%.8g %.8g, %.8g %.8g)", i, j, p1->x, p1->y, p2->x, p2->y);
532
534 {
535 LWDEBUG(4,
"this_cross == SEG_CROSS_LEFT");
536 cross_left++;
537 if ( ! first_cross )
539 }
540
542 {
543 LWDEBUG(4,
"this_cross == SEG_CROSS_RIGHT");
544 cross_right++;
545 if ( ! first_cross )
547 }
548
549
550
551
552
553
555 {
556 LWDEBUG(4,
"this_cross == SEG_COLINEAR");
557
558
559
560 }
561
562 LWDEBUG(4,
"this_cross == SEG_NO_INTERSECTION");
563
564
565 p1 = p2;
566
567 }
568
569
570 q1 = q2;
571
572 }
573
574 LWDEBUGF(4,
"first_cross=%d, cross_left=%d, cross_right=%d", first_cross, cross_left, cross_right);
575
576 if ( !cross_left && !cross_right )
578
579 if ( !cross_left && cross_right == 1 )
581
582 if ( !cross_right && cross_left == 1 )
584
585 if ( cross_left - cross_right == 1 )
587
588 if ( cross_left - cross_right == -1 )
590
591 if ( cross_left - cross_right == 0 && first_cross ==
SEG_CROSS_LEFT )
593
596
598
599}
double ptarray_length_2d(const POINTARRAY *pts)
Find the 2d length of the given POINTARRAY (even if it's 3d)
char * lwgeom_to_ewkt(const LWGEOM *lwgeom)
Return an allocated string.
@ LINE_MULTICROSS_END_RIGHT
@ LINE_MULTICROSS_END_SAME_FIRST_LEFT
@ LINE_MULTICROSS_END_LEFT
@ LINE_MULTICROSS_END_SAME_FIRST_RIGHT
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) a...
#define LWDEBUG(level, msg)
#define LWDEBUGF(level, msg,...)
static const POINT2D * getPoint2d_cp(const POINTARRAY *pa, uint32_t n)
Returns a POINT2D pointer into the POINTARRAY serialized_ptlist, suitable for reading from.