Skip to content

Commit

Permalink
Fix TCircle.RandomPoint + test
Browse files Browse the repository at this point in the history
  • Loading branch information
ollydev committed Oct 29, 2024
1 parent 0a38464 commit 152b215
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 4 deletions.
8 changes: 4 additions & 4 deletions Source/simba.vartype_circle.pas
Original file line number Diff line number Diff line change
Expand Up @@ -152,26 +152,26 @@ function TCircleHelper.RandomPoint: TPoint;
var
R, Theta, SinValue, CosValue: Double;
begin
R := Radius * Sqrt(Random());
R := Floor(Radius * Sqrt(Random()));
Theta := Random() * 2 * PI;

SinCos(Theta, SinValue, CosValue);

Result.X := Center.X + Round(R * CosValue);
Result.Y := Center.X + Round(R * SinValue);
Result.Y := Center.Y + Round(R * SinValue);
end;

function TCircleHelper.RandomPointCenter: TPoint;
var
R, Theta, SinValue, CosValue: Double;
begin
R := Radius * Sqrt(RandomLeft(0.0, 1.0));
R := Floor(Radius * Sqrt(RandomLeft(0.0, 1.0)));
Theta := Random() * 2 * PI;

SinCos(Theta, SinValue, CosValue);

Result.X := Center.X + Round(R * CosValue);
Result.Y := Center.X + Round(R * SinValue);
Result.Y := Center.Y + Round(R * SinValue);
end;

function TCircleHelper.Circularity(TPA: TPointArray): Double;
Expand Down
19 changes: 19 additions & 0 deletions Tests/circle.simba
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
{$assertions on}

var
c: TCircle;
begin
c := TCircle.Create(100, 100, 25);

Assert(c.Contains([100, 125]));
Assert(not c.Contains([100, 126]));
Assert(c.Contains([117, 117]));
Assert(not c.Contains([118, 118]));

RandSeed := 123;

for 1 to 1000 do
Assert(c.Contains(c.RandomPoint));
for 1 to 1000 do
Assert(c.Contains(c.RandomPointCenter));
end.

0 comments on commit 152b215

Please sign in to comment.