Welcome Guest ( Log In | Register )

[ Big| Medium| Small] -



Post new topic Reply to topic  [ 4 posts ] 
Sarkilas
  Thu Feb 02, 2012 3:34 pm
User avatar
Member

Location: Norway
This problem is something I don't seem to be able to wrap my head around. It's not an error or anything, it's just that my mind doesn't seem to let me find a suitable way to do this.

What I am trying to do is, first, based on some coordinate data, the code generates a list of rectangles, all within the screen's bounds. This first part is fine, no problems here.
But now, what I want to do next, is to get all the rectangles of the portions of the screen that was not used by the first list.

An example, assuming that the resolution is 1920x1080 and we have one rectangle in the first list with the following data:
x = 600, y = 240, width = height = 64

The rectangles that should be generated in the second list should cover the remaining portions of the screen, thus the list should contain:
Rect1: x = 0, y = 0, width = 1920, height = 600
Rect2: x = 0, y = 240, width = 600, height = 840
Rect3: x = 664, y = 240, width = 1256, height = 840
Rect4: x = 600, y = 304, width = 600, height = 776
(This was taken from rough assumption, I reckon these should fill the remaining portions)

To clarify:
  • The rectangles that fill the screen must NOT overlap a single pixel of the rectangles in the first list.
  • Every pixel of the screen must be covered in rectangles from either the first or the second list.
  • The first list can contain anything from none to 500 rectangles. So it must be dynamic.

Any help on this?

Thanks in advance.

_________________
Well..


Last edited by Sarkilas on Fri Feb 03, 2012 4:24 pm, edited 1 time in total.

Top Top
 Profile  
 

Vergessen
  Thu Feb 02, 2012 5:19 pm
Smile, you never know when you are on camera!
User avatar

Location: Hell(Bahrain)
man this sounds like a fun problem to solve, wish i had time

_________________
Lazy attempt at a signature thingy, will make a nice one when i have a name, until then please take a look :D
Image


Top Top
 Profile  
 

Brewmeister
  Fri Feb 03, 2012 12:46 pm
Paste above Main
User avatar

Location: 42.682152 N 82.970488 W
An iterative algorithm. (Iterations <= number of rectangles in first list)

First, order the first list either left to right (X), or top to bottom (Y).
Using left to right...

build the first new rect to the left of the first rectangle.

Check to see if the 2nd rect falls above or below the 1st. ( X(2) < X(1) + WIDTH(1) )
Fill in the area between X(1) & X(2)

Check 3rd rect to first & 2nd... etc...

When all tests are false, start over with the last X(n) + WIDTH(n), Y(n) + HEIGHT(n) as the new starting point.

HOpe that makes sense... basically, work from top left to bottom right until it's all filled in.

I made the assumption that the rects in the first list do not overlap (share the same pixels)

_________________
"Of course that's just my opinion. I could be wrong!"


Image


Top Top
 Profile  
 

Sarkilas
  Fri Feb 03, 2012 4:23 pm
User avatar
Member

Location: Norway
Brewmeister wrote:
I made the assumption that the rects in the first list do not overlap (share the same pixels)
That is an accurate assumption.

Thanks for the reply, it served its purpose and did exactly as I wanted it to do. Thanks!

_________________
Well..


Top Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 4 posts ] 


Who is online

Users browsing this forum: No users and 2 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group
Hosted By: