Janilabo

Untitled

Sep 10th, 2013
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Pascal 1.53 KB | None | 0 0
  1. {$L SSP.dll}
  2.  
  3. var
  4.   area: TBox;
  5.   width, height: Integer;
  6.  
  7. function BoxPartition(bx: TBox; width, height: Integer): TBoxArray;
  8. var
  9.   r, c, x, y, i: Integer;
  10.   er, ec: Extended;
  11.   a, b: Boolean;
  12. begin
  13.   if ((width > 0) and (height > 0)) then
  14.   begin      
  15.     er := (((area.Y2 - area.Y1) + 1) / height);
  16.     ec := (((area.X2 - area.X1) + 1) / width);
  17.     r := Ceil(er);
  18.     c := Ceil(ec);
  19.     SetLength(Result, (r * c));
  20.     a := (er <> r);
  21.     b := (ec <> c);
  22.     for y := 0 to (r - 1) do
  23.       for x := 0 to (c - 1) do
  24.       begin
  25.         i := ((y * c) + x);
  26.         Result[i].X1 := (width * x);
  27.         Result[i].Y1 := (height * y);
  28.         Result[i].X2 := (Result[i].X1 + (width - 1));
  29.         Result[i].Y2 := (Result[i].Y1 + (height - 1));
  30.         if a then
  31.           if (y = (r - 1)) then
  32.             Result[i].Y2 := bx.Y2;
  33.         if b then
  34.           if (x = (c - 1)) then
  35.             Result[i].X2 := bx.X2;
  36.       end;    
  37.   end else
  38.     SetLength(Result, 0);  
  39. end;
  40.  
  41. var
  42.   bmp: TSCARBitmap;
  43.   bxs: TBoxArray;
  44.   h, i: Integer;
  45.  
  46. begin
  47.   bmp := TSCARBitmap.Create('');
  48.   bmp.SetSize(500, 500);
  49.   area := Box(0, 0, 99, 99);
  50.   width := 33;
  51.   height := 33;      
  52.   bxs := BoxPartition(area, width, height);
  53.   h := High(bxs);
  54.   for i := 0 to h do
  55.     WriteLn(BoxToStr(bxs[i]) + ' [' + IntToStr((bxs[i].X2 - bxs[i].X1) + 1) + 'x' + IntToStr((bxs[i].Y2 - bxs[i].Y1) + 1) + ']');
  56.   bmp.SetPixels(SSP_TPAFromTBAEdges(bxs), clRed);
  57.   bmp.SetPixels(TPAFromBox(Box(0, 99, 32, 99)), clBlue);
  58.   DebugBitmap(bmp);
  59. end.
Advertisement
Add Comment
Please, Sign In to add comment