diff --git a/Examples/image_drawtext.simba b/Examples/image_drawtext.simba index 3c8c10753..b635d08cf 100644 --- a/Examples/image_drawtext.simba +++ b/Examples/image_drawtext.simba @@ -15,7 +15,7 @@ begin myImage.DrawColor := Colors.RED; myImage.DrawBox(myBox); myImage.DrawColor := Colors.BLACK; - myImage.DrawText(Now.ToString('c'), myBox, [EDrawTextAlign.CENTER, EDrawTextAlign.VERTICAL_CENTER]); + myImage.DrawText(Now.ToString('c'), myBox, [EImageTextAlign.CENTER, EImageTextAlign.VERTICAL_CENTER]); myImage.FontBold := True; myImage.FontSize := 50; diff --git a/Examples/mouse_teleport_event.simba b/Examples/mouse_teleport_event.simba index a45dbe8cc..a4bebfffc 100644 --- a/Examples/mouse_teleport_event.simba +++ b/Examples/mouse_teleport_event.simba @@ -1,19 +1,19 @@ var TPA: TPointArray; // stores the teleport events so we can view at the end -procedure MouseTeleportEvent(var Sender: TTarget; P: TPoint); +procedure MouseTeleportEvent(var Target: TTarget; Data: TTargetEventData); begin - WriteLn('Mouse teleported to: ', P); - TPA += P; + WriteLn('Mouse teleported to: ', Data.MouseTeleport); + TPA += [Data.MouseTeleport.X, Data.MouseTeleport.Y]; end; var - Event: TMouseTeleportEvent; + Event: TTargetEvent; begin - Event := Target.AddMouseEvent(@MouseTeleportEvent); + Event := Target.AddEvent(ETargetEventType.MOUSE_TELEPORT, @MouseTeleportEvent); Target.MouseTeleport([200,200]); Target.MouseMove([600,600]); - Target.RemoveMouseEvent(Event); // Remove the event + Target.RemoveEvent(ETargetEventType.MOUSE_TELEPORT, Event); // Remove the event Target.MouseMove([200, 600]); // The event has been removed so this wont be "recorded" when we show the path diff --git a/Examples/randomleft.simba b/Examples/randomleft.simba index c07ea8ae9..69094760a 100644 --- a/Examples/randomleft.simba +++ b/Examples/randomleft.simba @@ -1,3 +1,5 @@ +// Random left returns numbers weighted to the left number + const SampleCount = 1000000; Range = 10; diff --git a/Source/simba.vartype_pointarray.pas b/Source/simba.vartype_pointarray.pas index 183a5bebd..121edca80 100644 --- a/Source/simba.vartype_pointarray.pas +++ b/Source/simba.vartype_pointarray.pas @@ -1801,7 +1801,7 @@ function TPointArrayHelper.Rows: T2DPointArray; begin Start := I; Current := TPA[I].Y; - while (TPA[I].Y = Current) do + while (I < Len) and (TPA[I].Y = Current) do Inc(I); Buffer.Add(Copy(TPA, Start, I-Start)); @@ -1824,7 +1824,7 @@ function TPointArrayHelper.Columns: T2DPointArray; begin Start := I; Current := TPA[I].X; - while (TPA[I].X = Current) do + while (I < Len) and (TPA[I].X = Current) do Inc(I); Buffer.Add(Copy(TPA, Start, I-Start)); diff --git a/Tests/tpa_rowcolumn.simba b/Tests/tpa_rowcolumn.simba new file mode 100644 index 000000000..47a4e23ca --- /dev/null +++ b/Tests/tpa_rowcolumn.simba @@ -0,0 +1,45 @@ +{$assertions on} + +var + TPA, TPASorted: TPointArray; + Rows, Columns: T2DPointArray; + I, J: Integer; +begin + TPA := TPointArray.CreateFromBox([0,0,99,99], True); + Rows := TPA.Rows; + Columns := TPA.Columns; + + // row + TPASorted := TPA.SortByRow(True); + for I := 0 to High(TPASorted) do + Assert(TPASorted[I].Y = (I div 100)); + + TPASorted := TPA.SortByRow(False); + for I := 0 to High(TPASorted) do + Assert(TPASorted[I].Y = 99 - (I div 100)); + + Assert(Length(Rows) = 100); + for I := 0 to High(Rows) do + begin + Assert(Length(Rows[I]) = 100); + for j:=0 to High(Rows[I]) do + Assert(Rows[I,J] = [J,I]); + end; + + // column + TPASorted := TPA.SortByColumn(True); + for I := 0 to High(TPASorted) do + Assert(TPASorted[I].X = (I div 100)); + + TPASorted := TPA.SortByColumn(False); + for I := 0 to High(TPASorted) do + Assert(TPASorted[I].X = 99 - (I div 100)); + + Assert(Length(Columns) = 100); + for I := 0 to High(Columns) do + begin + Assert(Length(Columns[I]) = 100); + for j:=0 to High(Columns[I]) do + Assert(Columns[I,J] = [I,J]); + end; + end;