Janilabo Posted October 18, 2012 Share Posted October 18, 2012 // 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. Quote Link to comment Share on other sites More sharing options...
LordJashin Posted October 18, 2012 Share Posted October 18, 2012 (edited) 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 October 18, 2012 by LordJashin Quote Link to comment Share on other sites More sharing options...