Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function ExplodeBox(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)) 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;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement