[squeak-dev] intersect: when intsersects: is false
frank.shearar at angband.za.org
Sun Jun 20 08:36:34 UTC 2010
On 2010/06/20 00:58, Jim Rosenberg wrote:
> [Using Squeak 3.8; apologies if more current versions "fix" this ... ]
> This expression yields false:
> ((0 at 0) corner: (50 at 50)) intersects: ((100 at 100) corner: (150 at 150))
> So, what should this yield?:
> ((0 at 0) corner: (50 at 50)) intersect: ((100 at 100) corner: (150 at 150))
> I was expecting perhaps nil. Instead I got (100 at 100) corner: (50 at 50).
> This is "a surprise". It's certainly not right mathematically ...
It's still that way in trunk, at any rate.
I do think that the current behaviour's wrong.
In the interest of keeping the result of a #intersect: uniform, we could
return Rectangle origin: (0 at 0) corner: (0 at 0) instead of nil. (And we can
put that long expression inside a new method,
Rectangle>>emptyRectangle.) Then we could compose multiple #intersect:s
without special-casing anything.
I think we just need a guard clause like
| aPoint left right top bottom |
(self intersects: aRectangle) ifFalse: [^ self emptyRectangle].
"Rest of #intersect goes here."
but I'm sure Nicolas Cellier will weigh in with a definitive answer :)
More information about the Squeak-dev