44 #define GRAPH_LENGTH_FRAC 1.e-4 49 bool oddNODES =
false;
53 double x1, x2, y1, y2;
60 if ( ( ( y1 < y ) && ( y2 >= y ) ) ||
61 ( ( y2 < y ) && ( y1 >= y ) ) ) {
62 if ( x1 + ( y - y1 ) / ( y2 - y1 ) * ( x2 - x1 ) < x ) {
75 double x1, x2, x3, y1, y2, y3;
88 area += ( x2 * y3 + x1 * y2 + y1 * x3 - x2 * y1 - x3 * y2 - x1 * y3 );
93 return 0.5 * fabs(area);
107 double x1, x2, y1, y2, d, l, tx, ty, t, nx, ny, dist = 0.0;
117 d = sqrt( ( xp - x1 ) * ( xp - x1 ) + ( yp - y1 ) * ( yp - y1 ) );
126 l = sqrt( ( x2 - x1 ) * ( x2 - x1 ) + ( y2 - y1 ) * ( y2 - y1 ) );
127 tx = ( x2 - x1 ) / l;
128 ty = ( y2 - y1 ) / l;
130 t = ( xp - x1 ) * tx + ( yp - y1 ) * ty;
132 if ( ( t >= 0.0 ) && ( t <= l ) ) {
136 d = fabs( ( xp - x1 ) * nx + ( yp - y1 ) * ny );
155 LIST ggroup = make_list();
157 EASValsSetLayer(layer);
162 double xc = 0.0, yc = 0.0;
176 EASValsSetFillStyle(FILL_SOLID);
189 go = CreateTriangle3D(r);
190 add_to_tail(ggroup, go);
192 EGWithMaskChangeAttributes(COLOR_MASK | FILL_MASK | LAYER_MASK, go);
198 EASValsSetFillStyle(FILL_HOLLOW);
207 go = CreateLine3D(p);
208 add_to_tail(ggroup, go);
210 EGWithMaskChangeAttributes(COLOR_MASK | FILL_MASK | LAYER_MASK, go);
214 go = CreateGgroup(ggroup);
215 EMAddGraphicsToModel(ESIModel(), go);
233 node *next, *auxs = s, *auxc = c;
239 }
while ( auxs != s );
247 }
while ( auxc != c );
296 double par = ( ( p1->
x - p2->
x ) * ( q2->
y - q1->
y ) -
297 ( p1->
y - p2->
y ) * ( q2->
x - q1->
x ) );
299 #ifdef GRAPH_DEBUG_PRINT 300 fprintf(stderr,
"p1 [%e %e] p2 [%e %e] q1 [%e %e] q2 [%e %e]\n", p1->
x, p1->
y, p2->
x, p2->
y, q1->
x, q1->
y, q2->
x, q2->
y);
301 fprintf(stderr,
"par %e\n", par);
306 double plength = dist(p1->
x, p1->
y, p2->
x, p2->
y);
307 double qlength = dist(q1->
x, q1->
y, q2->
x, q2->
y);
308 double ptx = ( p2->
x - p1->
x ) / plength;
309 double pty = ( p2->
y - p1->
y ) / plength;
312 double d1 = ( pnx * ( q1->
x - p1->
x ) + pny * ( q1->
y - p1->
y ) );
313 double d2 = ( pnx * ( q2->
x - p1->
x ) + pny * ( q2->
y - p1->
y ) );
314 #ifdef GRAPH_DEBUG_PRINT 315 fprintf(stderr,
"dist (q-line, p-line)=%e\n", d1);
317 if ( ( fabs( d1 /
min(plength, qlength) ) >=
GT_EPS ) && ( fabs( d2 /
min(plength, qlength) ) >=
GT_EPS ) && (
sgn(d1) *
sgn(d2) > 0. ) ) {
321 double qt1 = ( ptx * ( q1->
x - p1->
x ) + pty * ( q1->
y - p1->
y ) ) / plength;
322 double qt2 = ( ptx * ( q2->
x - p1->
x ) + pty * ( q2->
y - p1->
y ) ) / plength;
323 #ifdef GRAPH_DEBUG_PRINT 324 fprintf(stderr,
"param of q1 on pline t1=%e\n", qt1);
325 fprintf(stderr,
"param of q2 on pline t2=%e\n", qt2);
327 if ( ( qt1 < 0. ) && ( qt2 < 0. ) ) {
331 if ( ( qt1 > 1. ) && ( qt2 > 1. ) ) {
335 if ( ( fabs(qt1) <
GT_EPS ) && ( fabs(1. - qt2) <
GT_EPS ) ) {
339 if ( ( fabs(qt2) <
GT_EPS ) && ( fabs(1. - qt1) <
GT_EPS ) ) {
343 double qtx = ( q2->
x - q1->
x ) / qlength;
344 double qty = ( q2->
y - q1->
y ) / qlength;
345 double pt1 = ( qtx * ( p1->
x - q1->
x ) + qty * ( p1->
y - q1->
y ) ) / qlength;
346 double pt2 = ( qtx * ( p2->
x - q1->
x ) + qty * ( p2->
y - q1->
y ) ) / qlength;
353 }
else if ( ( qt2 < -
GT_EPS ) && ( qt1 > ( 1. +
GT_EPS ) ) ) {
361 }
else if ( fabs(qt1) <
GT_EPS ) {
365 }
else if ( ( pt2 >
GT_EPS ) && ( pt2 < ( 1. -
GT_EPS ) ) ) {
371 }
else if ( fabs(1. - qt1) <
GT_EPS ) {
375 }
else if ( ( pt1 >
GT_EPS ) && ( pt1 < ( 1. -
GT_EPS ) ) ) {
381 }
else if ( fabs(qt2) <
GT_EPS ) {
385 }
else if ( ( pt2 >
GT_EPS ) && ( pt2 < ( 1. -
GT_EPS ) ) ) {
391 }
else if ( fabs(1. - qt2) <
GT_EPS ) {
395 }
else if ( ( pt1 >
GT_EPS ) && ( pt1 < ( 1. -
GT_EPS ) ) ) {
401 }
else if ( ( qt1 >=
GT_EPS ) && ( qt1 <= ( 1. -
GT_EPS ) ) ) {
402 double qlength = dist(q1->
x, q1->
y, q2->
x, q2->
y);
403 double qtx = ( q2->
x - q1->
x ) / qlength;
404 double qty = ( q2->
y - q1->
y ) / qlength;
405 double pt1 = ( qtx * ( p1->
x - q1->
x ) + qty * ( p1->
y - q1->
y ) ) / qlength;
406 double pt2 = ( qtx * ( p2->
x - q1->
x ) + qty * ( p2->
y - q1->
y ) ) / qlength;
407 if ( ( pt1 >=
GT_EPS ) && ( pt1 <= ( 1. -
GT_EPS ) ) ) {
411 }
else if ( ( pt2 >=
GT_EPS ) && ( pt2 <= ( 1. -
GT_EPS ) ) ) {
415 }
else if ( ( pt1 <=
GT_EPS || ( 1. - pt1 ) <=
GT_EPS ) && ( ( pt2 < 0. ) || ( pt2 > 1.0 ) ) ) {
419 }
else if ( ( pt2 <=
GT_EPS || ( 1. - pt2 ) <=
GT_EPS ) && ( ( pt1 < 0. ) || ( pt1 > 1.0 ) ) ) {
424 fprintf(stderr,
"testIfConcident: unresolved case q1 inside, q2 outside, pt1(t=%e), pt22(t=%e)\n", pt1, pt2);
427 }
else if ( ( qt2 >=
GT_EPS ) && ( qt2 <= ( 1. -
GT_EPS ) ) ) {
428 double qlength = dist(q1->
x, q1->
y, q2->
x, q2->
y);
429 double qtx = ( q2->
x - q1->
x ) / qlength;
430 double qty = ( q2->
y - q1->
y ) / qlength;
431 double pt1 = ( qtx * ( p1->
x - q1->
x ) + qty * ( p1->
y - q1->
y ) ) / qlength;
432 double pt2 = ( qtx * ( p2->
x - q1->
x ) + qty * ( p2->
y - q1->
y ) ) / qlength;
433 if ( ( pt1 >=
GT_EPS ) && ( pt1 <= ( 1. -
GT_EPS ) ) ) {
437 }
else if ( ( pt2 >=
GT_EPS ) && ( pt2 <= ( 1. -
GT_EPS ) ) ) {
441 }
else if ( ( pt1 <=
GT_EPS || ( 1. - pt1 ) <=
GT_EPS ) && ( ( pt2 < 0. ) || ( pt2 > 1.0 ) ) ) {
445 }
else if ( ( pt2 <=
GT_EPS || ( 1. - pt2 ) <=
GT_EPS ) && ( ( pt1 < 0. ) || ( pt1 > 1.0 ) ) ) {
450 fprintf(stderr,
"testIfConcident: unresolved case q2 inside, q1 outside, pt1(t=%e), pt2(t=%e)\n", pt1, pt2);
454 fprintf(stderr,
"testIfConcident: unresolved case, q1(t=%e), q2(t=%e)\n", qt1, qt2);
464 double *alpha_p,
double *alpha_q,
double *xint,
double *yint)
485 double x, y, tp, tq, par;
487 par = ( ( p1->
x - p2->
x ) * ( q2->
y - q1->
y ) -
488 ( p1->
y - p2->
y ) * ( q2->
x - q1->
x ) );
490 #ifdef GRAPH_DEBUG_PRINT 491 fprintf(stderr,
"p1 [%e %e] p2 [%e %e] q1 [%e %e] q2 [%e %e]\n", p1->
x, p1->
y, p2->
x, p2->
y, q1->
x, q1->
y, q2->
x, q2->
y);
492 fprintf(stderr,
"par %e\n", par);
496 fprintf(stderr,
"testIfIntersect: Parallel lines detected....\n");
497 fprintf(stderr,
"p1 [%e %e] p2 [%e %e] q1 [%e %e] q2 [%e %e]\n", p1->
x, p1->
y, p2->
x, p2->
y, q1->
x, q1->
y, q2->
x, q2->
y);
498 fprintf(stderr,
"par %e\n", par);
504 tp = ( ( p1->
x - q1->
x ) * ( q2->
y - q1->
y ) - ( q2->
x - q1->
x ) * ( p1->
y - q1->
y ) ) / par;
505 tq = ( ( p1->
x - p2->
x ) * ( p1->
y - q1->
y ) - ( p1->
x - q1->
x ) * ( p1->
y - p2->
y ) ) / par;
513 x = p1->
x + tp * ( p2->
x - p1->
x );
514 y = p1->
y + tp * ( p2->
y - p1->
y );
516 * alpha_p = dist(p1->
x, p1->
y, x, y) / dist(p1->
x, p1->
y, p2->
x, p2->
y);
517 * alpha_q = dist(q1->
x, q1->
y, x, y) / dist(q1->
x, q1->
y, q2->
x, q2->
y);
522 }
else if ( ( ( fabs(tp) <=
GT_EPS ) || ( fabs(1. - tp) <=
GT_EPS ) ) && ( ( tq >=
GT_EPS ) && ( tq <= ( 1. -
GT_EPS ) ) ) ) {
524 if ( fabs(tp) <=
GT_EPS ) {
526 * alpha_q = dist(q1->
x, q1->
y, p1->
x, p1->
y) / dist(q1->
x, q1->
y, q2->
x, q2->
y);
530 * alpha_q = dist(q1->
x, q1->
y, p2->
x, p2->
y) / dist(q1->
x, q1->
y, q2->
x, q2->
y);
533 }
else if ( ( ( fabs(tq) <=
GT_EPS ) || ( fabs(1. - tq) <=
GT_EPS ) ) && ( ( tp >=
GT_EPS ) && ( tp <= ( 1. -
GT_EPS ) ) ) ) {
535 if ( fabs(tq) <=
GT_EPS ) {
537 * alpha_p = dist(p1->
x, p1->
y, q1->
x, q1->
y) / dist(p1->
x, p1->
y, p2->
x, p2->
y);
541 * alpha_p = dist(p1->
x, p1->
y, q2->
x, q2->
y) / dist(p1->
x, p1->
y, p2->
x, p2->
y);
544 }
else if ( ( ( fabs(tq) <=
GT_EPS ) || ( fabs(1. - tq) <=
GT_EPS ) ) && ( ( fabs(tp) <=
GT_EPS ) || ( fabs(1. - tp) <=
GT_EPS ) ) ) {
546 if ( fabs(tq) <=
GT_EPS ) {
547 if ( ( fabs(tp) <=
GT_EPS ) ) {
555 if ( ( fabs(tp) <=
GT_EPS ) ) {
564 fprintf(stderr,
"testIfIntersect: unhandled case [tp %e, tq %e, par %e]\n", tp, tq, par);
583 node *auxs = NULL, *auxc = NULL, *is, *ic;
584 node *p1, *p2, *q1, *q2;
586 double alpha_s, alpha_c, alpha1, alpha2;
593 nw = this->createNode(v.
coords(0), v.
coords(1), 0, 0, 0, 0, NS_Vertex, 0, 0, 0);
607 nw = this->createNode(v.
coords(0), v.
coords(1), 0, 0, 0, 0, NS_Vertex, 0, 0, 0);
633 if ( auxs->
status != NS_Intersection ) {
635 p2 = next_node(auxs->
next);
636 if ( testCollapsedEdge(p1, p2) ) {
643 if ( auxc->status != NS_Intersection ) {
645 q2 = next_node(auxc->next);
646 if ( testCollapsedEdge(q1, q2) ) {
651 ret = testIfCoincident(p1, p2, q1, q2, & alpha1, & alpha2);
685 }
else if ( ret == 1 ) {
689 merge2vertex(p1, q1);
690 merge2vertex(p2, q2);
700 }
else if ( ret == 2 ) {
702 merge2vertex(p1, q2);
703 merge2vertex(p2, q1);
713 }
else if ( ret == 10 ) {
715 if ( vertex2IntersectionVertex(p1, q1, q2) ) {
716 is = createNode(p1->
x, p1->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha1);
719 insert( is, auxc, next_node(auxc->next) );
720 if ( alpha1 < alpha2 ) {
724 testNewIntersectionVertexEdgeCollapse(p1, q1, q2);
730 if ( vertex2IntersectionVertex(p2, q1, q2) ) {
731 ic = createNode(p2->
x, p2->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha2);
734 insert( ic, auxc, next_node(auxc->next) );
735 if ( alpha1 > alpha2 ) {
739 testNewIntersectionVertexEdgeCollapse(p2, q1, q2);
741 }
else if ( ret == 20 ) {
743 if ( vertex2IntersectionVertex(q1, p1, p2) ) {
744 is = createNode(q1->
x, q1->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha1);
747 insert( is, auxs, next_node(auxs->
next) );
748 if ( alpha1 < alpha2 ) {
752 testNewIntersectionVertexEdgeCollapse(q1, p1, p2);
758 if ( vertex2IntersectionVertex(q2, p1, p2) ) {
759 ic = createNode(q2->
x, q2->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha2);
762 insert( ic, auxs, next_node(auxs->
next) );
763 if ( alpha1 > alpha2 ) {
767 testNewIntersectionVertexEdgeCollapse(q2, p1, p2);
769 }
else if ( ret == 11 ) {
775 if ( vertex2IntersectionVertex(p1, q1, q2) ) {
776 is = createNode(p1->
x, p1->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha1);
779 insert( is, auxc, next_node(auxc->next) );
780 testNewIntersectionVertexEdgeCollapse(p1, q1, q2);
785 if ( vertex2IntersectionVertex(q1, p1, p2) ) {
786 is = createNode(q1->
x, q1->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha2);
789 insert( is, auxs, next_node(auxs->
next) );
790 testNewIntersectionVertexEdgeCollapse(q1, p1, p2);
794 }
else if ( ret == 12 ) {
800 if ( vertex2IntersectionVertex(p1, q1, q2) ) {
801 is = createNode(p1->
x, p1->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha1);
804 insert( is, auxc, next_node(auxc->next) );
805 testNewIntersectionVertexEdgeCollapse(p1, q1, q2);
811 if ( vertex2IntersectionVertex(q2, p1, p2) ) {
812 is = createNode(q2->
x, q2->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha2);
815 insert( is, auxs, next_node(auxs->
next) );
816 testNewIntersectionVertexEdgeCollapse(q2, p1, p2);
818 }
else if ( ret == 21 ) {
824 if ( vertex2IntersectionVertex(p2, q1, q2) ) {
825 is = createNode(p2->
x, p2->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha1);
828 insert( is, auxc, next_node(auxc->next) );
829 testNewIntersectionVertexEdgeCollapse(p2, q1, q2);
833 if ( vertex2IntersectionVertex(q1, p1, p2) ) {
834 is = createNode(q1->
x, q1->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha2);
837 insert( is, auxs, next_node(auxs->
next) );
838 testNewIntersectionVertexEdgeCollapse(q1, p1, p2);
842 }
else if ( ret == 22 ) {
848 if ( vertex2IntersectionVertex(p2, q1, q2) ) {
849 is = createNode(p2->
x, p2->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha1);
852 insert( is, auxc, next_node(auxc->next) );
853 testNewIntersectionVertexEdgeCollapse(p2, q1, q2);
858 if ( vertex2IntersectionVertex(q2, p1, p2) ) {
859 is = createNode(q2->
x, q2->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha2);
862 insert( is, auxs, next_node(auxs->
next) );
863 testNewIntersectionVertexEdgeCollapse(q2, p1, p2);
867 }
else if ( ret == 1102 ) {
869 merge2vertex(p1, q1);
875 if ( vertex2IntersectionVertex(q2, p1, p2) ) {
877 is = createNode(q2->
x, q2->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha1);
880 insert( is, auxs, next_node(auxs->
next) );
881 testNewIntersectionVertexEdgeCollapse(q2, p1, p2);
883 }
else if ( ret == 1120 ) {
885 merge2vertex(p1, q1);
892 if ( vertex2IntersectionVertex(p2, q1, q2) ) {
893 is = createNode(p2->
x, p2->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha1);
896 insert( is, auxc, next_node(auxc->next) );
897 testNewIntersectionVertexEdgeCollapse(p2, q1, q2);
899 }
else if ( ret == 2102 ) {
901 merge2vertex(p2, q1);
908 if ( vertex2IntersectionVertex(q2, p1, p2) ) {
909 is = createNode(q2->
x, q2->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha1);
912 insert( is, auxs, next_node(auxs->
next) );
913 testNewIntersectionVertexEdgeCollapse(q2, p1, p2);
917 }
else if ( ret == 2110 ) {
919 merge2vertex(p2, q1);
927 if ( vertex2IntersectionVertex(p1, q1, q2) ) {
928 is = createNode(p1->
x, p1->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha1);
931 insert( is, auxc, next_node(auxc->next) );
932 testNewIntersectionVertexEdgeCollapse(p1, q1, q2);
934 }
else if ( ret == 1201 ) {
936 merge2vertex(p1, q2);
943 if ( vertex2IntersectionVertex(q1, p1, p2) ) {
944 is = createNode(q1->
x, q1->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha1);
947 insert( is, auxs, next_node(auxs->
next) );
948 testNewIntersectionVertexEdgeCollapse(q1, p1, p2);
950 }
else if ( ret == 1220 ) {
952 merge2vertex(p1, q2);
959 if ( vertex2IntersectionVertex(p2, q1, q2) ) {
960 is = createNode(p2->
x, p2->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha1);
963 insert( is, auxc, next_node(auxc->next) );
964 testNewIntersectionVertexEdgeCollapse(p2, q1, q2);
968 }
else if ( ret == 2201 ) {
970 merge2vertex(p2, q2);
977 if ( vertex2IntersectionVertex(q1, p1, p2) ) {
978 is = createNode(q1->
x, q1->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha1);
981 insert( is, auxs, next_node(auxs->
next) );
982 testNewIntersectionVertexEdgeCollapse(q1, p1, p2);
986 }
else if ( ret == 2210 ) {
988 merge2vertex(p2, q2);
995 if ( vertex2IntersectionVertex(p1, q1, q2) ) {
996 is = createNode(p1->
x, p1->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha1);
999 insert( is, auxc, next_node(auxc->next) );
1000 testNewIntersectionVertexEdgeCollapse(p1, q1, q2);
1004 }
else if ( ret == 110 ) {
1006 merge2vertex(p1, q1);
1010 }
else if ( ret == 210 ) {
1012 merge2vertex(p2, q1);
1016 }
else if ( ret == 120 ) {
1018 merge2vertex(p1, q2);
1022 }
else if ( ret == 220 ) {
1024 merge2vertex(p2, q2);
1028 }
else if ( ret == -1 ) {
1029 ret = testIfIntersect(auxs, next_node(auxs->
next), auxc, next_node(auxc->next),
1030 & alpha_s, & alpha_c, & xi, & yi);
1048 }
else if ( ret == 1 ) {
1051 if ( ( p1->
status == NS_IntersectionVertex ) || ( p2->
status == NS_IntersectionVertex ) ||
1052 ( q1->
status == NS_IntersectionVertex ) || ( q2->
status == NS_IntersectionVertex ) ) {
1053 bool _p1 =
false, _p2 =
false, _q1 =
false, _q2 =
false;
1056 if ( p1->
status == NS_IntersectionVertex ) {
1057 if ( ( _p1 = belongs(p1, q1, q2) ) ) {
1062 if ( p2->
status == NS_IntersectionVertex ) {
1063 if ( ( _p2 = belongs(p2, q1, q2) ) ) {
1068 if ( q1->
status == NS_IntersectionVertex ) {
1069 if ( ( _q1 = belongs(q1, p1, p2) ) ) {
1074 if ( q2->
status == NS_IntersectionVertex ) {
1075 if ( ( _q2 = belongs(q2, p1, p2) ) ) {
1080 if ( ( c1 == 1 ) || ( c2 == 1 ) ) {
1082 }
else if ( ( c1 > 1 ) || ( c2 > 1 ) ) {
1092 is = createNode(xi, yi, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha_s);
1093 ic = createNode(xi, yi, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha_c);
1096 insert( is, auxs, next_node(auxs->
next) );
1097 insert( ic, auxc, next_node(auxc->next) );
1099 }
else if ( ret == 11 ) {
1101 merge2vertex(p1, q1);
1105 }
else if ( ret == 22 ) {
1107 merge2vertex(p2, q2);
1111 }
else if ( ret == 12 ) {
1113 merge2vertex(p1, q2);
1117 }
else if ( ret == 21 ) {
1119 merge2vertex(p2, q1);
1123 }
else if ( ret == 110 ) {
1125 if ( vertex2IntersectionVertex(p1, q1, q2) ) {
1126 is = createNode(p1->
x, p1->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha_c);
1129 insert( is, auxc, next_node(auxc->next) );
1130 testNewIntersectionVertexEdgeCollapse(p1, q1, q2);
1132 }
else if ( ret == 120 ) {
1134 if ( vertex2IntersectionVertex(p2, q1, q2) ) {
1135 is = createNode(p2->
x, p2->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha_c);
1138 insert( is, auxc, next_node(auxc->next) );
1139 testNewIntersectionVertexEdgeCollapse(p2, q1, q2);
1141 }
else if ( ret == 101 ) {
1143 if ( vertex2IntersectionVertex(q1, p1, p2) ) {
1144 is = createNode(q1->
x, q1->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha_s);
1147 insert( is, auxs, next_node(auxs->
next) );
1148 testNewIntersectionVertexEdgeCollapse(q1, p1, p2);
1150 }
else if ( ret == 102 ) {
1152 if ( vertex2IntersectionVertex(q2, p1, p2) ) {
1153 is = createNode(q2->
x, q2->
y, 0, 0, 0, 0, NS_Intersection, 0, 0, alpha_s);
1156 insert( is, auxs, next_node(auxs->
next) );
1157 testNewIntersectionVertexEdgeCollapse(q2, p1, p2);
1161 sprintf(buff,
"Graph::clip: unhandled return code (%d) from testIfIntersect service", ret);
1166 sprintf(buff,
"Graph::clip: unhandled return code (%d) from testIfCoincident service", ret);
1170 }
while ( ( auxc = auxc->next ) != c );
1172 }
while ( ( auxs = auxs->
next ) != s );
1174 #ifdef GRAPH_DEBUG_PRINT 1184 bool identical =
true;
1189 if ( auxs->
entry != -1 ) {
1193 if ( auxs->
status == NS_Intersection ) {
1194 if ( auxs->
entry != -1 ) {
1196 if ( auxs->
next->
status == NS_IntersectionVertex ) {
1204 xx = ( auxs->
x + xn ) * 0.5;
1205 yy = ( auxs->
y + yn ) * 0.5;
1209 }
else if ( auxs->
status == NS_IntersectionVertex ) {
1210 if ( auxs->
entry != -1 ) {
1212 if ( auxs->
next->
status == NS_IntersectionVertex ) {
1220 xx = ( 0.5 * ( auxs->
x + auxs->
neighbor->
x ) + xn ) * 0.5;
1221 yy = ( 0.5 * ( auxs->
y + auxs->
neighbor->
y ) + yn ) * 0.5;
1228 }
while ( auxs != s );
1233 if ( auxc->status == NS_Intersection ) {
1234 if ( auxc->entry != -1 ) {
1236 if ( auxc->next->status == NS_IntersectionVertex ) {
1237 xn = 0.5 * ( auxc->next->x + auxc->next->neighbor->x );
1238 yn = 0.5 * ( auxc->next->y + auxc->next->neighbor->y );
1244 xx = ( auxc->x + xn ) * 0.5;
1245 yy = ( auxc->y + yn ) * 0.5;
1248 }
else if ( auxc->status == NS_IntersectionVertex ) {
1249 if ( auxc->entry != -1 ) {
1251 if ( auxc->next->status == NS_IntersectionVertex ) {
1252 xn = 0.5 * ( auxc->next->x + auxc->next->neighbor->x );
1253 yn = 0.5 * ( auxc->next->y + auxc->next->neighbor->y );
1259 xx = ( 0.5 * ( auxc->x + auxc->neighbor->x ) + xn ) * 0.5;
1260 yy = ( 0.5 * ( auxc->y + auxc->neighbor->y ) + yn ) * 0.5;
1266 }
while ( auxc != c );
1275 }
while ( auxs != s );
1276 }
else if ( cnt == 0 ) {
1277 xx = ( s->x + s->next->x ) * 0.5;
1278 yy = ( s->y + s->next->y ) * 0.5;
1286 }
while ( auxs != s );
1287 }
else if (
testPoint( s, 0.5 * ( c->x + c->next->x ), 0.5 * ( c->y + c->next->y ) ) ) {
1294 }
while ( auxc != c );
1299 while ( ( crt = first(s) ) ) {
1303 if ( crt->
entry == 0 ) {
1307 if ( crt->
entry == 0 ) {
1310 }
else if ( crt->
entry == -1 ) {
1327 if ( ( crt->
status == NS_Intersection ) || ( ( crt->
status == NS_IntersectionVertex ) ) ) {
1339 #ifdef GRAPH_DEBUG_PRINT 1341 printf(
"Resulting Graph:\n");
1344 printf(
"Node [xy %e %e %e]\n", v.
coords(0), v.
coords(1), 0.0);
1358 while ( aux && ( aux->
status == NS_Intersection ) ) {
1370 while ( aux && ( aux->
status == NS_Intersection ) ) {
1382 while ( aux->
next ) {
1407 }
while ( aux != p );
1418 if ( n->
status == NS_Vertex ) {
1421 if ( ( next_node(n->
neighbor) == v2 ) && ( prev_node(n->
neighbor) == v1 ) ) {
1425 if ( ( prev_node(n->
neighbor) == v2 ) && ( next_node(n->
neighbor) == v1 ) ) {
1440 return sqrt( ( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ) );
1445 node *neighbor,
nodeStatus st,
int entry,
int visited,
double alpha)
1473 while ( aux != last && aux->
alpha <= ins->
alpha ) {
1499 while ( aux != q2 ) {
1500 if ( aux->
status == NS_Intersection ) {
1516 if ( dist(p1->
x, p1->
y, p2->
x, p2->
y) <=
GT_EPS ) {
1528 while ( aux != q2 ) {
1530 if ( aux->
status == NS_Intersection ) {
1558 if ( v->
status == NS_IntersectionVertex ) {
1563 THROW_GT_EXCEPTIONM(
"Graph::vertex2IntersectionVertex: topology error, neighbor is unrelated intersectionVertex");
1573 merge2vertex(v, l1);
1575 merge2vertex(v, l2);
1583 removeIntersectionIfExist(pv, v, l1, l2);
1584 removeIntersectionIfExist(v, nv, l1, l2);
1587 v->
status = NS_IntersectionVertex;
1596 double v_par, vp_par, vn_par;
1614 }
else if ( belongs(prev_node(v->
prev), l1, l2) ) {
1634 if ( v_par < vp_par ) {
1639 }
else if ( belongs(next_node(v->
next), l1, l2) ) {
1659 if ( v_par < vn_par ) {
1672 bool boundary =
false;
1673 if ( v1->
status == NS_IntersectionVertex && v2->
status == NS_IntersectionVertex ) {
1684 THROW_GT_EXCEPTIONM(
"Graph::merge2vertex: consistency error (one of merged vertices (or both) linked to another vertex already");
1686 }
else if ( v1->
status == NS_IntersectionVertex ) {
1694 v2->
status = NS_IntersectionVertex;
1698 }
else if ( v2->
status == NS_IntersectionVertex ) {
1706 v1->
status = NS_IntersectionVertex;
1720 bool oddNODES =
false;
1721 double x1, x2, y1, y2;
1731 if ( ( ( y1 < y ) && ( y2 >= y ) ) ||
1732 ( ( y2 < y ) && ( y1 >= y ) ) ) {
1733 if ( x1 + ( y - y1 ) / ( y2 - y1 ) * ( x2 - x1 ) < x ) {
1734 oddNODES = !oddNODES;
1739 }
while ( auxs != s );
1751 printf(
"Graph 1/2:\n");
1754 if ( auxs->
status == NS_Vertex ) {
1755 printf(
"Vertex [xy %e %e %e] [e=%d]\n", auxs->
x, auxs->
y, 0.0, auxs->
entry);
1756 }
else if ( auxs->
status == NS_IntersectionVertex ) {
1757 printf(
"IVertex [xy %e %e %e] [e=%d]\n", auxs->
x, auxs->
y, 0.0, auxs->
entry);
1759 printf(
"Intrsc [xy %e %e %e] [e=%d]\n", auxs->
x, auxs->
y, 0.0, auxs->
entry);
1763 }
while ( auxs != s );
1766 printf(
"Graph 2/2:\n");
1769 if ( auxc->
status == NS_Vertex ) {
1770 printf(
"Vertex [xy %e %e %e] [e=%d]\n", auxc->
x, auxc->
y, 0.0, auxc->
entry);
1771 }
else if ( auxc->
status == NS_IntersectionVertex ) {
1772 printf(
"IVertex [xy %e %e %e] [e=%d]\n", auxc->
x, auxc->
y, 0.0, auxc->
entry);
1774 printf(
"Intrsc [xy %e %e %e] [e=%d]\n", auxc->
x, auxc->
y, 0.0, auxc->
entry);
1778 }
while ( auxc != c );
1787 fprintf(stderr,
"\nGT_Exception thrown in %s:%d\n", file, line);
1789 fprintf(stderr,
"msg: %s\n", msg);
double computeVolume() const
double pointDistance(double x, double y) const
double sgn(double i)
Returns the signum of given value (if value is < 0 returns -1, otherwise returns 1) ...
void merge2vertex(node *v1, node *v2)
oofem::oofegGraphicContext gc[OOFEG_LAST_LAYER]
node * prev_node(node *p)
int testIfIntersect(node *p1, node *p2, node *q1, node *q2, double *alpha_p, double *alpha_q, double *xint, double *yint)
double dist(double x1, double y1, double x2, double y2)
int vertex2IntersectionVertex(node *v, node *l1, node *l2)
void removeIntersectionIfExist(node *p1, node *p2, node *q1, node *q2)
void clip(Polygon &result, const Polygon &a, const Polygon &b)
node * last_node(node *p)
int testPoint(node *poly, double x, double y) const
void insert(node *ins, node *first, node *last)
Class representing 2D polygon.
void setCoords(double x, double y)
bool intersectionExist(node *p1, node *p2, node *q1, node *q2)
int testIfCoincident(node *p1, node *p2, node *q1, node *q2, double *alpha_1, double *alpha_2)
Class representing vertex.
int min(int i, int j)
Returns smaller value from two given decimals.
void testNewIntersectionVertexEdgeCollapse(node *v, node *l1, node *l2)
int testPoint(double x, double y) const
node * createNode(double x, double y, node *next, node *prev, node *nextPoly, node *neighbor, nodeStatus st, int entry, int visited, double alpha)
Create new node struct.
GraphicObj * draw(oofegGraphicContext &, bool filled, int layer=OOFEG_DEBUG_LAYER)
bool testCollapsedEdge(node *p1, node *p2)
the oofem namespace is to define a context or scope in which all oofem names are defined.
bool belongs(node *n, node *v1, node *v2)
void init(const Polygon *p)
int giveNext(Vertex &p1, Vertex &p2)
node * next_node(node *p)