One critical piece of code on my application involves enumerating all rectangles on a 2-D surface. The rectangles do not intersect each other and I must be able to enumerate all rectangles within a given rectangular boundary.
I already have a function to return the rectangle for a given coordinate, if it exists
GetRectangle( int row, int col )
Here is how I would call the resulting code.
foreach( var rect in GetRectangles( row, col, rowCount, colCount ) ) {
//.. my processing code here
}
Obviously, I could call the function GetRectangle() for each of the points in the surface. I can also skip the width of the rectangle that was returned from the previous call as I know that they do not intersect. But, this is still not efficient enough.
Are you aware of such an algorithm?
UPDATE: The surface is not necessarily covered by rectangles but it can be for some special cases. So, the function GetRectangle( int row, int col ) might return null.
Think of the surface as a bitmap filled with random rectangles (which don't intersect). The task is to return all rectangles on that surface that falls within (i.e. intersects) a given frame. Hope this will clarify the question.
Thanks
