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):
|
def bounds(data):
|
||||||
"Returns a list of the smallest and largest numbers in data"
|
"Returns a list of the smallest and largest numbers in data"
|
||||||
lowest = None
|
return [minimum(data), maximum(data)]
|
||||||
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]
|
|
||||||
|
|
||||||
def clamp(value, low, high):
|
def clamp(value, low, high):
|
||||||
"""Clamps a value to a range from low to high.
|
"""Clamps a value to a range from low to high.
|
||||||
Returns value if it is between low and 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 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
|
return value
|
||||||
if value < low:
|
if value <= low:
|
||||||
return low
|
return low
|
||||||
if value == low:
|
if value >= high:
|
||||||
return low
|
|
||||||
if value > high:
|
|
||||||
return high
|
|
||||||
if value == high:
|
|
||||||
return high
|
return high
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue