I think there's a bug in tiles.RectMap.get_in_region.
Look at the attached image.
Black lines are pixels, gray lines are tiles. Blue squares represent a rect 
passed to tiles.RectMap.get_in_region (5, 8, 8, 12). Green squares are in 
tiles that should be and are returned by the function. Red squares are in 
tiles that are returned though they shouldn't.

The culprits are these lines:
x2 = min(len(self.cells), (x2 - ox) // self.tw + 1)
y2 = min(len(self.cells[0]), (y2 - oy) // self.th + 1)

More specifically, this part:
(x2 - ox) // self.tw + 1
(y2 - oy) // self.th + 1

In this example len(self.cells) is 9, x2 is 8, ox is 0 and self.tw is 2 so:
min(len(self.cells), (x2 - ox) // self.tw + 1)
evaluates to 5.

When the cells are returned, they are returned from 2 (which is max(0, (x1 
- ox) // self.tw) which is OK) to 5, that is cells 2, 3 and 4; one cell too 
many.

Same thing happens for the y axis.

The solution I found is the following:
x2 = min(len(self.cells), math.ceil(float(x2 - ox) / self.tw))
y2 = min(len(self.cells[0]), math.ceil(float(y2 - oy) / self.th))

In this example, the first equation is:
4 for x2 = 8
4 for x2 = 7
3 for x2 = 6
5 for x2 = 8.1

Which is perfect if I'm not mistaken.

-- 
You received this message because you are subscribed to the Google Groups 
"cocos2d discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/cocos-discuss?hl=en.
For more options, visit https://groups.google.com/groups/opt_out.


<<attachment: grid.png>>

Reply via email to