Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function TPADistanceToPt(TPA: TPointArray; p: TPoint; method: (dtpClosest, dtpFarthest)): Integer;
- var
- h, i, d: Integer;
- begin
- Result := -1;
- h := High(TPA);
- if (h < 0) then
- Exit;
- Result := Distance(TPA[i].X, TPA[i].Y, p.X, p.Y);
- if (h > 0) then
- case method of
- dtpClosest:
- for i := 1 to h do
- begin
- d := Distance(TPA[i].X, TPA[i].Y, p.X, p.Y);
- if (d < Result) then
- Result := d;
- end;
- dtpFarthest:
- for i := 1 to h do
- begin
- d := Distance(TPA[i].X, TPA[i].Y, p.X, p.Y);
- if (d > Result) then
- Result := d;
- end;
- end;
- end;
- function TPADistanceToPtEx(TPA: TPointArray; p: TPoint; method: (dtpClosest, dtpFarthest); var m_pt: TPoint): Integer;
- var
- h, i, d: Integer;
- begin
- Result := -1;
- h := High(TPA);
- if (h < 0) then
- Exit;
- Result := Distance(TPA[i].X, TPA[i].Y, p.X, p.Y);
- if (h > 0) then
- case method of
- dtpClosest:
- for i := 1 to h do
- begin
- d := Distance(TPA[i].X, TPA[i].Y, p.X, p.Y);
- if (d < Result) then
- begin
- Result := d;
- m_pt := TPA[i];
- end;
- end;
- dtpFarthest:
- for i := 1 to h do
- begin
- d := Distance(TPA[i].X, TPA[i].Y, p.X, p.Y);
- if (d > Result) then
- begin
- Result := d;
- m_pt := TPA[i];
- end;
- end;
- end;
- end;
- function TPADistanceToPtEx2(TPA: TPointArray; p: TPoint; method: (dtpClosest, dtpFarthest); var m_pts: TPointArray): Integer;
- var
- h, i, d, r: Integer;
- begin
- Result := -1;
- h := High(TPA);
- if (h < 0) then
- Exit;
- Result := Distance(TPA[i].X, TPA[i].Y, p.X, p.Y);
- SetLength(m_pts, (h + 1));
- m_pts[i] := TPA[i];
- if (h > 0) then
- begin
- case method of
- dtpClosest:
- for i := 1 to h do
- begin
- d := Distance(TPA[i].X, TPA[i].Y, p.X, p.Y);
- if (d <= Result) then
- begin
- if (d < Result) then
- begin
- Result := d;
- r := 0;
- end;
- m_pts[r] := TPA[i];
- Inc(r);
- end;
- end;
- dtpFarthest:
- for i := 1 to h do
- begin
- d := Distance(TPA[i].X, TPA[i].Y, p.X, p.Y);
- if (d >= Result) then
- begin
- if (d > Result) then
- begin
- Result := d;
- r := 0;
- end;
- m_pts[r] := TPA[i];
- Inc(r);
- end;
- end;
- end;
- SetLength(m_pts, r);
- end;
- end;
- var
- t: Integer;
- cPt, mPt: TPoint;
- TPA, mTPA: TPointArray;
- begin
- ClearDebug;
- TPA := TPAFromBox(Box(0, 0, 250, 250));
- cPt := TPACenter(TPA);
- TPARemove(TPA, cPt);
- t := GetSystemTime;
- WriteLn('TPADistanceToPt [closest]: ' + IntToStr(TPADistanceToPt(TPA, cPt, dtpClosest)) + ' - ' + IntToStr(GetSystemTime - t) + ' ms.');
- t := GetSystemTime;
- WriteLn('TPADistanceToPt [farthest]: ' + IntToStr(TPADistanceToPt(TPA, cPt, dtpFarthest)) + ' - ' + IntToStr(GetSystemTime - t) + ' ms.');
- t := GetSystemTime;
- WriteLn('TPADistanceToPtEx [closest]:' + IntToStr(TPADistanceToPtEx(TPA, cPt, dtpClosest, mPt)) + ' - ' + IntToStr(GetSystemTime - t) + ' ms.');
- t := GetSystemTime;
- WriteLn('TPADistanceToPtEx [farthest]: ' + IntToStr(TPADistanceToPtEx(TPA, cPt, dtpFarthest, mPt)) + ' - ' + IntToStr(GetSystemTime - t) + ' ms.');
- t := GetSystemTime;
- WriteLn('TPADistanceToPtEx2 [closest]: ' + IntToStr(TPADistanceToPtEx2(TPA, cPt, dtpClosest, mTPA)) + ' - ' + IntToStr(GetSystemTime - t) + ' ms.');
- t := GetSystemTime;
- WriteLn('TPADistanceToPtEx2 [farthest]: ' + IntToStr(TPADistanceToPtEx2(TPA, cPt, dtpFarthest, mTPA)) + ' - ' + IntToStr(GetSystemTime - t) + ' ms.');
- SetLength(TPA, 0);
- SetLength(mTPA, 0);
- end.
Advertisement
Add Comment
Please, Sign In to add comment