Double dispatching and Point

David N. Smith dnsmith at watson.ibm.com
Mon Feb 2 20:10:43 UTC 1998


At 13:37 -0500 2/2/98, Travis Griggs wrote:
>Good points. I have never found any use for the Point < method as defined. I
>have had reason to sort Points quite often, and have always done so using the
>following sort block:
>
>[:a :b | a y = b y ifTrue: [a x < b x] ifFalse: [a y < b y]]
>
>True, it establishes a convention, but I've never wanted ambiguous sorting of
>Points. Why not change the definition of < for Point. Does anyone use it to
>their benefit as implemented now, and in such a way that would make the above
>undesireable?


Some random thoughts (sorted):


(1) Well, an inside rectangle test is something like:

   (p1 >= p origin) & (p1 <= p corner)

(which is the definition of #between:and: in IBM Smalltalk, but not in Squeak).


(2) Making such a change would be incompatible with other Smalltalk systems
(and the new almost-standard if I recall correctly).


(3) One thing bothers me about your sort block is that it presumes that
points are lineralized along the Y axis. That is, a < b if its y value is
less. Only if they are equal are the x values considered.

   | lessThan |
   lessThan := [:a :b |
       a y = b y
         ifTrue:  [a x < b x]
         ifFalse: [a y < b y]].
   lessThan value: 6 at 3 value: 4 at 5
 true

This result just looks odd to me: a value with a higher x coordinate being
less than one with a lower coordinate.

I guess the first test could use x coordinates, and I'd feel better, but
why one over the other?


(4) How about testing some other value, like the magnitude of the point
(thinking in polar coordinates for a moment)? This isn't too slow if one
compares the squares of the coordinates and fakes the signs.


(5) Points are holders for numbers. One can well have a point with floating
point or fraction values, or a mixture. This is quite valid:

   (2/3)@7.5

Some contexts may assume that points have integer coordinates, but that's
their problem. If you add Point to some number hierarchy, what kind of
coordinates classes are allowed? This is valid now:

   ((2/3)@7.5) * (2/3)

   Produces: (4/9)@5.0

Would it still be? Should it be valid now?


Dave



_______________________________
David N. Smith
IBM T J Watson Research Center
Hawthorne, NY
_______________________________
Any opinions or recommendations
herein are those of the author
and not of his employer.





More information about the Squeak-dev mailing list