Working out pixels in a grid


#1

hi

I’m trying a project for a client similar to a pixel ad site, I created a script that captures the x,y co-ordinates along with the width and height of the square created.

I’m at the stage where i need to perform a check on new purchases to make sure they do not select an area that has already been sold.

But I can not figure out how best to perform the check. The user should not be able to create an advert that falls within the any purchased areas of the grid.

But just having the x,y co-orindate and the width and height I can’t seem to get to grips with how to use these to list all the grids in the squares that are taken. Does this make sense?

If anyone thing they can help or need more info please reply or msn me at -removed-, thanks

Mod Edit: Removed email address


#2

Since we don’t want to become a favorite amongst spammers, I’ve removed the email address. This is also against our rules, and the rules of asking a question.

As for your question, how do you keep track of which pixels are already taken and which ones are not? You could just perform a comparison.


#3

for any previously purchased area the information is stored in to a mysql database table. the information stored is the x co-ordinate, the y- coordinate the square width and square height.


#4

So, if a person selects a certain area, it’s quite easy to fetch the coordinates, and use them in a SQL Query:

SELECT * FROM areas WHERE
  ((x_start <= $myXstart AND x_end >= $myXstart) OR
  (x_start >= $myXend AND x_end <= $myXend)) AND
  ((y_start <= $myYstart AND y_end >= $myYstart) OR
  (y_start >= $myYend AND y_end <= $myYend))

Or somethin like that. You have to find out which conditions hold true for two patches to overlap.


#5

thanks for that it almost works, if i drawn a square within the sold areas the error is triggered but if i drawn a square in a free square and only overlap the top right or bottom right corner the error isnt being triggered

:(

#6

So: which other conditions should hold true? This is all simple logic if you ask me. Make a drawing and indicate which X’s and Y’s you have, and which should be on which side of which to get an overlap. You’ll get a large query but it’ll be specified pretty decently.


#7

well no part of a new square should cover or overlap a square area already created, meaning all four corners should not fall within the range

if that makes sense


#8

That’s exactly what you want to achieve :slight_smile:


#9

i think its just turning into one of those problems i’ve stared at too long…


#10

Perhaps. Like I said, if you just make yourself a little sketch of what exactly should be true to get an invalid area, you’ll see that it’s easier than trying to do it without using pen 'n paper.