Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {$I SimbaExt/SimbaExt.simba}
- (* Meh *)
- function SquareBoxes(Box:TBox; n:Int32): TBoxArray;
- var
- W,H,bW,bH,i,j,l,size:Int32;
- wmax,hmax,sx,sy,x,y:Double;
- begin
- W := Box.x2 - Box.x1;
- H := Box.y2 - Box.y1;
- wMax := Ceil(Sqrt(n * W/H));
- hMax := Ceil(Sqrt(n * H/W));
- if (Trunc(wMax*H/W)*wMax < n) then sx := H/Ceil(wMax*H/W)
- else sx := W/wMax;
- if (Trunc(hMax*W/H)*hMax < n) then sy := W/Ceil(hMax*W/H)
- else sy := H/hMax;
- size := Trunc(MaxE(sx,sy));
- SetLength(Result,n);
- if W > H then begin
- bH := H div size;
- bW := Ceil(n / bH);
- sx := (W / bW) - size;
- sy := (H / bH) - size;
- x := Box.x1 + sx/2;
- for i:=0 to bW-1 do
- begin
- y := Box.y1 + sy/2;
- for j:=0 to bH-1 do
- begin
- Result[l] := [Round(x),Round(y),Round(x)+size,Round(y)+size];
- inc(l);
- if (l = n) then Exit();
- y += size + sy;
- end;
- x += size + sx;
- end;
- end else begin
- bW := W div size;
- bH := Ceil(n / bW);
- sx := (W / bW) - size;
- sy := (H / bH) - size;
- y := Box.Y1 + sy/2;
- for i:=0 to bH-1 do
- begin
- x := Box.X1 + sx/2;
- for j:=0 to bW-1 do
- begin
- Result[l] := [Round(x),Round(y),Round(x)+size,Round(y)+size];
- inc(l);
- if (l = n) then Exit();
- x += size + sx;
- end;
- y += size + sy;;
- end;
- end;
- end;
- (*---| test |------------------------------------*)
- var
- B:TBox;
- Arr:TBoxArray;
- BMP:TRafBitmap;
- i:Int32;
- begin
- B := [100,100,430,199];
- Arr := SquareBoxes(B,23);
- BMP.Create(500,500,$FFFFFF);
- BMP.SetPixels(TPAFromBox(B), $FFAA55);
- for i:=0 to High(Arr) do
- begin
- BMP.SetPixels(TPAFromBox(Arr[i]), $22AAFF);
- BMP.SetPixels(EdgeFromBox(Arr[i]), $FFFFFF);
- end;
- BMP.SetPixels(EdgeFromBox(B), $000000);
- BMP.Debug();
- BMP.Free();
- end.
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement