Given two lines, characterize how (and if) they cross each other.
Given two lines, characterize how (and if) they cross each other.
463{
464 uint32_t i = 0, j = 0;
465 const POINT2D *p1, *p2, *q1, *q2;
467 int cross_left = 0;
468 int cross_right = 0;
469 int first_cross = 0;
470 int this_cross = 0;
471#if POSTGIS_DEBUG_LEVEL >= 4
472 char *geom_ewkt;
473#endif
474
477
478
479 if ( pa1->npoints < 2 || pa2->npoints < 2 )
481
482
485
486
487#if POSTGIS_DEBUG_LEVEL >= 4
494#endif
495
496
498
499 for ( i = 1; i < pa2->npoints; i++ )
500 {
501
502
504
505
507
508 for ( j = 1; j < pa1->npoints; j++ )
509 {
510
511
513
515
516 LWDEBUGF(4,
"i=%d, j=%d (%.8g %.8g, %.8g %.8g)", this_cross, i, j, p1->x, p1->y, p2->x, p2->y);
517
519 {
520 LWDEBUG(4,
"this_cross == SEG_CROSS_LEFT");
521 cross_left++;
522 if ( ! first_cross )
524 }
525
527 {
528 LWDEBUG(4,
"this_cross == SEG_CROSS_RIGHT");
529 cross_right++;
530 if ( ! first_cross )
532 }
533
534
535
536
537
538
540 {
541 LWDEBUG(4,
"this_cross == SEG_COLINEAR");
542
543
544
545 }
546
547 LWDEBUG(4,
"this_cross == SEG_NO_INTERSECTION");
548
549
550 p1 = p2;
551
552 }
553
554
555 q1 = q2;
556
557 }
558
559 LWDEBUGF(4,
"first_cross=%d, cross_left=%d, cross_right=%d", first_cross, cross_left, cross_right);
560
561 if ( !cross_left && !cross_right )
563
564 if ( !cross_left && cross_right == 1 )
566
567 if ( !cross_right && cross_left == 1 )
569
570 if ( cross_left - cross_right == 1 )
572
573 if ( cross_left - cross_right == -1 )
575
576 if ( cross_left - cross_right == 0 && first_cross ==
SEG_CROSS_LEFT )
578
581
583
584}
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 alloced 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.