Skip to content

Commit

Permalink
Add TBox TopLeft TopRight, BottomLeft, BottomRight
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Oct 15, 2024
1 parent f89a9f2 commit 6295bd4
Show file tree
Hide file tree
Showing 3 changed files with 78 additions and 4 deletions.
61 changes: 57 additions & 4 deletions Source/script/imports/simba.import_box.pas
Original file line number Diff line number Diff line change
Expand Up @@ -311,7 +311,7 @@ procedure _LapeBox_Normalize(const Params: PParamArray; const Result: Pointer);
TBox.Width
----------
```
function TBox.Width: Integer;
property TBox.Width: Integer;
```
*)
procedure _LapeBox_Width(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
Expand All @@ -323,7 +323,7 @@ procedure _LapeBox_Width(const Params: PParamArray; const Result: Pointer); LAPE
TBox.Height
-----------
```
function TBox.Height: Integer;
property TBox.Height: Integer;
```
*)
procedure _LapeBox_Height(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
Expand All @@ -335,7 +335,7 @@ procedure _LapeBox_Height(const Params: PParamArray; const Result: Pointer); LAP
TBox.Center
-----------
```
function TBox.Center: TPoint;
property TBox.Center: TPoint;
```
*)
procedure _LapeBox_Center(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
Expand Down Expand Up @@ -397,6 +397,54 @@ procedure _LapeBox_RandomPointCenter(const Params: PParamArray; const Result: Po
PPoint(Result)^ := PBox(Params^[0])^.RandomPointCenter();
end;

(*
TBox.TopLeft
------------
```
property TBox.TopLeft: TPoint;
```
*)
procedure _LapeBox_TopLeft(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PPoint(Result)^ := PBox(Params^[0])^.TopLeft;
end;

(*
TBox.TopRight
-------------
```
property TBox.TopRight: TPoint;
```
*)
procedure _LapeBox_TopRight(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PPoint(Result)^ := PBox(Params^[0])^.TopRight;
end;

(*
TBox.BottomLeft
---------------
```
property TBox.BottomLeft: TPoint;
```
*)
procedure _LapeBox_BottomLeft(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PPoint(Result)^ := PBox(Params^[0])^.BottomLeft;
end;

(*
TBox.BottomRight
----------------
```
property TBox.BottomRight: TPoint;
```
*)
procedure _LapeBox_BottomRight(const Params: PParamArray; const Result: Pointer); LAPE_WRAPPER_CALLING_CONV
begin
PPoint(Result)^ := PBox(Params^[0])^.BottomRight;
end;

procedure ImportBox(Compiler: TSimbaScript_Compiler);
begin
with Compiler do
Expand Down Expand Up @@ -440,8 +488,13 @@ procedure ImportBox(Compiler: TSimbaScript_Compiler);
addGlobalFunc('function TBox.RandomPoint: TPoint', @_LapeBox_RandomPoint);
addGlobalFunc('function TBox.RandomPointCenter: TPoint', @_LapeBox_RandomPointCenter);

addGlobalFunc('property TBox.TopLeft: TPoint;', @_LapeBox_TopLeft);
addGlobalFunc('property TBox.TopRight: TPoint;', @_LapeBox_TopRight);
addGlobalFunc('property TBox.BottomLeft: TPoint;', @_LapeBox_BottomLeft);
addGlobalFunc('property TBox.BottomRight: TPoint;', @_LapeBox_BottomRight);

ImportingSection := '';
end;
end;

end.
end.
16 changes: 16 additions & 0 deletions Source/simba.vartype_box.pas
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,8 @@ interface
type
TBoxHelper = record helper for TBox
private
function GetTopRight: TPoint; inline;
function GetBottomLeft: TPoint; inline;
function GetCenter: TPoint; inline;
function GetWidth: Integer; inline;
function GetHeight: Integer; inline;
Expand Down Expand Up @@ -57,6 +59,8 @@ TBoxHelper = record helper for TBox
function Clip(Other: TBox): TBox;
function Normalize: TBox;

property TopRight: TPoint read GetTopRight;
property BottomLeft: TPoint read GetBottomLeft;
property Width: Integer read GetWidth;
property Height: Integer read GetHeight;
property Center: TPoint read GetCenter;
Expand All @@ -72,6 +76,18 @@ implementation
Math,
simba.random, simba.containers, simba.geometry;

function TBoxHelper.GetTopRight: TPoint;
begin
Result.X := X2;
Result.Y := Y1;
end;

function TBoxHelper.GetBottomLeft: TPoint;
begin
Result.X := X1;
Result.Y := Y2;
end;

function TBoxHelper.GetCenter: TPoint;
begin
Result.X := (Self.X2 + Self.X1 + 1) div 2;
Expand Down
5 changes: 5 additions & 0 deletions Tests/box.simba
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,9 @@ begin
Assert(b.Expand(50, 100) = [50,0,250,300]);

Assert(b.Offset([-10, 10]) = [90, 110, 190, 210]);

Assert(b.TopLeft = [100,100]);
Assert(b.TopRight = [200,100]);
Assert(b.BottomLeft = [100,200]);
Assert(b.BottomRight = [200,200]);
end.

0 comments on commit 6295bd4

Please sign in to comment.