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
| function PointSurPolygone(const Pt : tPointD; TD : tTypeDessin; Poly: tAOPD): boolean;
const m = 5; // marge de tolérance
var nbPc,jp1 : integer;
function PointSurAutres(j1,j2 : integer) : boolean;
var j : integer;
begin for j:=j1 to j2 do begin
Result:=PointSurDroiteD(Poly[j-1],Poly[j], Pt, m);
if Result then Break;
end;
end;
begin Result:=False; nbPc:=length(Poly);
if ((TD=PolyGoneEtoile) or (TD=PolygoneER)) and (not odd(nbPc)) then
begin jp1:=(nbPc shr 1)-1;
if PointSurDroiteD(Poly[0],Poly[jp1], Pt, m) then begin Result:=True; EXIT; end;
Result:=PointSurAutres(1,jp1);
if Result then EXIT;
if PointSurDroiteD(Poly[jp1+1],Poly[High(Poly)], Pt, m) then begin
Result:=True; EXIT;
end;
Result:=PointSurAutres(jp1+2,High(Poly));
end else
begin if PointSurDroiteD(Poly[0], Poly[High(Poly)], Pt, m) then
begin Result:=True; EXIT; end;
Result:=PointSurAutres(1,High(Poly));
EXIT;
end;
end; // PointSurPolygone |
Partager