1: 2: 3: 4: 5: 6: 7: 8: 9: 10: 11: 12: 13: 14: 15: 16: 17: 18: 19: 20: 21: 22: 23: 24: 25: 26: 27: 28: 29: 30: 31: 32: 33: 34: 35: 36: 37: 38: 39: 40: 41: 42: 43: 44: 45: 46: 47: 48: 49: 50: 51: 52: 53: 54: 55: 56: 57: 58: 59: 60: 61: 62: 63:
| function LineDistBelow(cX1,cY1,cX2,cY2,lX1,lY1,lX2,lY2,minDist:Integer): Boolean; var aY,bY,aX,bX,c1,c2,tmp,tmp2,sxf,syf,dx,dy,d,t:Double; PX,PY:Integer; begin aY := cY2-cY1; aX := cX1-cX2; bY := lY2-lY1; bX := lX1-lX2; c1 := aY*cX1 + aX*cY1; c2 := bY*lX1 + bX*lY1;
tmp:=(aY*bX-bY*aX); tmp2:=(c1*bX-c2*aX); if(tmp=0) then begin if(tmp2=0) then begin tmp:=(cX1-lX1)*(cX1-lX1)+(cY1-lY1)*(cY1-lY1); if(tmp<minDist) then exit(true); tmp:=(cX2-lX1)*(cX2-lX1)+(cY2-lY1)*(cY2-lY1); if(tmp<minDist) then exit(true); tmp:=(cX1-lX2)*(cX1-lX2)+(cY1-lY2)*(cY1-lY2); if(tmp<minDist) then exit(true); tmp:=(cX2-lX2)*(cX2-lX2)+(cY2-lY2)*(cY2-lY2); if(tmp<minDist) then exit(true); exit(false); end; d:=hypot(aX,aY); dx:=aX/d;dy:=aY/d; t:=(lX1-cX1)*dx+(lY1-cY1)*dy; dx:=cX1+t*dx; dy:=cY1+t*dy; exit((dx-lX1)*(dx-lX1)+(dy-lY1)*(dy-lY1)<minDist); end; sXf := tmp2/tmp; sYf := (aY*c2-bY*c1)/tmp; if (sXf > cX1) and (sXf > cX2) or (sXf < cX1) and (sXf < cX2) or (sYf > cY1) and (sYf > cY2) or (sYf < cY1) and (sYf < cY2) then begin tmp:=Round(sXf);tmp2:=Round(sYf); if(Abs(tmp-cX1)>Abs(tmp-cX2)) or (Abs(tmp2-cY1)>Abs(tmp2-cY2)) then begin PX:=cX2;PY:=cY2; end else begin PX:=cX1;PY:=cY1; end; Result:=(PointLineDist(lX1,lY1,lX2,lY2,PX,PY)<minDist); end else if(sXf > lX1) and (sXf > lX2) or (sXf < lX1) and (sXf < lX2) or (sYf > lY1) and (sYf > lY2) or (sYf < lY1) and (sYf < lY2) then begin tmp:=Round(sXf);tmp2:=Round(sYf); if(Abs(tmp-lX1)>Abs(tmp-lX2)) or (Abs(tmp2-lY1)>Abs(tmp2-lY2)) then begin PX:=lX2;PY:=lY2; end else begin PX:=lX1;PY:=lY1; end; Result:=(PointLineDist(cX1,cY1,cX2,cY2,PX,PY)<minDist); end else Result:=true; end; |