Skip to content

Commit 3bf083d

Browse files
ladyadatannewt
authored andcommitted
handle reversed range on output
1 parent db9762a commit 3bf083d

File tree

1 file changed

+6
-1
lines changed

1 file changed

+6
-1
lines changed

simpleio.py

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -265,4 +265,9 @@ def map_range(x, in_min, in_max, out_min, out_max):
265265
:return: Returns value mapped to new range
266266
:rtype: float
267267
"""
268-
return max(min((x-in_min) * (out_max - out_min) / (in_max-in_min) + out_min, out_max), out_min)
268+
t = (x-in_min) * (out_max - out_min) / (in_max-in_min) + out_min
269+
if out_min <= out_max:
270+
return max(min(t, out_max), out_min)
271+
else:
272+
return min(max(t, out_max), out_min)
273+

0 commit comments

Comments
 (0)