Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {==============================================================================]
- Explodes bx to array of TBoxes by rows and columns
- [==============================================================================}
- function BoxExplode(bx: TBox; rows, columns: Integer): TBoxArray;
- var
- r, c, w, h, ew, eh, ow, oh, i, x, y: Integer;
- begin
- if ((rows > 0) and (columns > 0) and (bx.X1 <= bx.X2) and (bx.Y1 <= bx.Y2)) then
- begin
- w := ((bx.X2 - bx.X1) + 1);
- h := ((bx.Y2 - bx.Y1) + 1);
- if (rows > h) then
- rows := h;
- if (columns > w) then
- columns := w;
- w := (w div columns);
- h := (h div rows);
- ew := (((bx.X2 - bx.X1) + 1) - (w * columns));
- eh := (((bx.Y2 - bx.Y1) + 1) - (h * rows));
- SetLength(Result, (rows * columns));
- y := bx.Y1;
- for r := 0 to (rows - 1) do
- begin
- x := bx.X1;
- if ((eh > 0) and (r < eh)) then
- oh := 1
- else
- oh := 0;
- for c := 0 to (columns - 1) do
- begin
- if ((ew > 0) and (c < ew)) then
- ow := 1
- else
- ow := 0;
- i := ((r * columns) + c);
- Result[i].X1 := x;
- Result[i].X2 := (x + (w - 1) + ow);
- Result[i].Y1 := y;
- Result[i].Y2 := (y + (h - 1) + oh);
- x := (Result[i].X2 + 1);
- end;
- y := (Result[i].Y2 + 1);
- end;
- end else
- SetLength(Result, 0);
- end;
- var
- bx: TBox;
- bxs: TBoxArray;
- h, i: Integer;
- begin
- bx := Box(10, 10, 70, 70);
- bxs := BoxExplode(bx, 5, 10);
- h := High(bxs);
- for i := 0 to h do
- WriteLn('bxs[' + IntToStr(i) + '] = ' + BoxToStr(bxs[i]));
- end.
Advertisement
Add Comment
Please, Sign In to add comment