| 1 |
|
| #include "EXTERN.h" |
| 2 |
|
| #include "perl.h" |
| 3 |
|
| #include "XSUB.h" |
| 4 |
|
| |
| 5 |
|
| struct point { double x,y; int m; }; |
| 6 |
|
| |
| 7 |
|
| #define X(a) (SvNV(*av_fetch(a,0,0))) |
| 8 |
|
| #define Y(a) (SvNV(*av_fetch(a,1,0))) |
| 9 |
|
| |
| 10 |
|
| #define LOS 1 |
| 11 |
|
| #define ALL_LHS 2 |
| 12 |
|
| #define ALL_RHS 4 |
| 13 |
|
| |
| 14 |
|
| // AV *av_fwc(AV *a, int i) {{{ |
| 15 |
0 |
| AV *av_fwc(AV *a, int i) { |
| 16 |
0 |
| SV *s = *av_fetch(a,i,0); |
| 17 |
0 |
| AV *x = (AV *) SvRV(s); |
| 18 |
|
| |
| 19 |
0 |
▶ | if ((!SvROK(s)) || (SvTYPE(x) != SVt_PVAV)) |
Branch: 2 branches
| Branch | True | False | Total |
| if ((!SvROK(s)) || (SvTYPE(x) != SVt_PVAV)) |
0 |
0 |
0 |
| if ((!SvROK(s)) || (SvTYPE(x) != SVt_PVAV)) |
0 |
0 |
0 |
|
| 20 |
0 |
| croak("bad element (wrong type) in line segment array while processing from _std_intersect_loop()"); |
| 21 |
|
| |
| 22 |
0 |
▶ | if (av_len(x) != 1) |
Branch: 1 branch
| Branch | True | False | Total |
| if (av_len(x) != 1) |
0 |
0 |
0 |
|
| 23 |
0 |
| croak("bad element (wrong size) in line segment array while processing from _std_intersect_loop()"); |
| 24 |
|
| |
| 25 |
0 |
| return x; |
| 26 |
|
| } |
| 27 |
|
| // }}} |
| 28 |
|
| // int intersect(struct point A, struct point B, struct point C, struct point D) {{{ |
| 29 |
0 |
| int intersect(struct point A, struct point B, struct point C, struct point D) { |
| 30 |
|
| double d,p; |
| 31 |
|
| // fprintf(stderr, "[xs] A(%9.6f,%9.6f) B(%9.6f,%9.6f) C(%9.6f,%9.6f) D(%9.6f,%9.6f)", A.x,A.y, B.x,B.y, C.x,C.y, D.x,D.y); |
| 32 |
|
| |
| 33 |
|
| // perl // # P = p*A + (1-p)*B |
| 34 |
|
| // perl // # Q = q*C + (1-q)*D |
| 35 |
|
| // perl // |
| 36 |
|
| // perl // # for p=0, P=A, and for p=1, P=B |
| 37 |
|
| // perl // # for 0<=p<=1, P is on the line segment between A and B |
| 38 |
|
| // perl // |
| 39 |
|
| // perl // # find p,q such than P=Q |
| 40 |
|
| // perl // # (... lengthy derivation ...) |
| 41 |
|
| // perl // |
| 42 |
|
| // perl // my $d = ($ax-$bx)*($cy-$dy) - ($ay-$by)*($cx-$dx); |
| 43 |
|
| |
| 44 |
0 |
| d = (A.x-B.x)*(C.y-D.y) - (A.y-B.y)*(C.x-D.x); |
| 45 |
|
| // fprintf(stderr, " d=%f", d); |
| 46 |
|
| |
| 47 |
|
| // perl // if( $cx == $dx and $cy == $dy ) { |
| 48 |
|
| // perl // # 6/25/7 we're a point on the rhs ... apparently this happens when you remove the extrude shortcutting |
| 49 |
|
| // perl // |
| 50 |
|
| // perl // if( $ay == $by and $cy == $ay ) { |
| 51 |
|
| // perl // return ($cx, $cy) if $ax <= $cx and $cx <= $bx; |
| 52 |
|
| // perl // |
| 53 |
|
| // perl // } elsif( $ax == $bx and $cx == $ax ) { |
| 54 |
|
| // perl // return ($cx, $cy) if $ay <= $cy and $cy <= $by; |
| 55 |
|
| // perl // } |
| 56 |
|
| // perl // |
| 57 |
|
| // perl // die "probably a bug"; |
| 58 |
|
| // perl // } |
| 59 |
|
| |
| 60 |
0 |
▶ | if( C.x == D.x && C.y == D.y ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if( C.x == D.x && C.y == D.y ) { |
0 |
0 |
0 |
| if( C.x == D.x && C.y == D.y ) { |
0 |
0 |
0 |
|
| 61 |
0 |
▶ | if( A.y == B.y && C.y == A.y ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if( A.y == B.y && C.y == A.y ) { |
0 |
0 |
0 |
| if( A.y == B.y && C.y == A.y ) { |
0 |
0 |
0 |
|
| 62 |
0 |
▶ | if( A.x <= C.x && C.x <= B.x ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( A.x <= C.x && C.x <= B.x ) |
0 |
0 |
0 |
| if( A.x <= C.x && C.x <= B.x ) |
0 |
0 |
0 |
|
| 63 |
0 |
| return 1; |
| 64 |
|
| |
| 65 |
0 |
▶ | } else if( A.x == B.x && C.x == A.x ) { |
Branch: 2 branches
| Branch | True | False | Total |
| } else if( A.x == B.x && C.x == A.x ) { |
0 |
0 |
0 |
| } else if( A.x == B.x && C.x == A.x ) { |
0 |
0 |
0 |
|
| 66 |
0 |
▶ | if( A.y <= C.y && C.y <= B.y ) |
Branch: 2 branches
| Branch | True | False | Total |
| if( A.y <= C.y && C.y <= B.y ) |
0 |
0 |
0 |
| if( A.y <= C.y && C.y <= B.y ) |
0 |
0 |
0 |
|
| 67 |
0 |
| return 1; |
| 68 |
|
| } |
| 69 |
|
| |
| 70 |
0 |
| die("probably a bug"); |
| 71 |
|
| } |
| 72 |
|
| |
| 73 |
0 |
▶ | if( d == 0 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( d == 0 ) { |
0 |
0 |
0 |
|
| 74 |
|
| // perl // if( $d == 0 ) { |
| 75 |
|
| // perl // # d=0 when len(C->D)==0 !! |
| 76 |
|
| // perl // for my $l ([$ax,$ay], [$bx, $by]) { |
| 77 |
|
| // perl // for my $r ([$cx,$cy], [$dx, $dy]) { |
| 78 |
|
| // perl // return (@$l) if $l->[0] == $r->[0] and $l->[1] == $r->[1]; |
| 79 |
|
| // perl // }} |
| 80 |
|
| |
| 81 |
0 |
▶ | if( (A.x == C.x && A.y == C.y) || (B.x == C.x && B.y == C.y) || (A.x == D.x && A.y == D.y) || (B.x == D.x && B.y == D.y) ) |
Branch: 8 branches
| Branch | True | False | Total |
| if( (A.x == C.x && A.y == C.y) || (B.x == C.x && B.y == C.y) || (A.x == D.x && A.y == D.y) || (B.x == D.x && B.y == D.y) ) |
0 |
0 |
0 |
| if( (A.x == C.x && A.y == C.y) || (B.x == C.x && B.y == C.y) || (A.x == D.x && A.y == D.y) || (B.x == D.x && B.y == D.y) ) |
0 |
0 |
0 |
| if( (A.x == C.x && A.y == C.y) || (B.x == C.x && B.y == C.y) || (A.x == D.x && A.y == D.y) || (B.x == D.x && B.y == D.y) ) |
0 |
0 |
0 |
| if( (A.x == C.x && A.y == C.y) || (B.x == C.x && B.y == C.y) || (A.x == D.x && A.y == D.y) || (B.x == D.x && B.y == D.y) ) |
0 |
0 |
0 |
| if( (A.x == C.x && A.y == C.y) || (B.x == C.x && B.y == C.y) || (A.x == D.x && A.y == D.y) || (B.x == D.x && B.y == D.y) ) |
0 |
0 |
0 |
| if( (A.x == C.x && A.y == C.y) || (B.x == C.x && B.y == C.y) || (A.x == D.x && A.y == D.y) || (B.x == D.x && B.y == D.y) ) |
0 |
0 |
0 |
| if( (A.x == C.x && A.y == C.y) || (B.x == C.x && B.y == C.y) || (A.x == D.x && A.y == D.y) || (B.x == D.x && B.y == D.y) ) |
0 |
0 |
0 |
| if( (A.x == C.x && A.y == C.y) || (B.x == C.x && B.y == C.y) || (A.x == D.x && A.y == D.y) || (B.x == D.x && B.y == D.y) ) |
0 |
0 |
0 |
|
| 82 |
0 |
| return 1; |
| 83 |
|
| |
| 84 |
|
| // perl // |
| 85 |
|
| // perl // # NOTE: another huge bug from 6/23/7 !! This vertical overlap was totally overlooked before. |
| 86 |
|
| // perl // # This is arguably not the most efficient way to check it, but it's literally better than *nothing* |
| 87 |
|
| // perl // if( fabs($ax-$bx)<0.0001 and fabs($bx-$cx)<0.0001 and fabs($cx-$dx)<0.0001 ) { |
| 88 |
|
| // perl // return ($cx,$cy) if $ay <= $cy and $cy <= $by; |
| 89 |
|
| // perl // return ($dx,$dy) if $ay <= $dy and $dy <= $by; |
| 90 |
|
| // perl // |
| 91 |
0 |
▶ | if( fabs(A.x-B.x)<0.0001 && fabs(B.x-C.x)<0.0001 && fabs(C.x-D.x)<0.0001 ) { |
Branch: 3 branches
| Branch | True | False | Total |
| if( fabs(A.x-B.x)<0.0001 && fabs(B.x-C.x)<0.0001 && fabs(C.x-D.x)<0.0001 ) { |
0 |
0 |
0 |
| if( fabs(A.x-B.x)<0.0001 && fabs(B.x-C.x)<0.0001 && fabs(C.x-D.x)<0.0001 ) { |
0 |
0 |
0 |
| if( fabs(A.x-B.x)<0.0001 && fabs(B.x-C.x)<0.0001 && fabs(C.x-D.x)<0.0001 ) { |
0 |
0 |
0 |
|
| 92 |
0 |
▶ | if( (A.y<=C.y && C.y<=B.y) || (A.y<=D.y && D.y<=B.y) ) |
Branch: 4 branches
| Branch | True | False | Total |
| if( (A.y<=C.y && C.y<=B.y) || (A.y<=D.y && D.y<=B.y) ) |
0 |
0 |
0 |
| if( (A.y<=C.y && C.y<=B.y) || (A.y<=D.y && D.y<=B.y) ) |
0 |
0 |
0 |
| if( (A.y<=C.y && C.y<=B.y) || (A.y<=D.y && D.y<=B.y) ) |
0 |
0 |
0 |
| if( (A.y<=C.y && C.y<=B.y) || (A.y<=D.y && D.y<=B.y) ) |
0 |
0 |
0 |
|
| 93 |
0 |
| return 1; |
| 94 |
|
| } |
| 95 |
|
| |
| 96 |
|
| // perl // # 6/25/7 -- sorta the same deal as above, but horizontal |
| 97 |
|
| // perl // } elsif( fabs($ay-$by)<0.0001 and fabs($by-$cy)<0.0001 and fabs($cy-$dy)<0.0001 ) { |
| 98 |
|
| // perl // return ($cx,$cy) if $ax <= $cx and $cx <= $bx; |
| 99 |
|
| // perl // return ($dx,$dy) if $ax <= $dx and $dx <= $bx; |
| 100 |
|
| // perl // } |
| 101 |
0 |
▶ | if( fabs(A.y-B.y)<0.0001 && fabs(B.y-C.y)<0.0001 && fabs(C.y-D.y)<0.0001 ) { |
Branch: 3 branches
| Branch | True | False | Total |
| if( fabs(A.y-B.y)<0.0001 && fabs(B.y-C.y)<0.0001 && fabs(C.y-D.y)<0.0001 ) { |
0 |
0 |
0 |
| if( fabs(A.y-B.y)<0.0001 && fabs(B.y-C.y)<0.0001 && fabs(C.y-D.y)<0.0001 ) { |
0 |
0 |
0 |
| if( fabs(A.y-B.y)<0.0001 && fabs(B.y-C.y)<0.0001 && fabs(C.y-D.y)<0.0001 ) { |
0 |
0 |
0 |
|
| 102 |
0 |
▶ | if( (A.x<=C.x && C.x<=B.x) || (A.x<=D.x && D.x<=B.x) ) |
Branch: 4 branches
| Branch | True | False | Total |
| if( (A.x<=C.x && C.x<=B.x) || (A.x<=D.x && D.x<=B.x) ) |
0 |
0 |
0 |
| if( (A.x<=C.x && C.x<=B.x) || (A.x<=D.x && D.x<=B.x) ) |
0 |
0 |
0 |
| if( (A.x<=C.x && C.x<=B.x) || (A.x<=D.x && D.x<=B.x) ) |
0 |
0 |
0 |
| if( (A.x<=C.x && C.x<=B.x) || (A.x<=D.x && D.x<=B.x) ) |
0 |
0 |
0 |
|
| 103 |
0 |
| return 1; |
| 104 |
|
| } |
| 105 |
|
| |
| 106 |
|
| // perl // ## DEBUG ## warn "\t\tlsi p=||\n"; |
| 107 |
|
| // perl // return; # probably parallel |
| 108 |
|
| // perl // } |
| 109 |
0 |
| return 0; |
| 110 |
|
| } |
| 111 |
|
| |
| 112 |
|
| // perl // my $p = ( ($by-$dy)*($cx-$dx) - ($bx-$dx)*($cy-$dy) ) / $d; |
| 113 |
|
| |
| 114 |
0 |
| p = ( (B.y-D.y)*(C.x-D.x) - (B.x-D.x)*(C.y-D.y) ) / d; |
| 115 |
|
| // fprintf(stderr, " p=%f", p); |
| 116 |
|
| |
| 117 |
|
| // perl // ## NOTE: this was an effin hard bug to find... |
| 118 |
|
| // perl // ## my @w = ( ( ($p <= 1) ? 1:0 ), ( ($p == 1) ? 1:0 ), ( ($p != 1) ? 1:0 ), ( ($p - 1) ),); |
| 119 |
|
| // perl // ## warn "\t\tlsi p=$p (@w)\n"; |
| 120 |
|
| // perl // ## lsi p-1 = 2.22044604925031e-16 = 1? No, not actually, sometimes... |
| 121 |
|
| // perl // |
| 122 |
|
| // perl // $p = 0 if fabs($p) < 0.00001; # fixed 6/23/7 |
| 123 |
|
| // perl // $p = 1 if fabs($p-1) < 0.00001; |
| 124 |
|
| |
| 125 |
0 |
▶ | if( fabs(p) < 0.00001 ) p = 0; |
Branch: 1 branch
| Branch | True | False | Total |
| if( fabs(p) < 0.00001 ) p = 0; |
0 |
0 |
0 |
|
| 126 |
0 |
▶ | if( fabs(p-1) < 0.00001 ) p = 1; |
Branch: 1 branch
| Branch | True | False | Total |
| if( fabs(p-1) < 0.00001 ) p = 1; |
0 |
0 |
0 |
|
| 127 |
|
| |
| 128 |
|
| // fprintf(stderr, " p=%f\n", p); |
| 129 |
|
| |
| 130 |
|
| // perl // ## DEBUG ## warn "\t\tlsi p=$p\n"; |
| 131 |
|
| // perl // |
| 132 |
|
| // perl // # we probably don't need to find q because we already restricted the domain/range above |
| 133 |
|
| // perl // return unless $p >= 0 and $p <= 1; |
| 134 |
|
| |
| 135 |
0 |
▶ | if( p>=0 && p<=1 ) // reversed this logic |
Branch: 2 branches
| Branch | True | False | Total |
| if( p>=0 && p<=1 ) // reversed this logic |
0 |
0 |
0 |
| if( p>=0 && p<=1 ) // reversed this logic |
0 |
0 |
0 |
|
| 136 |
0 |
| return 1; |
| 137 |
|
| |
| 138 |
|
| // perl // |
| 139 |
|
| // perl // my $px = $p*$ax + (1-$p)*$bx; |
| 140 |
|
| // perl // my $py = $p*$ay + (1-$p)*$by; |
| 141 |
|
| // perl // |
| 142 |
|
| // perl // return ($px, $py); |
| 143 |
|
| |
| 144 |
0 |
| return 0; // reversed this logic |
| 145 |
|
| } |
| 146 |
|
| // }}} |
| 147 |
|
| // int inner_any_any(struct point *lps, struct point *rps, struct point *op1, struct point *op2, int strategy) {{{ |
| 148 |
0 |
| int inner_any_any(struct point *lps, struct point *rps, struct point *op1, struct point *op2, int strategy) { |
| 149 |
|
| int i,j,k; |
| 150 |
|
| int l,r,o; |
| 151 |
|
| int blocked; |
| 152 |
|
| |
| 153 |
0 |
| l=lps[0].m; r=rps[0].m; o=op1[0].m; |
| 154 |
|
| |
| 155 |
0 |
▶ | if( strategy ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( strategy ) { |
0 |
0 |
0 |
|
| 156 |
0 |
▶ | for(i=0; i<=l; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<=l; i++) { |
0 |
0 |
0 |
|
| 157 |
0 |
▶ | for(j=0; j<=r; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0; j<=r; j++) { |
0 |
0 |
0 |
|
| 158 |
0 |
| blocked = 0; |
| 159 |
0 |
▶ | for(k=0; k<=o; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=0; k<=o; k++) { |
0 |
0 |
0 |
|
| 160 |
0 |
▶ | if( intersect(op1[k], op2[k], lps[i], rps[j]) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( intersect(op1[k], op2[k], lps[i], rps[j]) ) { |
0 |
0 |
0 |
|
| 161 |
0 |
| blocked ++; |
| 162 |
0 |
| break; |
| 163 |
|
| } |
| 164 |
|
| } |
| 165 |
|
| |
| 166 |
0 |
▶ | if( !blocked ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( !blocked ) |
0 |
0 |
0 |
|
| 167 |
0 |
| return 1; |
| 168 |
|
| }} |
| 169 |
|
| |
| 170 |
|
| } else { |
| 171 |
0 |
▶ | for(i=0; i<=l; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<=l; i++) { |
0 |
0 |
0 |
|
| 172 |
0 |
▶ | for(j=0; j<=r; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0; j<=r; j++) { |
0 |
0 |
0 |
|
| 173 |
0 |
| blocked = 0; |
| 174 |
0 |
▶ | for(k=0; k<=o; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=0; k<=o; k++) { |
0 |
0 |
0 |
|
| 175 |
0 |
▶ | if( intersect(op1[k], op2[k], lps[i], rps[j]) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( intersect(op1[k], op2[k], lps[i], rps[j]) ) { |
0 |
0 |
0 |
|
| 176 |
0 |
| blocked ++; break; |
| 177 |
|
| } |
| 178 |
|
| } |
| 179 |
|
| |
| 180 |
0 |
▶ | if( blocked ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( blocked ) |
0 |
0 |
0 |
|
| 181 |
0 |
| return 1; |
| 182 |
|
| }} |
| 183 |
|
| } |
| 184 |
|
| |
| 185 |
0 |
| return 0; |
| 186 |
|
| } |
| 187 |
|
| // }}} |
| 188 |
|
| // int inner_any_all(struct point *lps, struct point *rps, struct point *op1, struct point *op2, int strategy) {{{ |
| 189 |
0 |
| int inner_any_all(struct point *lps, struct point *rps, struct point *op1, struct point *op2, int strategy) { |
| 190 |
|
| int i,j,k; |
| 191 |
|
| int l,r,o; |
| 192 |
|
| int blocked; |
| 193 |
|
| int c; |
| 194 |
|
| |
| 195 |
0 |
| l=lps[0].m; r=rps[0].m; o=op1[0].m; |
| 196 |
|
| |
| 197 |
0 |
▶ | if( strategy ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( strategy ) { |
0 |
0 |
0 |
|
| 198 |
0 |
▶ | for(i=0; i<=l; i++) { c=0; |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<=l; i++) { c=0; |
0 |
0 |
0 |
|
| 199 |
0 |
▶ | for(j=0; j<=r; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0; j<=r; j++) { |
0 |
0 |
0 |
|
| 200 |
0 |
| blocked = 0; |
| 201 |
0 |
▶ | for(k=0; k<=o; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=0; k<=o; k++) { |
0 |
0 |
0 |
|
| 202 |
0 |
▶ | if( intersect(op1[k], op2[k], lps[i], rps[j]) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( intersect(op1[k], op2[k], lps[i], rps[j]) ) { |
0 |
0 |
0 |
|
| 203 |
0 |
| blocked ++; |
| 204 |
0 |
| break; |
| 205 |
|
| } |
| 206 |
|
| } |
| 207 |
|
| |
| 208 |
0 |
▶ | if( !blocked ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( !blocked ) |
0 |
0 |
0 |
|
| 209 |
0 |
| c++; |
| 210 |
|
| } |
| 211 |
|
| |
| 212 |
|
| // fprintf(stderr, "\e[1;30m[%0.4f,%0.4f] c=%d;j=%d\e[m\n", lps[i].x,lps[i].y, c,j ); |
| 213 |
|
| |
| 214 |
0 |
▶ | if( c==j ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( c==j ) |
0 |
0 |
0 |
|
| 215 |
0 |
| return 1; |
| 216 |
|
| } |
| 217 |
|
| |
| 218 |
|
| } else { |
| 219 |
0 |
▶ | for(i=0; i<=l; i++) { c=0; |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<=l; i++) { c=0; |
0 |
0 |
0 |
|
| 220 |
0 |
▶ | for(j=0; j<=r; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0; j<=r; j++) { |
0 |
0 |
0 |
|
| 221 |
0 |
| blocked = 0; |
| 222 |
0 |
▶ | for(k=0; k<=o; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=0; k<=o; k++) { |
0 |
0 |
0 |
|
| 223 |
0 |
▶ | if( intersect(op1[k], op2[k], lps[i], rps[j]) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( intersect(op1[k], op2[k], lps[i], rps[j]) ) { |
0 |
0 |
0 |
|
| 224 |
0 |
| blocked ++; |
| 225 |
0 |
| break; |
| 226 |
|
| } |
| 227 |
|
| } |
| 228 |
|
| |
| 229 |
0 |
▶ | if( blocked ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( blocked ) |
0 |
0 |
0 |
|
| 230 |
0 |
| c++; |
| 231 |
|
| } |
| 232 |
|
| |
| 233 |
0 |
▶ | if( c==j ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( c==j ) |
0 |
0 |
0 |
|
| 234 |
0 |
| return 1; |
| 235 |
|
| } |
| 236 |
|
| } |
| 237 |
|
| |
| 238 |
0 |
| return 0; |
| 239 |
|
| } |
| 240 |
|
| // }}} |
| 241 |
|
| // int inner_all_any(struct point *lps, struct point *rps, struct point *op1, struct point *op2, int strategy) {{{ |
| 242 |
0 |
| int inner_all_any(struct point *lps, struct point *rps, struct point *op1, struct point *op2, int strategy) { |
| 243 |
|
| int i,j,k; |
| 244 |
|
| int l,r,o; |
| 245 |
|
| int blocked; |
| 246 |
0 |
| int c = 0; |
| 247 |
|
| |
| 248 |
0 |
| l=lps[0].m; r=rps[0].m; o=op1[0].m; |
| 249 |
|
| |
| 250 |
0 |
▶ | if( strategy ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( strategy ) { |
0 |
0 |
0 |
|
| 251 |
0 |
▶ | for(j=0; j<=r; j++) { c=0; |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0; j<=r; j++) { c=0; |
0 |
0 |
0 |
|
| 252 |
0 |
▶ | for(i=0; i<=l; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<=l; i++) { |
0 |
0 |
0 |
|
| 253 |
0 |
| blocked = 0; |
| 254 |
0 |
▶ | for(k=0; k<=o; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=0; k<=o; k++) { |
0 |
0 |
0 |
|
| 255 |
0 |
▶ | if( intersect(op1[k], op2[k], lps[i], rps[j]) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( intersect(op1[k], op2[k], lps[i], rps[j]) ) { |
0 |
0 |
0 |
|
| 256 |
0 |
| blocked ++; |
| 257 |
0 |
| break; |
| 258 |
|
| } |
| 259 |
|
| } |
| 260 |
|
| |
| 261 |
0 |
▶ | if( !blocked ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( !blocked ) |
0 |
0 |
0 |
|
| 262 |
0 |
| c++; |
| 263 |
|
| } |
| 264 |
|
| |
| 265 |
0 |
▶ | if( c==j ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( c==j ) |
0 |
0 |
0 |
|
| 266 |
0 |
| return 1; |
| 267 |
|
| } |
| 268 |
|
| |
| 269 |
|
| } else { |
| 270 |
0 |
▶ | for(j=0; j<=r; j++) { c=0; |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0; j<=r; j++) { c=0; |
0 |
0 |
0 |
|
| 271 |
0 |
▶ | for(i=0; i<=l; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<=l; i++) { |
0 |
0 |
0 |
|
| 272 |
0 |
| blocked = 0; |
| 273 |
0 |
▶ | for(k=0; k<=o; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=0; k<=o; k++) { |
0 |
0 |
0 |
|
| 274 |
0 |
▶ | if( intersect(op1[k], op2[k], lps[i], rps[j]) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( intersect(op1[k], op2[k], lps[i], rps[j]) ) { |
0 |
0 |
0 |
|
| 275 |
0 |
| blocked ++; |
| 276 |
0 |
| break; |
| 277 |
|
| } |
| 278 |
|
| } |
| 279 |
|
| |
| 280 |
0 |
▶ | if( blocked ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( blocked ) |
0 |
0 |
0 |
|
| 281 |
0 |
| c++; |
| 282 |
|
| } |
| 283 |
|
| |
| 284 |
0 |
▶ | if( c==j ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( c==j ) |
0 |
0 |
0 |
|
| 285 |
0 |
| return 1; |
| 286 |
|
| } |
| 287 |
|
| } |
| 288 |
|
| |
| 289 |
0 |
| return 0; |
| 290 |
|
| } |
| 291 |
|
| // }}} |
| 292 |
|
| // int inner_all_all(struct point *lps, struct point *rps, struct point *op1, struct point *op2, int strategy) {{{ |
| 293 |
0 |
| int inner_all_all(struct point *lps, struct point *rps, struct point *op1, struct point *op2, int strategy) { |
| 294 |
|
| int i,j,k; |
| 295 |
|
| int l,r,o; |
| 296 |
|
| int blocked; |
| 297 |
|
| |
| 298 |
0 |
| l=lps[0].m; r=rps[0].m; o=op1[0].m; |
| 299 |
|
| |
| 300 |
0 |
▶ | if( strategy ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( strategy ) { |
0 |
0 |
0 |
|
| 301 |
0 |
▶ | for(i=0; i<=l; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<=l; i++) { |
0 |
0 |
0 |
|
| 302 |
0 |
▶ | for(j=0; j<=r; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0; j<=r; j++) { |
0 |
0 |
0 |
|
| 303 |
0 |
▶ | for(k=0; k<=o; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=0; k<=o; k++) { |
0 |
0 |
0 |
|
| 304 |
0 |
▶ | if( intersect(op1[k], op2[k], lps[i], rps[j]) ) |
Branch: 1 branch
| Branch | True | False | Total |
| if( intersect(op1[k], op2[k], lps[i], rps[j]) ) |
0 |
0 |
0 |
|
| 305 |
0 |
| return 0; // if any one segment blocks any rhs (or lhs) ... 0!! |
| 306 |
|
| } |
| 307 |
|
| } |
| 308 |
|
| } |
| 309 |
|
| |
| 310 |
|
| } else { |
| 311 |
0 |
▶ | for(i=0; i<=l; i++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<=l; i++) { |
0 |
0 |
0 |
|
| 312 |
0 |
▶ | for(j=0; j<=r; j++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0; j<=r; j++) { |
0 |
0 |
0 |
|
| 313 |
0 |
| blocked = 0; |
| 314 |
0 |
▶ | for(k=0; k<=o; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=0; k<=o; k++) { |
0 |
0 |
0 |
|
| 315 |
0 |
▶ | if( intersect(op1[k], op2[k], lps[i], rps[j]) ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( intersect(op1[k], op2[k], lps[i], rps[j]) ) { |
0 |
0 |
0 |
|
| 316 |
0 |
| blocked = 1; // here though, we can mis one or two |
| 317 |
0 |
| break; |
| 318 |
|
| } |
| 319 |
|
| } |
| 320 |
|
| |
| 321 |
0 |
▶ | if( !blocked ) // as long as each lhs and rhs are blocked by something |
Branch: 1 branch
| Branch | True | False | Total |
| if( !blocked ) // as long as each lhs and rhs are blocked by something |
0 |
0 |
0 |
|
| 322 |
0 |
| return 0; |
| 323 |
|
| } |
| 324 |
|
| } |
| 325 |
|
| } |
| 326 |
|
| |
| 327 |
0 |
| return 1; |
| 328 |
|
| } |
| 329 |
|
| // }}} |
| 330 |
|
| // int std_loop(SV *sv_lhs, SV*sv_rhs, SV*sv_ods, int strategy) {{{ |
| 331 |
0 |
| int std_loop(SV *sv_lhs, SV*sv_rhs, SV*sv_ods, int strategy) { |
| 332 |
|
| AV *lhs, *rhs, *ods; |
| 333 |
|
| int l,r,o; |
| 334 |
|
| int i,j,k; |
| 335 |
|
| |
| 336 |
|
| struct point *lps, *rps, *op1, *op2; |
| 337 |
|
| AV *t1,*t2; |
| 338 |
|
| |
| 339 |
0 |
| int ret = -1; |
| 340 |
|
| |
| 341 |
|
| // fprintf(stderr, "beg std_loop(strategy=%d)\n", strategy); |
| 342 |
|
| |
| 343 |
0 |
▶ | if ((!SvROK(sv_lhs)) || (SvTYPE(lhs = (AV*)SvRV(sv_lhs)) != SVt_PVAV)) croak("first argument to _std_intersect_loop() isn't an arrayref"); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((!SvROK(sv_lhs)) || (SvTYPE(lhs = (AV*)SvRV(sv_lhs)) != SVt_PVAV)) croak("first argument to _std_intersect_loop() isn't an arrayref"); |
0 |
0 |
0 |
| if ((!SvROK(sv_lhs)) || (SvTYPE(lhs = (AV*)SvRV(sv_lhs)) != SVt_PVAV)) croak("first argument to _std_intersect_loop() isn't an arrayref"); |
0 |
0 |
0 |
|
| 344 |
0 |
▶ | if ((!SvROK(sv_rhs)) || (SvTYPE(rhs = (AV*)SvRV(sv_rhs)) != SVt_PVAV)) croak("second argument to _std_intersect_loop() isn't an arrayref"); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((!SvROK(sv_rhs)) || (SvTYPE(rhs = (AV*)SvRV(sv_rhs)) != SVt_PVAV)) croak("second argument to _std_intersect_loop() isn't an arrayref"); |
0 |
0 |
0 |
| if ((!SvROK(sv_rhs)) || (SvTYPE(rhs = (AV*)SvRV(sv_rhs)) != SVt_PVAV)) croak("second argument to _std_intersect_loop() isn't an arrayref"); |
0 |
0 |
0 |
|
| 345 |
0 |
▶ | if ((!SvROK(sv_ods)) || (SvTYPE(ods = (AV*)SvRV(sv_ods)) != SVt_PVAV)) croak("third argument to _std_intersect_loop() isn't an arrayref"); |
Branch: 2 branches
| Branch | True | False | Total |
| if ((!SvROK(sv_ods)) || (SvTYPE(ods = (AV*)SvRV(sv_ods)) != SVt_PVAV)) croak("third argument to _std_intersect_loop() isn't an arrayref"); |
0 |
0 |
0 |
| if ((!SvROK(sv_ods)) || (SvTYPE(ods = (AV*)SvRV(sv_ods)) != SVt_PVAV)) croak("third argument to _std_intersect_loop() isn't an arrayref"); |
0 |
0 |
0 |
|
| 346 |
|
| |
| 347 |
0 |
| l = av_len(lhs); r = av_len(rhs); o = av_len(ods); |
| 348 |
|
| |
| 349 |
0 |
▶ | if( l<0 || r<0 ) croak("the lhs and rhs arrays must have locations in them"); |
Branch: 2 branches
| Branch | True | False | Total |
| if( l<0 || r<0 ) croak("the lhs and rhs arrays must have locations in them"); |
0 |
0 |
0 |
| if( l<0 || r<0 ) croak("the lhs and rhs arrays must have locations in them"); |
0 |
0 |
0 |
|
| 350 |
|
| |
| 351 |
0 |
▶ | if( o>=0 ) { |
Branch: 1 branch
| Branch | True | False | Total |
| if( o>=0 ) { |
0 |
0 |
0 |
|
| 352 |
0 |
| lps = calloc(l+1, sizeof(struct point)); rps = calloc(r+1, sizeof(struct point)); |
| 353 |
0 |
| op1 = calloc(o+1, sizeof(struct point)); op2 = calloc(o+1, sizeof(struct point)); |
| 354 |
|
| |
| 355 |
0 |
| lps[0].m = l; rps[0].m = r; op1[0].m = o; |
| 356 |
|
| |
| 357 |
0 |
▶ | for(i=0; i<=l; i++) { t1 = av_fwc(lhs,i); lps[i].x = X(t1); lps[i].y = Y(t1); } |
Branch: 1 branch
| Branch | True | False | Total |
| for(i=0; i<=l; i++) { t1 = av_fwc(lhs,i); lps[i].x = X(t1); lps[i].y = Y(t1); } |
0 |
0 |
0 |
|
| 358 |
0 |
▶ | for(j=0; j<=r; j++) { t1 = av_fwc(rhs,j); rps[j].x = X(t1); rps[j].y = Y(t1); } |
Branch: 1 branch
| Branch | True | False | Total |
| for(j=0; j<=r; j++) { t1 = av_fwc(rhs,j); rps[j].x = X(t1); rps[j].y = Y(t1); } |
0 |
0 |
0 |
|
| 359 |
0 |
▶ | for(k=0; k<=o; k++) { |
Branch: 1 branch
| Branch | True | False | Total |
| for(k=0; k<=o; k++) { |
0 |
0 |
0 |
|
| 360 |
0 |
| t1 = (AV *)SvRV(*av_fetch(ods,k,0)); |
| 361 |
0 |
| t2 = av_fwc(t1,0); op1[k].x = X(t2); op1[k].y = Y(t2); |
| 362 |
0 |
| t2 = av_fwc(t1,1); op2[k].x = X(t2); op2[k].y = Y(t2); |
| 363 |
|
| } |
| 364 |
|
| |
| 365 |
|
| // printf("SET\n"); |
| 366 |
|
| // for(i=0; i<=l; i++) { printf("[%f,%f]\n", lps[i].x, lps[i].y); } |
| 367 |
|
| // for(j=0; j<=l; j++) { printf("[%f,%f]\n", rps[j].x, rps[j].y); } |
| 368 |
|
| // printf("DONE\n"); |
| 369 |
|
| |
| 370 |
|
| // fprintf(stderr, "\e[1;30m strategy=%d \e[m", strategy); |
| 371 |
|
| |
| 372 |
0 |
▶ | if( strategy & ALL_RHS && strategy & ALL_LHS ) { |
Branch: 2 branches
| Branch | True | False | Total |
| if( strategy & ALL_RHS && strategy & ALL_LHS ) { |
0 |
0 |
0 |
| if( strategy & ALL_RHS && strategy & ALL_LHS ) { |
0 |
0 |
0 |
|
| 373 |
0 |
| ret = inner_all_all(lps,rps,op1,op2, strategy & LOS); |
| 374 |
|
| |
| 375 |
0 |
▶ | } else if( strategy & ALL_LHS ) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if( strategy & ALL_LHS ) { |
0 |
0 |
0 |
|
| 376 |
0 |
| ret = inner_all_any(lps,rps,op1,op2, strategy & LOS); |
| 377 |
|
| |
| 378 |
0 |
▶ | } else if( strategy & ALL_RHS ) { |
Branch: 1 branch
| Branch | True | False | Total |
| } else if( strategy & ALL_RHS ) { |
0 |
0 |
0 |
|
| 379 |
0 |
| ret = inner_any_all(lps,rps,op1,op2, strategy & LOS); |
| 380 |
|
| |
| 381 |
|
| } else { |
| 382 |
0 |
| ret = inner_any_any(lps,rps,op1,op2, strategy & LOS); |
| 383 |
|
| } |
| 384 |
|
| |
| 385 |
0 |
| free(lps); free(rps); free(op1); free(op2); |
| 386 |
|
| |
| 387 |
|
| } else { |
| 388 |
0 |
| ret = (strategy & LOS ) ? 1:0; |
| 389 |
|
| } |
| 390 |
|
| |
| 391 |
0 |
| return ret; |
| 392 |
|
| } |
| 393 |
|
| // }}} |
| 394 |
|
| |
| 395 |
|
| MODULE = Games::RolePlay::MapGen PACKAGE = Games::RolePlay::MapGen::MapQueue |
| 396 |
|
| PROTOTYPES: ENABLE |
| 397 |
|
| |
| 398 |
|
| int |
| 399 |
|
| any_any_intersect_loop(sv_lhs,sv_rhs,sv_ods) |
| 400 |
|
| SV *sv_lhs |
| 401 |
|
| SV *sv_rhs |
| 402 |
|
| SV *sv_ods |
| 403 |
|
| |
| 404 |
|
| CODE: |
| 405 |
0 |
| RETVAL = std_loop(sv_lhs,sv_rhs,sv_ods,0); |
| 406 |
|
| |
| 407 |
|
| OUTPUT: |
| 408 |
|
| RETVAL |
| 409 |
|
| |
| 410 |
|
| int |
| 411 |
|
| any_any_los_loop(sv_lhs,sv_rhs,sv_ods) |
| 412 |
|
| SV *sv_lhs |
| 413 |
|
| SV *sv_rhs |
| 414 |
|
| SV *sv_ods |
| 415 |
|
| |
| 416 |
|
| CODE: |
| 417 |
0 |
| RETVAL = std_loop(sv_lhs,sv_rhs,sv_ods,LOS); |
| 418 |
|
| |
| 419 |
|
| OUTPUT: |
| 420 |
|
| RETVAL |
| 421 |
|
| |
| 422 |
|
| int |
| 423 |
|
| any_all_intersect_loop(sv_lhs,sv_rhs,sv_ods) |
| 424 |
|
| SV *sv_lhs |
| 425 |
|
| SV *sv_rhs |
| 426 |
|
| SV *sv_ods |
| 427 |
|
| |
| 428 |
|
| CODE: |
| 429 |
0 |
| RETVAL = std_loop(sv_lhs,sv_rhs,sv_ods,ALL_RHS); |
| 430 |
|
| |
| 431 |
|
| OUTPUT: |
| 432 |
|
| RETVAL |
| 433 |
|
| |
| 434 |
|
| int |
| 435 |
|
| any_all_los_loop(sv_lhs,sv_rhs,sv_ods) |
| 436 |
|
| SV *sv_lhs |
| 437 |
|
| SV *sv_rhs |
| 438 |
|
| SV *sv_ods |
| 439 |
|
| |
| 440 |
|
| CODE: |
| 441 |
0 |
| RETVAL = std_loop(sv_lhs,sv_rhs,sv_ods,ALL_RHS+LOS); |
| 442 |
|
| |
| 443 |
|
| OUTPUT: |
| 444 |
|
| RETVAL |
| 445 |
|
| |
| 446 |
|
| int |
| 447 |
|
| all_any_intersect_loop(sv_lhs,sv_rhs,sv_ods) |
| 448 |
|
| SV *sv_lhs |
| 449 |
|
| SV *sv_rhs |
| 450 |
|
| SV *sv_ods |
| 451 |
|
| |
| 452 |
|
| CODE: |
| 453 |
0 |
| RETVAL = std_loop(sv_lhs,sv_rhs,sv_ods,ALL_LHS); |
| 454 |
|
| |
| 455 |
|
| OUTPUT: |
| 456 |
|
| RETVAL |
| 457 |
|
| |
| 458 |
|
| int |
| 459 |
|
| all_any_los_loop(sv_lhs,sv_rhs,sv_ods) |
| 460 |
|
| SV *sv_lhs |
| 461 |
|
| SV *sv_rhs |
| 462 |
|
| SV *sv_ods |
| 463 |
|
| |
| 464 |
|
| CODE: |
| 465 |
0 |
| RETVAL = std_loop(sv_lhs,sv_rhs,sv_ods,ALL_LHS+LOS); |
| 466 |
|
| |
| 467 |
|
| OUTPUT: |
| 468 |
|
| RETVAL |
| 469 |
|
| |
| 470 |
|
| int |
| 471 |
|
| all_all_intersect_loop(sv_lhs,sv_rhs,sv_ods) |
| 472 |
|
| SV *sv_lhs |
| 473 |
|
| SV *sv_rhs |
| 474 |
|
| SV *sv_ods |
| 475 |
|
| |
| 476 |
|
| CODE: |
| 477 |
0 |
| RETVAL = std_loop(sv_lhs,sv_rhs,sv_ods,ALL_RHS+ALL_LHS); |
| 478 |
|
| |
| 479 |
|
| OUTPUT: |
| 480 |
|
| RETVAL |
| 481 |
|
| |
| 482 |
|
| int |
| 483 |
|
| all_all_los_loop(sv_lhs,sv_rhs,sv_ods) |
| 484 |
|
| SV *sv_lhs |
| 485 |
|
| SV *sv_rhs |
| 486 |
|
| SV *sv_ods |
| 487 |
|
| |
| 488 |
|
| CODE: |
| 489 |
0 |
| RETVAL = std_loop(sv_lhs,sv_rhs,sv_ods,ALL_RHS+ALL_LHS+LOS); |
| 490 |
|
| |
| 491 |
|
| OUTPUT: |
| 492 |
|
| RETVAL |