Skip to content

Commit d85ddb0

Browse files
BenKirkelsbehacklJasonGrace2282
authored
refactor: improved consistency of rate_functions (#4144)
Co-authored-by: Benjamin Hackl <[email protected]> Co-authored-by: Aarush Deshpande <[email protected]>
1 parent cd2a3b9 commit d85ddb0

File tree

1 file changed

+6
-8
lines changed

1 file changed

+6
-8
lines changed

Diff for: manim/utils/rate_functions.py

+6-8
Original file line numberDiff line numberDiff line change
@@ -161,33 +161,31 @@ def smooth(t: float, inflection: float = 10.0) -> float:
161161
)
162162

163163

164+
@unit_interval
164165
def smoothstep(t: float) -> float:
165166
"""Implementation of the 1st order SmoothStep sigmoid function.
166167
The 1st derivative (speed) is zero at the endpoints.
167168
https://en.wikipedia.org/wiki/Smoothstep
168169
"""
169-
return 0 if t <= 0 else 3 * t**2 - 2 * t**3 if t < 1 else 1
170+
return 3 * t**2 - 2 * t**3
170171

171172

173+
@unit_interval
172174
def smootherstep(t: float) -> float:
173175
"""Implementation of the 2nd order SmoothStep sigmoid function.
174176
The 1st and 2nd derivatives (speed and acceleration) are zero at the endpoints.
175177
https://en.wikipedia.org/wiki/Smoothstep
176178
"""
177-
return 0 if t <= 0 else 6 * t**5 - 15 * t**4 + 10 * t**3 if t < 1 else 1
179+
return 6 * t**5 - 15 * t**4 + 10 * t**3
178180

179181

182+
@unit_interval
180183
def smoothererstep(t: float) -> float:
181184
"""Implementation of the 3rd order SmoothStep sigmoid function.
182185
The 1st, 2nd and 3rd derivatives (speed, acceleration and jerk) are zero at the endpoints.
183186
https://en.wikipedia.org/wiki/Smoothstep
184187
"""
185-
alpha: float = 0
186-
if 0 < t < 1:
187-
alpha = 35 * t**4 - 84 * t**5 + 70 * t**6 - 20 * t**7
188-
elif t >= 1:
189-
alpha = 1
190-
return alpha
188+
return 35 * t**4 - 84 * t**5 + 70 * t**6 - 20 * t**7
191189

192190

193191
@unit_interval

0 commit comments

Comments
 (0)