Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
34
Task/Map-range/Fantom/map-range.fantom
Normal file
34
Task/Map-range/Fantom/map-range.fantom
Normal file
|
|
@ -0,0 +1,34 @@
|
|||
class FRange
|
||||
{
|
||||
const Float low
|
||||
const Float high
|
||||
// in constructing a range, ensure the low value is smaller than high
|
||||
new make (Float low, Float high)
|
||||
{
|
||||
this.low = ( low <= high ? low : high )
|
||||
this.high = ( low <= high ? high : low )
|
||||
}
|
||||
|
||||
// return range as a string
|
||||
override Str toStr () { "[$low,$high]" }
|
||||
|
||||
// return a point in given range interpolated into this range
|
||||
Float remap (Float point, FRange given)
|
||||
{
|
||||
this.low + (point - given.low) * (this.high - this.low) / (given.high - given.low)
|
||||
}
|
||||
}
|
||||
|
||||
class Main
|
||||
{
|
||||
public static Void main ()
|
||||
{
|
||||
range1 := FRange (0f, 10f)
|
||||
range2 := FRange (-1f, 0f)
|
||||
11.times |Int n|
|
||||
{
|
||||
m := range2.remap (n.toFloat, range1)
|
||||
echo ("Value $n in ${range1} maps to $m in ${range2}")
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue