First time here? Check out the FAQ!

How can I keep a maximum distance between two normalised values?

0 votes
this is probably very simple...

I want to have a value that always keeps a fixed seperation between itself and another value on a normalised 0,1 scale

Starting with:

!min + !max

as !min goes up and the sum clips at 1, then how can I arithmetically make the !max wrap around to below the !min thereby always keeping its distance?
asked Aug 3 in Capytalk & Smalltalk by cristian-vogel (Master) (5,310 points)
not quite the answer, but this SmallTalk function will normalise to 0,1 from arbitrary min and max

"normalise an input to 0,1 clipping to a min and max"

| norm |

norm := [:value :min :max |
    | clippedToMinMax |
    clippedToMinMax := (value vmin: max) vmax: min.
    (clippedToMinMax - min) / (max - min)

norm value: !In value: !Min value: !Max
Not sure exactly how you want it to behave. Could you give a couple of numeric examples?  Thanks!

1 Answer

0 votes
How about: | min max | min := !Min clipTo01. max := min + !Distance - ((min + !Distance) gt: 1).
answered Aug 4 by kymaguy (Master) (9,050 points)