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
|
function detectligne(xs,ys : integer;table1:Ttable) : Extended;
var a, b, miEp, lg : Extended; dx,dy,yc : integer; okx,oky : boolean;
begin
Result:=-1;
miEp:=f1.tligne['Ep']/2;
dx:=f1.tligne['Xe'] -f1.tligne['X0'] ;
dy:=f1.tligne['Ye'] -f1.tligne['Y0'];
okx:=False; oky:=False;
if ((dy<0) and (ys<=f1.tligne['Y0']) and (ys>=f1.tligne['Ye']))or ((dy>0) and (ys<=f1.tligne['Ye']) and (ys>=f1.tligne['Y0'])) then oky:=True;
if ((dx>0) and (xs<=f1.tligne['Xe']) and (xs>=f1.tligne['X0']))or ((dx<0) and (xs<=f1.tligne['X0']) and (xs>=f1.tligne['Xe'])) then okx:=True;
if (dx=0) and (dy=0) then begin if (xs - miEp <=f1.tligne['X0']) and (f1.tligne['X0']<= xs + miEp)and (ys - miEp <=f1.tligne['Y0']) and (f1.tligne['Y0'] <= ys + miEp)then Result:=-maxInt; EXIT;end;
if (dx=0) then
begin if (xs - miEp <=f1.tligne['X0']) and (f1.tligne['X0'] <= xs + miEp)and oky then Result:=(ys - f1.tligne['Y0'])/dy;EXIT;end
else
if (dy=0) then
begin if (ys - miEp <=f1.tligne['Y0']) and (f1.tligne['Y0'] <= ys + miEp)and okx then Result:=(xs - f1.tligne['X0'])/dx;EXIT;end
else
begin
a:=dy/dx;
b:=f1.tligne['Y0'] - a*f1.tligne['X0'];
yc:=round(a*xs + b);
lg:=sqrt(dx*dx + dy*dy);
miEp:=abs(miEp*lg/dx);
if (yc + miEp >= ys) and (yc - miEp <= ys) and okx and oky then Result:=(xs - f1.tligne['X0'])/dx;
end;
end; |
Partager