-
Notifications
You must be signed in to change notification settings - Fork 4
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add a constrained parameter to map_range() #2
Add a constrained parameter to map_range() #2
Conversation
This allows for the conversion of unconstrained ranges, eg. Celsius to Fahrenheit.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Rather than add a control parameter to the original function, how about creating a new function with a different name that is an unconstrained map_range()
? It is really a particular kind of linear transformation, though getting into the linear algebra of linear transformations is beyond what most people want to cope with.
map_range()
can call this new function to do the mapping, and then do the constraining itself.
I am not sure what to call this new function. Let's think about it.
One option would simply be
|
|
Slight tangent; are you able to run the tests locally?
|
…uit#3) * Split map_range into map_range and unconstrained_map_range. * map_range will constrain the output value within the provided limits * unconstrained_map_range will only use the limits to define the linear equation * Add tests for constrain with auto-swap * Add tests for unconstrained_map_range
I figured an answer - use |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the discussion on this, and making it more useful! I asked a couple of things.
Add tests for out-of-range reversed order map_range.
While waiting for my vaccine today, I realised there's a better name for
If you want, I can change the name and do another push. |
I the sound of |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is great! Thanks for your work on this.
Updating https://github.com/adafruit/Adafruit_CircuitPython_BME280 to 2.6.1 from 2.6.0: > Merge pull request adafruit/Adafruit_CircuitPython_BME280#46 from jposada202020/improving_docs Updating https://github.com/adafruit/Adafruit_CircuitPython_BNO055 to 5.3.0 from 5.2.6: > Merge pull request adafruit/Adafruit_CircuitPython_BNO055#78 from ViennaMike/axis_remap Updating https://github.com/adafruit/Adafruit_CircuitPython_IRRemote to 4.0.6 from 4.0.5: > Merge pull request adafruit/Adafruit_CircuitPython_IRRemote#46 from kevinjwalters/tx-var-bits > "Increase duplicate code check threshold " Updating https://github.com/adafruit/Adafruit_CircuitPython_SHTC3 to 1.0.6 from 1.0.5: > Merge pull request adafruit/Adafruit_CircuitPython_SHTC3#7 from jposada202020/improving_docs > "Increase duplicate code check threshold " > Merge pull request adafruit/Adafruit_CircuitPython_SHTC3#6 from FoamyGuy/pylintrc_and_versions Updating https://github.com/adafruit/Adafruit_CircuitPython_MIDI to 1.4.0 from 1.3.5: > Added copyright information > Merge pull request adafruit/Adafruit_CircuitPython_MIDI#27 from gamblor21/add_control_values Updating https://github.com/adafruit/Adafruit_CircuitPython_SimpleMath to 2.0.0 from 1.0.2: > Merge pull request adafruit/Adafruit_CircuitPython_SimpleMath#2 from lesamouraipourpre/unconstrained-map-range > Added tests check to pre commit config > "Increase duplicate code check threshold " Updating https://github.com/adafruit/Adafruit_CircuitPython_Bundle/circuitpython_library_list.md to NA from NA: > Added the following libraries: Adafruit_CircuitPython_Colorsys
Add a constrained parameter to map_range(), defaulting to True.
This allows for the conversion of unconstrained ranges, eg. Celsius to Fahrenheit.