Jump to content
  • Sky
  • Blueberry
  • Slate
  • Blackcurrant
  • Watermelon
  • Strawberry
  • Orange
  • Banana
  • Apple
  • Emerald
  • Chocolate
  • Charcoal
Janilabo

GetBoxesInBoxBySize

Recommended Posts

// Returns ALL the possible boxes by size (width*height), that exist in a box (bx).
function GetBoxesInBoxBySize(bx: TBox; width, height: Integer): TBoxArray;
var
 r, c, w, h, x, y, i: Integer;
begin
 if ((bx.X1 > bx.X2) or (bx.Y1 > bx.Y2) or (width < 1) or (height < 1)) then
   Exit;
 GetBoxSize(bx, w, h);                                                
 if ((width < (w + 1)) and (height < (h + 1))) then
 begin
   r := (h - (height - 1));
   c := (w - (width - 1));        
   SetLength(Result, (r * c));
   for y := bx.Y1 to (bx.Y1 + (r - 1)) do
     for x := bx.X1 to (bx.X1 + (c - 1)) do 
     begin     
       i := (((y - bx.Y1) * c) + (x - bx.X1));
       Result[i].X1 := x;
       Result[i].Y1 := y;
       Result[i].X2 := (x + (width - 1));
       Result[i].Y2 := (y + (height - 1));
     end;
 end;
end;

var
 h, i: Integer;
 bx: TBox; 
 TBA: TBoxArray;

begin
 ClearDebug;
 bx := Box(2, 2, 7, 7);
 TBA := GetBoxesInBoxBySize(bx, 5, 5);
 h := High(TBA);
 for i := 0 to h do
   WriteLn('TBA[' + IntToStr(i) + ']: ' + BoxToStr(TBA[i]));
 SetLength(TBA, 0); 
end.

Share this post


Link to post
Share on other sites

Nice, I need to look around these forums more. I believe a lot of the functions in here I could add to OSI. I might just add this one to Divi/Box.scar

 

Jani, I have been improving the log system greatly, but I don't know how to add Exception handling really. I think I am going to focus on that next, because it would take forever to do:

 

[scar]

try

except

WriteLn('NameOfFunction: Failed, .......');

finally

[/scar]

That for every function.

 

I believe you can pull the information about the error, and all sorts of fun stuff!

 

Expect a new thread about the new Logging changes I'm going to commit eventually. I've simplified it into functions, and a TOSILog type.

 

Whats cool is. If some1 wanted to make their own log from the TOSILog type. e.g. var Abc: TOSILog;

They can do that. But if they want to save it they need to do OSILog := TheirLog;

Autologging and everything will still work with this because OSILog is your log now.

And so you can have 2 logs saved one for OSI and one of your own. I might just make a function geared toward this.

 

You can customize everything with this type, but the format of the header in the text file. Right now its osi's header.

Might make some functions for TOSIType too. Just in case anyone does this....

Edited by LordJashin

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.


×
×
  • Create New...