Skip to content

Commit 4ae9cee

Browse files
tychedeliacatilac
authored andcommitted
Add bounds flag.
1 parent 71a0b49 commit 4ae9cee

1 file changed

Lines changed: 7 additions & 2 deletions

File tree

  • crates/processing_pyo3/mewnala

crates/processing_pyo3/mewnala/math.py

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -43,8 +43,13 @@ def norm(value, start, stop):
4343
return (value - start) / (stop - start)
4444

4545

46-
def remap(value, start1, stop1, start2, stop2):
47-
return start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1))
46+
def remap(value, start1, stop1, start2, stop2, within_bounds=False):
47+
mapped = start2 + (stop2 - start2) * ((value - start1) / (stop1 - start1))
48+
if not within_bounds:
49+
return mapped
50+
if start2 < stop2:
51+
return constrain(mapped, start2, stop2)
52+
return constrain(mapped, stop2, start2)
4853

4954

5055
def mag(*args):

0 commit comments

Comments
 (0)