• Sky
• Blueberry
• Slate
• Blackcurrant
• Watermelon
• Strawberry
• Orange
• Banana
• Apple
• Emerald
• Chocolate
• Charcoal

# BoxCentralization

## Recommended Posts

This procedure places a box (sub_bx) to center of a another box (main_bx).

Couldn't think of any better name for this procedure.

[scar]procedure BoxCentralization(var sub_bx: TBox; main_bx: TBox; method: Integer);

var

o: TPoint;

begin

o := Point(((Round(main_bx.Y1 + ((main_bx.Y2 - main_bx.Y1) / 2)) - (((sub_bx.Y2 - sub_bx.Y1) + 1) div 2)) - sub_bx.Y1), ((Round(main_bx.X1 + ((main_bx.X2 - main_bx.X1) / 2)) - (((sub_bx.X2 - sub_bx.X1) + 1) div 2)) - sub_bx.X1));

case method of

0: sub_bx := Box((sub_bx.X1 + o.X), (sub_bx.Y1 + o.Y), (sub_bx.X2 + o.X), (sub_bx.Y2 + o.Y)); // Widthwise & Heightwise.

1: sub_bx := Box((sub_bx.X1 + o.X), sub_bx.Y1, (sub_bx.X2 + o.X), sub_bx.Y2); // Widthwise

2: sub_bx := Box(sub_bx.X1, (sub_bx.Y1 + o.Y), sub_bx.X2, (sub_bx.Y2 + o.Y)); // Heightwise

end;

end;

var

m: Integer;

m_bx, c_bx, c_bx2: TBox;

begin

ClearDebug;

m_bx := Box(0, 0, 1000, 1000);

c_bx := Box(50, 50, 100, 100);

WriteLn('m_bx: ' + BoxToStr(m_bx) + #13#10 + 'c_bx: ' + BoxToStr(c_bx) + #13#10);

for m := 0 to 2 do

begin

c_bx2 := c_bx;

BoxCentralization(c_bx2, m_bx, m);

WriteLn('c_bx: ' + BoxToStr(c_bx2) + ' [Centralization method: ' + IntToStr(m) + ']');

end;

end.[/scar]

Edited by Janilabo

## Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×

×