How to get bounds rect of the shapes??

How to get bounds rect of the shapes??

https://drive.google.com/file/d/0BwdfodaqQm4pLXpNRGNkM2tyMGM/view?usp=sharing

After some tries , I get it work:

procedure TForm1.Button1Click(Sender: TObject);
begin
with TRectangle.Create(FViewBox) do
begin
Parent := FViewBox;
BoundsRect := GetBoundsRect(FViewBox);
Opacity := 0.7;
end;
end;

function TForm1.GetBoundsRect(TPathContainer: TLayout): TRectF;
var
LControl: TControl;
LPath: TPath;
LLeft, LRight, LTop, LBottom: Single;
LLeftAssigned, LRightAssigned, LTopAssigned, LBottomAssigned: Boolean;
begin
LLeftAssigned := False;
LRightAssigned := False;
LTopAssigned := False;
LBottomAssigned := False;
// Get Bounds Rect of All Paths
for LControl in TPathContainer.Controls do
begin
if LControl is TPath then
begin
LPath := LControl as TPath;
if not LLeftAssigned then
begin
LLeft := LPath.Data.GetBounds.Left;
LLeftAssigned := True;
end
else
LLeft := Min(LLeft, LPath.Data.GetBounds.Left);
if not LRightAssigned then
begin
LRight := LPath.Data.GetBounds.Right;
LRightAssigned := True;
end
else
LRight := Max(LRight, LPath.Data.GetBounds.Right);
if not LTopAssigned then
begin
LTop := LPath.Data.GetBounds.Top;
LTopAssigned := True;
end
else
LTop := Min(LTop, LPath.Data.GetBounds.Top);
if not LBottomAssigned then
begin
LBottom := LPath.Data.GetBounds.Bottom;
LBottomAssigned := True;
end
else
LBottom := Max(LBottom, LPath.Data.GetBounds.Bottom);
end;
end;

Result := TRectF.Create(LLeft, LTop, LRight, LBottom);

Result.Fit(FVectorContainer.BoundsRect);
OffsetRect(Result, -FVectorContainer.Position.X, -FVectorContainer.Position.Y);

end;


Comments

  1. Alexander Benikowski Thank you , finally get it work by adding the last two lines.

    ReplyDelete
  2. Oh my, call my answer incomplete. Inflate generally 0.5 of the of any stroke widths (for "on the path" lines), and allow for miter joints (to limit) for any miter joined strokes.

    ReplyDelete

Post a Comment