Closed
Description
The behaviour when the min_value
and max_value
parameters are swapped is non-obvious.
from adafruit_simplemath import constrain
print(constrain(-5, 0, 10)) # Outputs 0, as expected
print(constrain(5, 0, 10)) # Outputs 5, as expected
print(constrain(15, 0, 10)) # Outputs 10, as expected
print(constrain(-5, 10, 0)) # Outputs 10
print(constrain(5, 10, 0)) # Outputs 10
print(constrain(15, 10, 0)) # Outputs 10
I think it should either
- raise an exception if they are swapped
- auto-swap the values
- add an
exception
parameter defaulted toFalse
, which will auto-swap ifFalse
and raise an exception ifTrue
My personal preference is to auto-swap the value, because it 'just works'.
I can create a PR if there is a consensus reached.
Metadata
Metadata
Assignees
Labels
No labels