Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {$L SSP.dll}
- var
- area: TBox;
- width, height: Integer;
- function BoxPartition(bx: TBox; width, height: Integer): TBoxArray;
- var
- r, c, x, y, i: Integer;
- er, ec: Extended;
- a, b: Boolean;
- begin
- if ((width > 0) and (height > 0)) then
- begin
- er := (((area.Y2 - area.Y1) + 1) / height);
- ec := (((area.X2 - area.X1) + 1) / width);
- r := Ceil(er);
- c := Ceil(ec);
- SetLength(Result, (r * c));
- a := (er <> r);
- b := (ec <> c);
- for y := 0 to (r - 1) do
- for x := 0 to (c - 1) do
- begin
- i := ((y * c) + x);
- Result[i].X1 := (width * x);
- Result[i].Y1 := (height * y);
- Result[i].X2 := (Result[i].X1 + (width - 1));
- Result[i].Y2 := (Result[i].Y1 + (height - 1));
- if a then
- if (y = (r - 1)) then
- Result[i].Y2 := bx.Y2;
- if b then
- if (x = (c - 1)) then
- Result[i].X2 := bx.X2;
- end;
- end else
- SetLength(Result, 0);
- end;
- var
- bmp: TSCARBitmap;
- bxs: TBoxArray;
- h, i: Integer;
- begin
- bmp := TSCARBitmap.Create('');
- bmp.SetSize(500, 500);
- area := Box(0, 0, 99, 99);
- width := 33;
- height := 33;
- bxs := BoxPartition(area, width, height);
- h := High(bxs);
- for i := 0 to h do
- WriteLn(BoxToStr(bxs[i]) + ' [' + IntToStr((bxs[i].X2 - bxs[i].X1) + 1) + 'x' + IntToStr((bxs[i].Y2 - bxs[i].Y1) + 1) + ']');
- bmp.SetPixels(SSP_TPAFromTBAEdges(bxs), clRed);
- bmp.SetPixels(TPAFromBox(Box(0, 99, 32, 99)), clBlue);
- DebugBitmap(bmp);
- end.
Advertisement
Add Comment
Please, Sign In to add comment