[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

Re: [pygame] Merge: rect optimisation



Hi,

thanks Sam :)

This change is finally pulled in.

On Wed, Oct 17, 2012 at 6:45 PM, Christopher Night <cosmologicon@xxxxxxxxx> wrote:
Yeah your new test is correct. I'm surprised it wasn't done that way to begin with, actually. The inequality comparisons you have are correct for pygame's definition of a rectangle.

FWIW, I would swap the ordering of the 2nd and 3rd test as you have them. From a probabilistic argument, this will tend to get you earlier short-circuiting, though the difference here is going to be very small.

-Christopher


On Wed, Oct 17, 2012 at 10:06 AM, Sam Bull <sam.hacking@xxxxxxxx> wrote:
Can somebody check the code I've proposed for a merge, I believe it is a
more efficient method for checking rect intersection:

https://bitbucket.org/pygame/pygame/pull-request/11/optimise-rect-intersection/diff

The theory is that if (A.topleft < B.bottomright and A.bottomright >
B.topleft) then they must be overlapping. This needs about half the
tests from the current version.

I also wasn't sure where to put "<=" instead of "<" to ensure perfect
backwards compatibility, so it would be great if anybody could point
that out too.

Thanks,
Sam Bull