diff --git a/Projects/Simba/Simba.lpi b/Projects/Simba/Simba.lpi index af46d9c..889e59c 100644 --- a/Projects/Simba/Simba.lpi +++ b/Projects/Simba/Simba.lpi @@ -44,7 +44,7 @@ - + @@ -304,6 +304,15 @@ + + + + + + + + + diff --git a/Projects/Simba/Simba.lpr b/Projects/Simba/Simba.lpr index ac13155..26c37db 100644 --- a/Projects/Simba/Simba.lpr +++ b/Projects/Simba/Simba.lpr @@ -33,7 +33,7 @@ uses {$ENDIF}{$ENDIF} Interfaces, Forms, SimbaUnit, colourhistory, About, internets, debugimage, framefunctionlist, simpleanalyzer, updater, updateform, Simbasettings, - libloader, mufasabase, v_ideCodeInsight, + libloader, mufasabase, tpa, v_ideCodeInsight, PSDump, v_ideCodeParser, v_AutoCompleteForm, CastaliaPasLex, CastaliaPasLexTypes, CastaliaSimplePasPar, CastaliaSimplePasParTypes, dcpbase64, mPasLex, v_Constants, v_MiscFunctions, diff --git a/Projects/Simba/Simba.res b/Projects/Simba/Simba.res index 42c7633..0087bd7 100644 Binary files a/Projects/Simba/Simba.res and b/Projects/Simba/Simba.res differ diff --git a/Units/MMLAddon/PSInc/Wrappers/tpa.inc b/Units/MMLAddon/PSInc/Wrappers/tpa.inc index 0c7c547..c35a0a3 100644 --- a/Units/MMLAddon/PSInc/Wrappers/tpa.inc +++ b/Units/MMLAddon/PSInc/Wrappers/tpa.inc @@ -143,6 +143,11 @@ begin FilterPointsLine(points,radial,radius,mx,my); end; +procedure ps_FilterTPADist(var TPA: TPointArray; maxDist: integer); +begin + FilterTPADist(TPA, maxDist); +end; + function ps_GetATPABounds(const ATPA: T2DPointArray): TBox;extdecl; begin result := GetATPABounds(ATPA); diff --git a/Units/MMLAddon/PSInc/psexportedmethods.inc b/Units/MMLAddon/PSInc/psexportedmethods.inc index 4dad21c..42b7b3c 100644 --- a/Units/MMLAddon/PSInc/psexportedmethods.inc +++ b/Units/MMLAddon/PSInc/psexportedmethods.inc @@ -458,6 +458,7 @@ 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_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;'); AddFunction(@ps_FindTPAinTPA,'function FindTPAinTPA(const SearchTPA, TotalTPA: TPointArray; var Matches: TPointArray): Boolean;'); diff --git a/Units/MMLCore/tpa.pas b/Units/MMLCore/tpa.pas index 9c0abae..ea6b6c9 100644 --- a/Units/MMLCore/tpa.pas +++ b/Units/MMLCore/tpa.pas @@ -67,6 +67,7 @@ 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 FilterTPADist(var TPA: TPointArray; maxDist: integer); function RemoveDistTPointArray(x, y, dist: Integer;const ThePoints: TPointArray; RemoveHigher: Boolean): TPointArray; function GetATPABounds(const ATPA: T2DPointArray): TBox; function GetTPABounds(const TPA: TPointArray): TBox; @@ -1168,6 +1169,55 @@ begin Points:= P; end; +{/\ + Removes points in the TPA that are within maxDist of each other. +/\} +procedure FilterTPADist(var TPA: TPointArray; maxDist: integer); +var + c, i, j, l, h, maxDistSq: integer; + newTPA: TPointArray; + inBadElements: TBooleanArray; +begin + h := high(TPA); + l := (h + 1); + maxDistSq := (maxDist * maxDist); + + setLength(inBadElements, l); + setLength(newTPA, l); + + for i := 0 to h do + inBadElements[i] := false; + + for i := 0 to (h - 1) do + begin + if (inBadElements[i]) then + continue; + + for j := (i + 1) to h do + begin + if (inBadElements[j]) then + continue; + + // 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; + + c := 0; + + // set the new TPA + for i := 0 to h do + if (not inBadElements[i]) then + begin + newTPA[c] := TPA[i]; + inc(c); + end; + + setLength(newTPA, c); + TPA := newTPA; +end; + {/\ Removes the points that are inside or outside the distance Dist from the point (x, y) from the TPointArray ThePoints. /\}