Skip to content

Commit

Permalink
TCircle from SRL
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Sep 19, 2023
1 parent 9ac2640 commit d0f921c
Show file tree
Hide file tree
Showing 13 changed files with 615 additions and 9 deletions.
1 change: 1 addition & 0 deletions DocGen/docgen.simba
Original file line number Diff line number Diff line change
Expand Up @@ -185,6 +185,7 @@ begin
ParseSourceFile('simba.import_box', 'TBox' );
ParseSourceFile('simba.import_boxarray', 'TBoxArray' );
ParseSourceFile('simba.import_quad', 'TQuad' );
ParseSourceFile('simba.import_circle', 'TCircle' );
ParseSourceFile('simba.import_windowhandle', 'TWindowHandle' );
ParseSourceFile('simba.import_debugimage', 'Debug Image' );
ParseSourceFile('simba.import_variant', 'Variant' );
Expand Down
10 changes: 9 additions & 1 deletion Source/Simba.lpi
Original file line number Diff line number Diff line change
Expand Up @@ -340,7 +340,7 @@
<PackageName Value="LCL"/>
</Item5>
</RequiredPackages>
<Units Count="144">
<Units Count="146">
<Unit0>
<Filename Value="Simba.lpr"/>
<IsPartOfProject Value="True"/>
Expand Down Expand Up @@ -998,6 +998,14 @@
<Filename Value="script/imports/simbaclasses/simba.import_externalimage.pas"/>
<IsPartOfProject Value="True"/>
</Unit143>
<Unit144>
<Filename Value="simba.circle.pas"/>
<IsPartOfProject Value="True"/>
</Unit144>
<Unit145>
<Filename Value="script/imports/simba/simba.import_circle.pas"/>
<IsPartOfProject Value="True"/>
</Unit145>
</Units>
</ProjectOptions>
<CompilerOptions>
Expand Down
2 changes: 2 additions & 0 deletions Source/forms/simba.functionlistform.pas
Original file line number Diff line number Diff line change
Expand Up @@ -164,6 +164,8 @@ function GetURL(const Section: String): String;
'Dialogs': Result := 'https://villavu.github.io/Simba/Dialogs.html';
'DTM': Result := 'https://villavu.github.io/Simba/DTM.html';
'System': Result := 'https://villavu.github.io/Simba/System.html';
'TCircle': Result := 'https://villavu.github.io/Simba/TCircle.html';
'DateTime': Result := 'https://villavu.github.io/Simba/DateTime.html';
end;
end;

Expand Down
228 changes: 228 additions & 0 deletions Source/script/imports/simba/simba.import_circle.pas
Original file line number Diff line number Diff line change
@@ -0,0 +1,228 @@
{
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
}
unit simba.import_circle;

{$i simba.inc}

interface

uses
Classes, SysUtils,
simba.mufasatypes, simba.script_compiler;

procedure ImportCircle(Compiler: TSimbaScript_Compiler);

implementation

uses
lptypes,
simba.circle;

(*
TCircle
=======
Record that contains center point and radius.
*)

