Last active
December 28, 2021 06:48
-
-
Save Dioarya/7d84323f0a0b456296c35a1d5569680a to your computer and use it in GitHub Desktop.
ranged modulo
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
def rmod(v: float, minimum: float, maximum: float) -> float: | |
"""modulo with minimum and maximum range | |
Args: | |
v (float): value | |
minimum (float): minimum | |
maximum (float): maximum | |
Returns: | |
float: result | |
""" | |
if minimum == 0: | |
return v % maximum | |
t = ((v - minimum) / (maximum - minimum)) % 1 # Inverse lerp | |
return (1 - t) * minimum + t * maximum # Lerp |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment