Bug in Rectangle>>containsPoint:?
Tim Olson
tim at jumpnet.com
Sat Apr 25 13:03:15 UTC 1998
Hi, Chris:
>I seem to have found a bug in Rectangle. In the method
>
>containsPoint: aPoint
> "Answer whether aPoint is within the receiver."
> ^origin <= aPoint and: [aPoint < corner]
> ^^^
>
>the second comparison is a "<". I think it should be a "<=" instead.
I think the definition as it exists is correct (or at least internally
correct and consistent as used in Squeak). It's not explicitly stated
anywhere, but a Rectangle consists of the set of points bounded by its
origin and its corner, up to but not including the points on the corner's
edges (right and bottom edges).
This is because rectangles are frequently tiled, and if the exclusion
didn't exist, there would be certain points that would be members of
ajoining Rectangles, instead of belonging solely to one or the other.
However, exclusion is fundamental to things like mouse hit detection,
view layout, etc.
Think of it this way: if you are told to paint a rectangle on a tiled
floor, starting in the corner (corner: 0 at 0) and going for one tile's
length in both directions (extent: 1 at 1), you would end up with a single
tile painted, and would respond "no" to the question of whether the tile
at 1 at 1 was painted.
-- tim
More information about the Squeak-dev
mailing list
|