generated from mwc/lab_scatter
I updated clamp and bounds.
This commit is contained in:
parent
b3603aeeb6
commit
9271a15c2c
24
transform.py
24
transform.py
|
@ -26,34 +26,18 @@ def minimum(data):
|
|||
|
||||
def bounds(data):
|
||||
"Returns a list of the smallest and largest numbers in data"
|
||||
lowest = None
|
||||
for number in data:
|
||||
if lowest is None:
|
||||
lowest = number
|
||||
if number < lowest:
|
||||
lowest = number
|
||||
highest = None
|
||||
for number in data:
|
||||
if highest is None:
|
||||
highest = number
|
||||
if number > highest:
|
||||
highest = number
|
||||
return [lowest, highest]
|
||||
return [minimum(data), maximum(data)]
|
||||
|
||||
def clamp(value, low, high):
|
||||
"""Clamps a value to a range from low to high.
|
||||
Returns value if it is between low and high.
|
||||
If value is lower than low, returns low. If value is higher than high, returns high.
|
||||
"""
|
||||
if low < value < high:
|
||||
if low < value and value < high:
|
||||
return value
|
||||
if value < low:
|
||||
if value <= low:
|
||||
return low
|
||||
if value == low:
|
||||
return low
|
||||
if value > high:
|
||||
return high
|
||||
if value == high:
|
||||
if value >= high:
|
||||
return high
|
||||
|
||||
|
||||
|
|
Loading…
Reference in New Issue