29#define D ((ax2 - ax1) * (by1 - by2) - (ay2 - ay1) * (bx1 - bx2))
30#define DA ((bx1 - ax1) * (by1 - by2) - (by1 - ay1) * (bx1 - bx2))
31#define DB ((ax2 - ax1) * (by1 - ay1) - (ay2 - ay1) * (bx1 - ax1))
33#ifdef ASDASDASFDSAFFDAS
91void swap(
double *a,
double *
b)
103 double *x1,
double *y1,
double *x2,
double *y2)
125 G_debug(3,
"segment_intersection_2d_e()");
138 G_debug(3,
" identical segments");
147 G_debug(3,
" connected by endpoints");
153 G_debug(3,
" connected by endpoints");
160 G_debug(3,
" no intersection (disjoint bounding boxes)");
164 G_debug(3,
" no intersection (disjoint bounding boxes)");
171 G_debug(3,
" general position");
186 G_debug(3,
" no intersection");
193 G_debug(3,
" no intersection");
199 G_debug(3,
" no intersection");
206 G_debug(3,
" no intersection");
227 G_debug(3,
" intersection %.16g, %.16g", *x1, *y1);
236 G_debug(3,
" parallel segments");
267 G_debug(3,
" collinear segments");
270 G_debug(3,
" no intersection");
314 G_debug(3,
" partial overlap");
347 G_warning((
"segment_intersection_2d() ERROR (should not be reached)"));
363 double *x1,
double *y1,
double *x2,
double *y2,
373 G_debug(4,
"segment_intersection_2d()");
384 G_debug(2,
" -> identical segments");
440 G_debug(2,
" not parallel/collinear: ra = %.18g",
ra);
445 G_debug(2,
" no intersection");
453 G_debug(2,
" intersection %.18f, %.18f", *x1, *y1);
458 G_debug(3,
" -> parallel/collinear");
477 G_debug(2,
" -> collinear vertical");
489 G_debug(2,
" -> no intersection");
497 G_debug(2,
" -> connected by end points");
503 G_debug(2,
" -> connected by end points");
508 G_debug(3,
" -> vertical overlap");
511 G_debug(2,
" -> a contains b");
523 G_debug(2,
" -> b contains a");
535 G_debug(2,
" -> partial overlap");
570 "Vect_segment_intersection() ERROR (collinear vertical segments)"));
579 G_debug(2,
" -> collinear non vertical");
584 G_debug(2,
" -> no intersection");
589 G_debug(2,
" -> overlap/connected end points");
595 G_debug(2,
" -> connected by end points");
601 G_debug(2,
" -> connected by end points");
624 G_debug(2,
" -> a contains b");
636 G_debug(2,
" -> b contains a");
648 G_debug(2,
" -> partial overlap");
682 (
"segment_intersection_2d() ERROR (collinear non vertical segments)"));
694 double *x1,
double *y1,
double *x2,
double *y2)
740 G_debug(
DLEVEL,
" no intersection (disjoint bounding boxes)");
744 G_debug(
DLEVEL,
" no intersection (disjoint bounding boxes)");
788 if ((
da < 0) || (
da > d)) {
794 if ((
db < 0) || (
db > d)) {
800 if ((
da > 0) || (
da < d)) {
806 if ((
db > 0) || (
db < d)) {
828 if ((
da != 0) || (
db != 0)) {
916 G_warning((
"segment_intersection_2d() ERROR (should not be reached)"));
935 if (a == 0 ||
b == 0) {
951 double *x1,
double *y1,
double *x2,
double *y2)
975 G_debug(3,
"segment_intersection_2d_test()");
988 G_debug(4,
" identical segments");
997 G_debug(4,
" connected by endpoints");
1003 G_debug(4,
" connected by endpoints");
1010 G_debug(4,
" no intersection (disjoint bounding boxes)");
1014 G_debug(4,
" no intersection (disjoint bounding boxes)");
1025 G_debug(3,
" dd = %sE%d", (s[0] == 0) ?
"0" : s,
exp);
1029 G_debug(3,
" general position");
1042 G_debug(4,
" rra = %sE%d", (s[0] == 0) ?
"0" : s,
exp);
1045 G_debug(4,
" rrb = %sE%d", (s[0] == 0) ?
"0" : s,
exp);
1081 G_debug(2,
" intersection at:");
1082 G_debug(2,
" xx = %.18e", *x1);
1084 G_debug(2,
" yy = %.18e", *y1);
1089 G_debug(3,
" parallel/collinear...");
void G_warning(const char *,...) __attribute__((format(printf
int G_debug(int, const char *,...) __attribute__((format(printf
int segment_intersection_2d(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, double bx2, double by2, double *x1, double *y1, double *x2, double *y2)
int segment_intersection_2d_tol(double ax1, double ay1, double ax2, double ay2, double bx1, double by1, double bx2, double by2, double *x1, double *y1, double *x2, double *y2, double tol)
int almost_equal(double a, double b, int bits)
#define FEQUAL(X, Y, TOL)