(*
TCircle.Create
~~~~~~~~~~~~~~
> function TCircle.Create(ACenter: TPoint; ARadius: Integer): TCircle; static;
*)
procedure _LapeCircle_Create(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PCircle(Result)^ := TCircle.Create(PPoint(Params^[0])^, PInteger(Params^[1])^);
end;

(*
TCircle.CreateFromPoints
~~~~~~~~~~~~~~~~~~~~~~~~
> function CreateFromPoints(Points: TPointArray): TCircle; static;
*)
procedure _LapeCircle_CreateFromPoints(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PCircle(Result)^ := TCircle.CreateFromPoints(PPointArray(Params^[0])^);
end;

(*
TCircle.ToTPA
~~~~~~~~~~~~~
> function TCircle.ToTPA(Filled: Boolean): TPointArray;
*)
procedure _LapeCircle_ToTPA(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PPointArray(Result)^ := PCircle(Params^[0])^.ToTPA(PBoolean(Params^[1])^);
end;

(*
TCircle.Bounds
~~~~~~~~~~~~~~
> function TCircle.Bounds: TBox;
*)
procedure _LapeCircle_Bounds(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PBox(Result)^ := PCircle(Params^[0])^.Bounds();
end;

(*
TCircle.Contains
~~~~~~~~~~~~~~~~
> function TCircle.Contains(P: TPoint): Boolean
*)
procedure _LapeCircle_Contains(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PBoolean(Result)^ := PCircle(Params^[0])^.Contains(PPoint(Params^[1])^);
end;

(*
TCircle.PointAtDegrees
~~~~~~~~~~~~~~~~~~~~~~
> function TCircle.PointAtDegrees(Degrees: Double): TPoint;
*)
procedure _LapeCircle_PointAtDegrees(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PPoint(Result)^ := PCircle(Params^[0])^.PointAtDegrees(PDouble(Params^[1])^);
end;

(*
TCircle.RandomPoint
~~~~~~~~~~~~~~~~~~~
> function TCircle.RandomPoint: TPoint;
Returns a completely random point in the circle.
*)
procedure _LapeCircle_RandomPoint(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PPoint(Result)^ := PCircle(Params^[0])^.RandomPoint();
end;

(*
TCircle.RandomPointCenter
~~~~~~~~~~~~~~~~~~~~~~~~~
> function TCircle.RandomPointCenter: TPoint;
Returns a random point in the circle which is weighted torwards the circle's center.
*)
procedure _LapeCircle_RandomPointCenter(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PPoint(Result)^ := PCircle(Params^[0])^.RandomPointCenter();
end;

(*
TCircle.Circumference
~~~~~~~~~~~~~~~~~~~~~
> function TCircle.Circumference: Double;
Returns the distance around the outside of a circle.
*)
procedure _LapeCircle_Circumference(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PDouble(Result)^ := PCircle(Params^[0])^.Circumference();
end;

(*
TCircle.Area
~~~~~~~~~~~~
> function TCircle.Area: Double;
Returns the area the circle covers.
*)
procedure _LapeCircle_Area(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PDouble(Result)^ := PCircle(Params^[0])^.Area();
end;

(*
TCircle.Area
~~~~~~~~~~~~
> function TCircle.Area: Double;
Returns the area the circle covers.
*)
procedure _LapeCircle_Expand(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PCircle(Result)^ := PCircle(Params^[0])^.Expand(PInteger(Params^[1])^);
end;

(*
TCircle.Area
~~~~~~~~~~~~
> function TCircle.Area: Double;
Returns the area the circle covers.
*)
procedure _LapeCircle_Offset(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PCircle(Result)^ := PCircle(Params^[0])^.Offset(PPoint(Params^[1])^);
end;

(*
TCircle.Extract
~~~~~~~~~~~~~~~
> function TCircle.Extract(Points: TPointArray): TPointArray;
Returns the points that **are** in the circle.
*)
procedure _LapeCircle_Extract(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PPointArray(Result)^ := PCircle(Params^[0])^.Extract(PPointArray(Params^[1])^);
end;

(*
TCircle.Exclude
~~~~~~~~~~~~~~~
> function TCircle.Exclude(Points: TPointArray): TPointArray;
Returns the points that are not inside the circle.
*)
procedure _LapeCircle_Exclude(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PPointArray(Result)^ := PCircle(Params^[0])^.Exclude(PPointArray(Params^[1])^);
end;

(*
in
~~
> operator in(Left: TPoint; Right: TCircle): Boolean;
*)
procedure _LapePoint_IN_Cicle(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PBoolean(Result)^ := PPoint(Params^[0])^ in PCircle(Params^[1])^;
end;

procedure ImportCircle(Compiler: TSimbaScript_Compiler);
begin
with Compiler do
begin
ImportingSection := 'TCircle';

addGlobalType('record Center: TPoint; Radius: Integer; end;', 'TCircle');

addGlobalFunc('function TCircle.Create(ACenter: TPoint; ARadius: Integer): TCircle; static; overload', @_LapeCircle_Create);
addGlobalFunc('function TCircle.CreateFromPoints(Points: TPointArray): TCircle; static; overload', @_LapeCircle_CreateFromPoints);

addGlobalFunc('function TCircle.ToTPA(Filled: Boolean): TPointArray', @_LapeCircle_ToTPA);
addGlobalFunc('function TCircle.Bounds: TBox', @_LapeCircle_Bounds);
addGlobalFunc('function TCircle.Contains(P: TPoint): Boolean', @_LapeCircle_Contains);
addGlobalFunc('function TCircle.PointAtDegrees(Degrees: Double): TPoint;', @_LapeCircle_PointAtDegrees);

addGlobalFunc('function TCircle.RandomPoint: TPoint', @_LapeCircle_RandomPoint);
addGlobalFunc('function TCircle.RandomPointCenter: TPoint', @_LapeCircle_RandomPointCenter);

addGlobalFunc('function TCircle.Circumference: Double', @_LapeCircle_Circumference);
addGlobalFunc('function TCircle.Area: Double', @_LapeCircle_Area);
addGlobalFunc('function TCircle.Expand(Amount: Integer): TCircle', @_LapeCircle_Expand);
addGlobalFunc('function TCircle.Offset(P: TPoint): TCircle', @_LapeCircle_Offset);
addGlobalFunc('function TCircle.Extract(Points: TPointArray): TPointArray', @_LapeCircle_Extract);
addGlobalFunc('function TCircle.Exclude(Points: TPointArray): TPointArray', @_LapeCircle_Exclude);

addGlobalFunc('operator in(Left: TPoint; Right: TCircle): Boolean;', @_LapePoint_IN_Cicle);

ImportingSection := '';
end;
end;

end.
7 changes: 6 additions & 1 deletion Source/script/imports/simba/simba.import_quad.pas
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
}
unit simba.import_quad;

{$i simba.inc}
Expand Down Expand Up @@ -291,4 +296,4 @@ procedure ImportQuad(Compiler: TSimbaScript_Compiler);
end;
end;

end.
end.
18 changes: 17 additions & 1 deletion Source/script/imports/simba/simba.import_tpa.pas
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
{
Author: Raymond van Venetië and Merlijn Wajer
Project: Simba (https://github.com/MerlijnWajer/Simba)
License: GNU General Public License (https://www.gnu.org/licenses/gpl-3.0)
}
unit simba.import_tpa;

{$i simba.inc}
Expand All @@ -14,7 +19,7 @@ implementation

uses
lptypes,
simba.tpa, simba.geometry,
simba.tpa, simba.circle, simba.geometry,
simba.algo_difference, simba.algo_intersection, simba.algo_symmetricDifference;

(*
Expand Down Expand Up @@ -637,6 +642,16 @@ procedure _LapeTPAMinAreaRect(const Params: PParamArray; const Result: Pointer);
PQuad(Result)^ := PPointArray(Params^[0])^.MinAreaRect();
end;

(*
TPointArray.MinAreaCircle
~~~~~~~~~~~~~~~~~~~~~~~~~
> function TPointArray.MinAreaCircle: TCircle;
*)
procedure _LapeTPAMinAreaCircle(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PCircle(Result)^ := PPointArray(Params^[0])^.MinAreaCircle();
end;

(*
TPointArray.Erode
~~~~~~~~~~~~~~~~~
Expand Down Expand Up @@ -763,6 +778,7 @@ procedure ImportTPA(Compiler: TSimbaScript_Compiler);
addGlobalFunc('function TPointArray.Extremes: TPointArray', @_LapeTPAExtremes);
addGlobalFunc('function TPointArray.Bounds: TBox; overload', @_LapeTPABounds);
addGlobalFunc('function TPointArray.MinAreaRect: TQuad', @_LapeTPAMinAreaRect);
addGlobalFunc('function TPointArray.MinAreaCircle: TCircle', @_LapeTPAMinAreaCircle);
addGlobalFunc('function TPointArray.Mean: TPoint; overload', @_LapeTPAMean);

addGlobalFunc('function TPointArray.Connect: TPointArray', @_LapeTPAConnect);
Expand Down
13 changes: 11 additions & 2 deletions Source/script/simba.compiler_dump.pas
Original file line number Diff line number Diff line change
Expand Up @@ -319,15 +319,24 @@ procedure TSimbaCompilerDump.DumpToFile(FileName: String);

// Move lape stuff to better sections
Move('function Random(min, max: Int64): Int64;', 'Math', 'Random');
Move('function Random(min, max: Extended): Extended', 'Math', 'Random');
Move('function Random(min, max: Double): Double', 'Math', 'Random');
Move('function Random(l: Int64): Int64', 'Math', 'Random');
Move('function Random: Extended', 'Math', 'Random');
Move('function Random: Double', 'Math', 'Random');
Move('procedure Randomize', 'Math', 'Random');
Move('var RandSeed', 'Math', 'Random');

Move('function GetTickCount: UInt64', 'DateTime', 'Timing');
Move('procedure Sleep(MilliSeconds: UInt32);', 'DateTime', 'Timing');

Move('type TBox = record X1, Y1, X2, Y2: Integer; end;', 'System', 'TBox');
Move('type TBoxArray = array of TBox;', 'System', 'TBox');

Move('type TQuad = record Top, Right, Bottom, Left: TPoint; end;', 'System', 'TQuad');
Move('type TQuadArray = array of TQuad;', 'System', 'TQuad');

Move('type TPoint = record X, Y: Integer; end;', 'System', 'TPoint');
Move('type TPointArray = array of TPoint;', 'System', 'TPointArray');

with TStringList.Create() do
try
LineBreak := #0;
Expand Down
2 changes: 2 additions & 0 deletions Source/script/simba.script_imports.pas
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,7 @@ implementation
simba.import_system, simba.import_colormath,
simba.import_matrix, simba.import_windowhandle,
simba.import_quad, simba.import_box, simba.import_boxarray, simba.import_point,
simba.import_circle,

// LCL
simba.import_lcl_system, simba.import_lcl_graphics, simba.import_lcl_controls,
Expand All @@ -47,6 +48,7 @@ procedure AddSimbaImports(Compiler: TSimbaScript_Compiler);
ImportMatrix(Compiler);
ImportWindowHandle(Compiler);
ImportQuad(Compiler);
ImportCircle(Compiler);
ImportBox(Compiler);
ImportBoxArray(Compiler);
ImportPoint(Compiler);
Expand Down
Loading

0 comments on commit d0f921c

Please sign in to comment.