[squeak-dev] [ENH] coercing a number to an interval

Enrico Spinielli enrico.spinielli at googlemail.com
Sun Apr 25 06:39:20 UTC 2010


Yes,
naming has been my major problem with this...in fact to be complete
the name should take into account that with the above definition the
interval is right open

coerceRangeToRightOpenIntervalFrom:to:

verbose, uh?
But if we want to implement the complementary definition

x mod (a .. b]

there is the need for such distinction.
Given the following property

x mod (a .. b]  = x mod [b .. a)

the implementation is trivial:

Number>>coerceRangeToLeftOpenIntervalFrom:min to: max

"x mod (a .. b]  = x mod [b .. a)"


^self coerceRangeToRightOpenIntervalFrom:max to: min



coerceRangeToRightIntervalFrom:to: could be a very nice addition for Point
(and classes implementing \\?)
to make things like the following possible:

(110 at 120) coerceToRangeFrom: (11 at 71) to: (50 at 60) .  ->  32 at 65


i.e. like having an infinite space and recenter position within the view
bounds
see

Morph>>wrap where newX and newY are set.


Another example for wrapping:

TextMorph>>cursorWrapped:  (this is not with Point)



Now the name is hard to select!

inInterval:
inRightOpenInterval:
withinInterval:
withinRightOpenInterval
...


I personally do not dislike nRightOpenInterval:

Bye
Enrico

On Sat, Apr 24, 2010 at 21:44, Nicolas Cellier <
nicolas.cellier.aka.nice at gmail.com> wrote:

> 2010/4/24 Stéphane Rollandin <lecteur at zogotounga.net>:
> >> Hmm... #coerceToInterval: sounds like converting something into an
> >> instance of Interval..
> >> so, maybe there could be some other names, like
> >>  #putOnInterval:
> >>  #withinInterval:
> >>
> >> 359 withinInterval: (-90 to: 90)
> >
> > 359 moduloInterval: (-90 to: 90)   ?
> >
>
> +1
>
> > Stef
> >
> >
> >
> >
>
>


-- 
Enrico Spinielli
"Do Androids dream of electric sheep?"— Philip K. Dick
"Hear and forget; see and remember;do and understand."—Mitchel Resnick
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.squeakfoundation.org/pipermail/squeak-dev/attachments/20100425/247301e2/attachment.htm


More information about the Squeak-dev mailing list