Changeset 124 for abuse/trunk/src/intsect.cpp
 Timestamp:
 Mar 18, 2008, 9:36:56 PM (15 years ago)
 File:

 1 edited
Legend:
 Unmodified
 Added
 Removed

abuse/trunk/src/intsect.cpp
r56 r124 15 15 16 16 void pushback(int32_t x1,int32_t y1,int32_t &x2,int32_t &y2, 17 17 int32_t xp1, int32_t yp1, int32_t xp2, int32_t yp2, int xdir, int ydir, int inside) 18 18 { 19 19 … … 23 23 // { 24 24 // if (inside && y2>=yp1) 25 25 26 26 } 27 27 28 28 29 29 /* int setback_intersect(int32_t x1,int32_t y1,int32_t &x2,int32_t &y2, 30 30 int32_t xp1, int32_t yp1, int32_t xp2, int32_t yp2) 31 31 { 32 32 int32_t mx1,my1,b1,mx2,my2,b2,side1,side2,tx2,ty2; … … 45 45 { 46 46 side1=xp1x1; 47 side2=xp2x2; 47 side2=xp2x2; 48 48 } else 49 49 { 50 50 b1=y1(my1*x1/mx1); // calculate the y intercept 51 side1=yp1((my1*xp1)/mx1+b1); 52 side2=yp2((my1*xp2)/mx1+b1); 51 side1=yp1((my1*xp1)/mx1+b1); 52 side2=yp2((my1*xp2)/mx1+b1); 53 53 } 54 54 } … … 68 68 if (!mx2) 69 69 { 70 71 70 side1=x1xp2; 71 side2=x2xp2; 72 72 } else 73 73 { 74 75 76 74 b2=yp1(my2*xp1/mx2); 75 side1=y1((my2*x1)/mx2+b2); 76 side2=y2((my2*x2)/mx2+b2); 77 77 } 78 78 } 79 79 80 80 // check two wierd cases where the lines are parallel 81 if (mx1==mx2 && mx1==0) 81 if (mx1==mx2 && mx1==0) 82 82 if (y2<yp1  y1>yp2) 83 side1=side2=1; 83 side1=side2=1; 84 84 else side1=side2=0; 85 85 … … 95 95 if (x1>x2) xadd=1; else if (x1<x2) xadd=1; else xadd=0; 96 96 if (y1>y2) yadd=1; else if (y1<y2) yadd=1; else yadd=0; 97 97 98 98 // now find the point of intersection 99 99 if (mx1==0) // if the first line is strait up & down 100 { 101 102 100 { 101 if (mx2==0) // if they are both strait up then 102 { tx2=x1; ty2=y1; } // they connect everywhere, don't let it move! 103 103 else 104 ty2=my2*x2/mx2+b2+yadd; 104 ty2=my2*x2/mx2+b2+yadd; 105 105 } else if (mx2==0) 106 106 { tx2=xp1+xadd; … … 114 114 else tx2=mx2*(y1b2)/my2+xadd; 115 115 else if (my2==0) 116 { 116 { 117 117 ty2=yp1+yadd; 118 tx2=mx1*(ty2b1)/my1; 119 } 120 else 118 tx2=mx1*(ty2b1)/my1; 119 } 120 else 121 121 { 122 122 if (abs(mx1)>abs(my1)) … … 137 137 } 138 138 139 if (abs(tx2x1)<abs(x2x1)  abs(ty2y1)<abs(y2y1)) 139 if (abs(tx2x1)<abs(x2x1)  abs(ty2y1)<abs(y2y1)) 140 140 { 141 141 x2=tx2; 142 142 y2=ty2; 143 143 return 1; 144 } 145 } 146 } 147 return 0; 144 } 145 } 146 } 147 return 0; 148 148 } */ 149 149 150 150 151 151 int setback_intersect(int32_t x1,int32_t y1,int32_t &x2,int32_t &y2, 152 int32_t xp1, int32_t yp1, int32_t xp2, int32_t yp2, 152 int32_t xp1, int32_t yp1, int32_t xp2, int32_t yp2, 153 153 int32_t inside) // which side is inside the polygon? (0 always setback) 154 154 { 155 155 // the line equations will be put in the form 156 156 // x(y2y1)+y(x1x2)x1*y2+x2*y1=0 157 // A B C 158 159 int32_t a1,b1,c1,a2,b2,c2,r1,r2; 160 161 a1=y2y1; 162 b1=x1x2; 163 c1=x1*y2+x2*y1; 157 // A B C 158 159 int32_t a1,b1,c1,a2,b2,c2,r1,r2; 160 161 a1=y2y1; 162 b1=x1x2; 163 c1=x1*y2+x2*y1; 164 164 165 165 if (yp1<yp2  (yp1==yp2 && xp1>xp2)) // use only increasing functions 166 { 166 { 167 167 r1=yp1; yp1=yp2; yp2=r1; // swap endpoints if wrong order 168 168 r1=xp1; xp1=xp2; xp2=r1; 169 } 169 } 170 170 171 171 int32_t xdiff,ydiff; 172 /* int32_t xdiff=abs(xp1xp2),ydiff=yp1yp2; 173 if (xdiff>=ydiff) // increment the endpoints 174 if (xp2<xp1) { xp2; xp1++; } 175 else { xp2++; xp1; } 176 172 /* int32_t xdiff=abs(xp1xp2),ydiff=yp1yp2; 173 if (xdiff>=ydiff) // increment the endpoints 174 if (xp2<xp1) { xp2; xp1++; } 175 else { xp2++; xp1; } 176 177 177 if (xdiff<=ydiff) 178 178 { 179 yp1++; 179 yp1++; 180 180 yp2; 181 181 } */ 182 182 183 183 184 184 r1=xp1*a1+yp1*b1+c1; … … 187 187 if ((r1^r2)<=0  r1==0  r2==0) // signs must be different to intersect 188 188 { 189 a2=yp2yp1; 190 b2=xp1xp2; 191 c2=xp1*yp2+xp2*yp1; 189 a2=yp2yp1; 190 b2=xp1xp2; 191 c2=xp1*yp2+xp2*yp1; 192 192 r1=x1*a2+y1*b2+c2; 193 193 r2=x2*a2+y2*b2+c2; … … 195 195 if ((r1^r2)<=0  r1==0  r2==0) 196 196 { 197 if ( ((xp1<xp2) && ((r2^inside)>0))  197 if ( ((xp1<xp2) && ((r2^inside)>0))  198 198 (xp1>=xp2 && ((r2^inside)<0))  199 inside==0  r2==0) 200 { 201 int32_t ae=a1*b2,bd=b1*a2; 202 203 204 205 y2=(a1*c2a2*c1)/(bdae);206 207 ydiff=abs(y2y1);208 // 209 // 210 211 {212 213 214 215 216 // }217 // 218 // 219 220 221 222 223 224 225 // 226 227 if (inside) // check to make sure end point is on the 228 229 r1=x1*a2+y1*b2+c2;230 r2=x2*a2+y2*b2+c2;231 232 {233 234 235 }236 } 237 return 1;238 239 } 240 } 241 } 199 inside==0  r2==0) 200 { 201 int32_t ae=a1*b2,bd=b1*a2; 202 if (ae!=bd) // colinear returns 0 203 { 204 x2=(b1*c2b2*c1)/(aebd); 205 y2=(a1*c2a2*c1)/(bdae); 206 xdiff=abs(x2x1); 207 ydiff=abs(y2y1); 208 // if (xdiff<=ydiff) // push the intersection back one pixel 209 // { 210 if (y2!=y1) 211 { 212 if (y2>y1) 213 y2; 214 else y2++; 215 } 216 // } 217 // if (xdiff>=ydiff) 218 // { 219 if (x2!=x1) 220 { 221 if (x2>x1) 222 x2; 223 else x2++; 224 } 225 // } 226 227 if (inside) // check to make sure end point is on the 228 { // right side 229 r1=x1*a2+y1*b2+c2; 230 r2=x2*a2+y2*b2+c2; 231 if ((r2!=0 && ((r1^r2)<0))) 232 { 233 x2=x1; 234 y2=y1; 235 } 236 } 237 return 1; 238 } 239 } 240 } 241 } 242 242 return 0; 243 243 244 244 } 245 245
Note: See TracChangeset
for help on using the changeset viewer.