diff --git a/Units/MMLAddon/PSInc/Wrappers/tpa.inc b/Units/MMLAddon/PSInc/Wrappers/tpa.inc index f8ef974..c35a0a3 100644 --- a/Units/MMLAddon/PSInc/Wrappers/tpa.inc +++ b/Units/MMLAddon/PSInc/Wrappers/tpa.inc @@ -143,16 +143,6 @@ begin FilterPointsLine(points,radial,radius,mx,my); end; -procedure ps_FilterTPACustom(TPA: TPointArray; compare: function(a, b: integer): boolean); -begin - FilterTPACustom(TPA, @compare); -end; - -procedure ps_FilterTPADistEx(var TPA: TPointArray; maxL, maxW: integer); -begin - FilterTPADistEx(TPA, maxL, maxW); -end; - procedure ps_FilterTPADist(var TPA: TPointArray; maxDist: integer); begin FilterTPADist(TPA, maxDist); diff --git a/Units/MMLAddon/PSInc/psexportedmethods.inc b/Units/MMLAddon/PSInc/psexportedmethods.inc index 3c82ba0..42b7b3c 100644 --- a/Units/MMLAddon/PSInc/psexportedmethods.inc +++ b/Units/MMLAddon/PSInc/psexportedmethods.inc @@ -458,8 +458,6 @@ AddFunction(@ps_FloodFillTPA,'function FloodFillTPA(const TPA : TPointArray) : T AddFunction(@ps_FilterPointsPie,'procedure FilterPointsPie(var Points: TPointArray; const SD, ED, MinR, MaxR: Extended; Mx, My: Integer);'); AddFunction(@ps_FilterPointsLine,'procedure FilterPointsLine(var Points: TPointArray; Radial: Extended; Radius, MX, MY: Integer);'); AddFunction(@ps_filterpointsdist,'procedure FilterPointsDist(var Points: TPointArray; const MinDist, MaxDist: Extended; Mx, My: Integer);'); -AddFunction(@ps_filterTPACustom, 'procedure FilterTPACustom(var TPA: TPointArray; compare: function(a, b: integer): boolean);'); -AddFunction(@ps_filterTPADistEx, 'procedure FilterTPADistEx(var TPA: TPointArray; maxL, maxW: integer);'); AddFunction(@ps_filterTPADist, 'procedure FilterTPADist(var TPA: TPointArray; maxDist: integer);'); AddFunction(@ps_GetATPABounds,'function GetATPABounds(const ATPA: T2DPointArray): TBox;'); AddFunction(@ps_GetTPABounds,'function GetTPABounds(const TPA: TPointArray): TBox;'); diff --git a/Units/MMLCore/tpa.pas b/Units/MMLCore/tpa.pas index bded283..ea6b6c9 100644 --- a/Units/MMLCore/tpa.pas +++ b/Units/MMLCore/tpa.pas @@ -67,8 +67,6 @@ function FloodFillTPA(const TPA : TPointArray) : T2DPointArray; procedure FilterPointsPie(var Points: TPointArray; const SD, ED, MinR, MaxR: Extended; Mx, My: Integer); procedure FilterPointsDist(var Points: TPointArray; const MinDist,MaxDist: Extended; Mx, My: Integer); procedure FilterPointsLine(var Points: TPointArray; Radial: Extended; Radius, MX, MY: Integer); -procedure FilterTPACustom(var TPA: TPointArray; compare: function(a, b: integer): boolean); -procedure FilterTPADistEx(var TPA: TPointArray; maxL, maxW: integer); procedure FilterTPADist(var TPA: TPointArray; maxDist: integer); function RemoveDistTPointArray(x, y, dist: Integer;const ThePoints: TPointArray; RemoveHigher: Boolean): TPointArray; function GetATPABounds(const ATPA: T2DPointArray): TBox; @@ -1172,36 +1170,37 @@ begin end; {/\ - Removes points in the TPA using the funciton 'compare'. If 'compare' returns - true, point b is removed from the TPA. + Removes points in the TPA that are within maxDist of each other. /\} -procedure FilterTPACustom(TPA: TPointArray; compare: function(a, b: integer): boolean); +procedure FilterTPADist(var TPA: TPointArray; maxDist: integer); var - c, i, j, l, h: integer; + c, i, j, l, h, maxDistSq: integer; newTPA: TPointArray; inBadElements: TBooleanArray; begin h := high(TPA); - l := (h + 1); // i.e. length(TPA); + l := (h + 1); + maxDistSq := (maxDist * maxDist); setLength(inBadElements, l); setLength(newTPA, l); for i := 0 to h do - inBadElements[i] := false; // just in case.. + inBadElements[i] := false; for i := 0 to (h - 1) do begin - if (inBadElements[i]) then // increases speed significantly + if (inBadElements[i]) then continue; for j := (i + 1) to h do begin - if (inBadElements[j]) then // increases speed significantly + if (inBadElements[j]) then continue; - if (compare(TPA[i], TPA[j])) then - inBadElements[j] := true; + // simplified -> a^2 + b^2 <= c^2 + if (((TPA[i].x - TPA[j].x) * (TPA[i].x - TPA[j].x)) + ((TPA[i].y - TPA[j].y) * (TPA[i].y - TPA[j].y)) <= maxDistSq) then + inBadElements[j] := true; end; end; @@ -1219,30 +1218,6 @@ begin TPA := newTPA; end; -{/\ - Removes points in the TPA that are within maxL or maxW of each other. -/\} -procedure FilterTPADistEx(var TPA: TPointArray; maxL, maxW: integer); -function lwComp(a,b: TPoint): Boolean; -begin - result := (abs(a.x-b.x) <= maxW) or (abs(a.y-b.y) <= maxL); // lambda would be nice.. -end; -begin - FilterTPACustom(TPA, @lwComp); -end; - -{/\ - Removes points in the TPA that are within 'maxDist' of each other. -/\} -procedure FilterTPADist(var TPA: TPointArray; maxDist: integer); -function distComp(a, b: TPoint): boolean; -begin - result := (((a.x-b.x)*(a.x-b.x)) + ((a.y-b.y)*(a.y-b.y)) <= (maxDist*maxDist)); -end; -begin - FilterTPACustom(TPA, @distComp); -end; - {/\ Removes the points that are inside or outside the distance Dist from the point (x, y) from the TPointArray ThePoints. /\}