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 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 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 >> > >
Re: [pygame] Merge: rect optimisation
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 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 >
[pygame] Merge: rect optimisation
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 signature.asc Description: This is a digitally signed message part