[squeak-dev] [ENH] coercing a number to an interval
enrico.spinielli at googlemail.com
Sun Apr 25 06:39:20 UTC 2010
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
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
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!
I personally do not dislike nRightOpenInterval:
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) ?
> > Stef
"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...
More information about the Squeak-dev