mirror of
https://github.com/moparisthebest/Simba
synced 2025-01-08 12:18:02 -05:00
Fixed bug in Arctan2, added new function ChangeDistPT and ChangeDistTPA.
This commit is contained in:
parent
6bbdc985ba
commit
84f9ee6587
@ -46,7 +46,7 @@ uses
|
|||||||
CastaliaSimplePasPar, v_AutoCompleteForm, PSDump;
|
CastaliaSimplePasPar, v_AutoCompleteForm, PSDump;
|
||||||
|
|
||||||
const
|
const
|
||||||
SimbaVersion = 666;
|
SimbaVersion = 668;
|
||||||
|
|
||||||
type
|
type
|
||||||
|
|
||||||
|
@ -83,9 +83,9 @@ begin
|
|||||||
Result:=Random(Abs(aFrom-aTo))+Min(aTo,AFrom);
|
Result:=Random(Abs(aFrom-aTo))+Min(aTo,AFrom);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
function ps_ArcTan2(x,y : extended) : extended; extdecl;
|
function ps_ArcTan2(y,x : extended) : extended; extdecl;
|
||||||
begin
|
begin
|
||||||
result := ArcTan2(x,y);
|
result := ArcTan2(y,x);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
procedure ps_IncEx(var x : integer; increase : integer); extdecl;
|
procedure ps_IncEx(var x : integer; increase : integer); extdecl;
|
||||||
|
@ -183,6 +183,16 @@ begin
|
|||||||
result := RotatePoint(p,angle,mx,my);
|
result := RotatePoint(p,angle,mx,my);
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function ps_ChangeDistPT(const PT : TPoint; mx,my : integer; newdist : extended) : TPoint;extdecl;
|
||||||
|
begin
|
||||||
|
result := ChangeDistPT(pt,mx,my,newdist);
|
||||||
|
end;
|
||||||
|
|
||||||
|
function ps_ChangeDistTPA(var TPA : TPointArray; mx,my : integer; newdist : extended) : boolean; extdecl;
|
||||||
|
begin
|
||||||
|
result := ChangeDistTPA(tpa,mx,my,newdist);
|
||||||
|
end;
|
||||||
|
|
||||||
function ps_FindGapsTPA(const TPA: TPointArray; MinPixels: Integer): T2DPointArray; extdecl;
|
function ps_FindGapsTPA(const TPA: TPointArray; MinPixels: Integer): T2DPointArray; extdecl;
|
||||||
begin
|
begin
|
||||||
result := FindGapsTPA(TPA,minpixels);
|
result := FindGapsTPA(TPA,minpixels);
|
||||||
|
@ -55,7 +55,7 @@ AddFunction(@ps_min,'function Min(a, b: Integer): Integer;');
|
|||||||
AddFunction(@ps_minE,'function MinE(a, b: extended): Extended;');
|
AddFunction(@ps_minE,'function MinE(a, b: extended): Extended;');
|
||||||
AddFunction(@ps_maxE,'function MaxE(a, b: extended): Extended;');
|
AddFunction(@ps_maxE,'function MaxE(a, b: extended): Extended;');
|
||||||
AddFunction(@ps_iAbs,'function iAbs(a : integer) : integer;');
|
AddFunction(@ps_iAbs,'function iAbs(a : integer) : integer;');
|
||||||
AddFunction(@ps_ArcTan2,'function ArcTan2(x,y : extended) : extended;');
|
AddFunction(@ps_ArcTan2,'function ArcTan2(y,x : extended) : extended;');
|
||||||
AddFunction(@ps_IntToBox,'function IntToBox(xs,ys,xe,ye : integer) : TBox;');
|
AddFunction(@ps_IntToBox,'function IntToBox(xs,ys,xe,ye : integer) : TBox;');
|
||||||
AddFunction(@ps_IntInBox,'function IntInBox(x, y: Integer; Box: TBox): Boolean;');
|
AddFunction(@ps_IntInBox,'function IntInBox(x, y: Integer; Box: TBox): Boolean;');
|
||||||
AddFunction(@ps_PointToBox,'function PointToBox(PT1,PT2 : TPoint): TBox;');
|
AddFunction(@ps_PointToBox,'function PointToBox(PT1,PT2 : TPoint): TBox;');
|
||||||
@ -360,6 +360,8 @@ AddFunction(@ps_FindTextTPAinTPA,'function FindTextTPAinTPA(Height : integer;con
|
|||||||
AddFunction(@ps_SortCircleWise,'procedure SortCircleWise(var tpa: TPointArray; const cx, cy, StartDegree: Integer; SortUp, ClockWise: Boolean);');
|
AddFunction(@ps_SortCircleWise,'procedure SortCircleWise(var tpa: TPointArray; const cx, cy, StartDegree: Integer; SortUp, ClockWise: Boolean);');
|
||||||
AddFunction(@ps_LinearSort,'procedure LinearSort(var tpa: TPointArray; cx, cy, sd: Integer; SortUp: Boolean);');
|
AddFunction(@ps_LinearSort,'procedure LinearSort(var tpa: TPointArray; cx, cy, sd: Integer; SortUp: Boolean);');
|
||||||
AddFunction(@ps_RotatePoint,'function RotatePoint(Const p: TPoint; angle, mx, my: Extended): TPoint;');
|
AddFunction(@ps_RotatePoint,'function RotatePoint(Const p: TPoint; angle, mx, my: Extended): TPoint;');
|
||||||
|
AddFunction(@ps_ChangeDistPT,'function ChangeDistPT(const PT : TPoint; mx,my : integer; newdist : extended) : TPoint;');
|
||||||
|
AddFunction(@ps_ChangeDistTPA,'function ChangeDistTPA(var TPA : TPointArray; mx,my : integer; newdist : extended) : boolean;');
|
||||||
AddFunction(@ps_FindGapsTPA,'function FindGapsTPA(const TPA: TPointArray; MinPixels: Integer): T2DPointArray;');
|
AddFunction(@ps_FindGapsTPA,'function FindGapsTPA(const TPA: TPointArray; MinPixels: Integer): T2DPointArray;');
|
||||||
AddFunction(@ps_RemoveDistTPointArray,'function RemoveDistTPointArray(x, y, dist: Integer;const ThePoints: TPointArray; RemoveHigher: Boolean): TPointArray;');
|
AddFunction(@ps_RemoveDistTPointArray,'function RemoveDistTPointArray(x, y, dist: Integer;const ThePoints: TPointArray; RemoveHigher: Boolean): TPointArray;');
|
||||||
AddFunction(@ps_CombineTPA,'function CombineTPA(const Ar1, Ar2: TPointArray): TPointArray;');
|
AddFunction(@ps_CombineTPA,'function CombineTPA(const Ar1, Ar2: TPointArray): TPointArray;');
|
||||||
|
@ -218,6 +218,7 @@ uses
|
|||||||
uPSR_extctrls, //Runtime-libs
|
uPSR_extctrls, //Runtime-libs
|
||||||
Graphics, //For Graphics types
|
Graphics, //For Graphics types
|
||||||
math, //Maths!
|
math, //Maths!
|
||||||
|
mmath, //Real maths!
|
||||||
strutils,
|
strutils,
|
||||||
tpa, //Tpa stuff
|
tpa, //Tpa stuff
|
||||||
forms,//Forms
|
forms,//Forms
|
||||||
|
@ -104,6 +104,7 @@ uses
|
|||||||
// colour_conv,// For RGBToColor, etc.
|
// colour_conv,// For RGBToColor, etc.
|
||||||
Client, // For the Client Casts.
|
Client, // For the Client Casts.
|
||||||
math, //min/max
|
math, //min/max
|
||||||
|
mmath,
|
||||||
tpa, //TPABounds
|
tpa, //TPABounds
|
||||||
dtmutil
|
dtmutil
|
||||||
;
|
;
|
||||||
|
@ -31,17 +31,20 @@ interface
|
|||||||
uses
|
uses
|
||||||
Classes, SysUtils,MufasaTypes;
|
Classes, SysUtils,MufasaTypes;
|
||||||
|
|
||||||
function RotatePoints(P: TPointArray; A, cx, cy: Extended): TPointArray;
|
function RotatePoints(const P: TPointArray;const A, cx, cy: Extended): TPointArray;
|
||||||
function RotatePoint(p: TPoint; angle, mx, my: Extended): TPoint;
|
function RotatePoint(const p: TPoint;const angle, mx, my: Extended): TPoint;
|
||||||
|
function ChangeDistPT(const PT : TPoint; mx,my : integer; newdist : extended) : TPoint;
|
||||||
|
function ChangeDistTPA(var TPA : TPointArray; mx,my : integer; newdist : extended) : boolean;
|
||||||
|
|
||||||
implementation
|
implementation
|
||||||
|
uses
|
||||||
|
math;
|
||||||
|
|
||||||
{/\
|
{/\
|
||||||
Rotates the given points (P) by A (in radians) around the point defined by cx, cy.
|
Rotates the given points (P) by A (in radians) around the point defined by cx, cy.
|
||||||
/\}
|
/\}
|
||||||
|
|
||||||
function RotatePoints(P: TPointArray; A, cx, cy: Extended): TPointArray;
|
function RotatePoints(const P: TPointArray;const A, cx, cy: Extended): TPointArray;
|
||||||
|
|
||||||
var
|
var
|
||||||
I, L: Integer;
|
I, L: Integer;
|
||||||
@ -60,12 +63,43 @@ end;
|
|||||||
Rotates the given point (p) by A (in radians) around the point defined by cx, cy.
|
Rotates the given point (p) by A (in radians) around the point defined by cx, cy.
|
||||||
/\}
|
/\}
|
||||||
|
|
||||||
function RotatePoint(p: TPoint; angle, mx, my: Extended): TPoint;
|
function RotatePoint(const p: TPoint;const angle, mx, my: Extended): TPoint;
|
||||||
|
|
||||||
begin
|
begin
|
||||||
Result.X := Round(mx + cos(angle) * (p.x - mx) - sin(angle) * (p.y - my));
|
Result.X := Round(mx + cos(angle) * (p.x - mx) - sin(angle) * (p.y - my));
|
||||||
Result.Y := Round(my + sin(angle) * (p.x - mx) + cos(angle) * (p.y- my));
|
Result.Y := Round(my + sin(angle) * (p.x - mx) + cos(angle) * (p.y- my));
|
||||||
end;
|
end;
|
||||||
|
|
||||||
|
function ChangeDistPT(const PT : TPoint; mx,my : integer; newdist : extended) : TPoint;
|
||||||
|
var
|
||||||
|
angle : extended;
|
||||||
|
begin
|
||||||
|
angle := ArcTan2(pt.y-my,pt.x-mx);
|
||||||
|
result.y := round(sin(angle) * newdist) + mx;
|
||||||
|
result.x := round(cos(angle) * newdist) + my;
|
||||||
|
end;
|
||||||
|
|
||||||
|
function ChangeDistTPA(var TPA : TPointArray; mx,my : integer; newdist : extended) : boolean;
|
||||||
|
var
|
||||||
|
angle : extended;
|
||||||
|
i : integer;
|
||||||
|
begin
|
||||||
|
result := false;
|
||||||
|
if length(TPA) < 1 then
|
||||||
|
exit;
|
||||||
|
result := true;
|
||||||
|
try
|
||||||
|
for i := high(TPA) downto 0 do
|
||||||
|
begin
|
||||||
|
angle := ArcTan2(TPA[i].y-my,TPA[i].x-mx);
|
||||||
|
TPA[i].y := round(sin(angle) * newdist) + mx;
|
||||||
|
TPA[i].x := round(cos(angle) * newdist) + my;
|
||||||
|
end;
|
||||||
|
except
|
||||||
|
result := false;
|
||||||
|
end;
|
||||||
|
|
||||||
|
end;
|
||||||
|
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
@ -79,8 +79,6 @@ procedure LinearSort(var tpa: TPointArray; cx, cy, sd: Integer; SortUp: Boolean)
|
|||||||
function MergeATPA(const ATPA : T2DPointArray) : TPointArray;
|
function MergeATPA(const ATPA : T2DPointArray) : TPointArray;
|
||||||
procedure AppendTPA(var TPA : TPointArray; const ToAppend : TPointArray);
|
procedure AppendTPA(var TPA : TPointArray; const ToAppend : TPointArray);
|
||||||
function TPAFromBox(const Box : TBox) : TPointArray;
|
function TPAFromBox(const Box : TBox) : TPointArray;
|
||||||
Function RotatePoints(Const P: TPointArray; A, cx, cy: Extended): TPointArray ;
|
|
||||||
Function RotatePoint(Const p: TPoint; angle, mx, my: Extended): TPoint; inline;
|
|
||||||
function FindTPAEdges(const p: TPointArray): TPointArray;
|
function FindTPAEdges(const p: TPointArray): TPointArray;
|
||||||
function PointInTPA(const p: TPoint;const arP: TPointArray): Boolean;
|
function PointInTPA(const p: TPoint;const arP: TPointArray): Boolean;
|
||||||
function ClearTPAFromTPA(const arP, ClearPoints: TPointArray): TPointArray;
|
function ClearTPAFromTPA(const arP, ClearPoints: TPointArray): TPointArray;
|
||||||
@ -100,7 +98,7 @@ procedure OffsetATPA(var ATPA : T2DPointArray; const Offset : TPoint);
|
|||||||
implementation
|
implementation
|
||||||
|
|
||||||
uses
|
uses
|
||||||
math;
|
math,mmath;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user