Skip to content

Commit 882d807

Browse files
authored
math.easing: fix in_out_back/1, add tests (#25939)
1 parent 04e4f43 commit 882d807

3 files changed

Lines changed: 16 additions & 11 deletions

File tree

‎vlib/math/easing/easing.v‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ pub fn out_back(x f64) f64 {
192192
@[inline]
193193
pub fn in_out_back(x f64) f64 {
194194
return if x < 0.5 {
195-
(pow(2.0 * x, x) * ((c2 + 1) * 2.0 * x - c2)) / 2.0
195+
(pow(2.0 * x, 2.0) * ((c2 + 1) * 2.0 * x - c2)) / 2.0
196196
} else {
197197
(pow(2.0 * x - 2.0, 2.0) * ((c2 + 1.0) * (x * 2.0 - 2.0) + c2) + 2.0) / 2.0
198198
}

‎vlib/math/easing/easing_test.v‎

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,3 +9,8 @@ fn test_linear() {
99
assert easing.linear(x) == x
1010
}
1111
}
12+
13+
fn test_in_out_back() {
14+
assert easing.in_out_back(0.333).eq_epsilon(-0.04451079425639395)
15+
assert easing.in_out_back(3).eq_epsilon(136.79638)
16+
}

‎vlib/v/slow_tests/inout/math_easing_tables.out‎

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -54,16 +54,16 @@
5454
+------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
5555
| x | linear | sine | quad | cubic | quart | quint | expo | circ | back | elastic | bounce |
5656
+------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+---------+
57-
| -0.5 | -0.500 | 0.500 | 0.500 | -0.500 | 0.500 | -0.500 | 0.000 | 0.500 | nan | -0.000 | -7.355 |
58-
| -0.4 | -0.400 | 0.345 | 0.320 | -0.256 | 0.205 | -0.164 | 0.000 | 0.200 | nan | 0.000 | -5.925 |
59-
| -0.3 | -0.300 | 0.206 | 0.180 | -0.108 | 0.065 | -0.039 | 0.000 | 0.100 | nan | -0.000 | -4.797 |
60-
| -0.2 | -0.200 | 0.095 | 0.080 | -0.032 | 0.013 | -0.005 | 0.000 | 0.042 | nan | 0.000 | -3.972 |
61-
| -0.1 | -0.100 | 0.024 | 0.020 | -0.004 | 0.001 | -0.000 | 0.000 | 0.010 | nan | -0.000 | -3.450 |
62-
| -0.0 | -0.000 | -0.000 | 0.000 | -0.000 | 0.000 | -0.000 | 0.000 | 0.000 | nan | 0.000 | 0.000 |
63-
| 0.1 | 0.100 | 0.024 | 0.020 | 0.004 | 0.001 | 0.000 | 0.002 | 0.010 | -0.799 | 0.000 | -3.046 |
64-
| 0.2 | 0.200 | 0.095 | 0.080 | 0.032 | 0.013 | 0.005 | 0.008 | 0.042 | -0.482 | -0.004 | -2.347 |
65-
| 0.3 | 0.300 | 0.206 | 0.180 | 0.108 | 0.065 | 0.039 | 0.031 | 0.100 | -0.188 | 0.024 | -2.416 |
66-
| 0.4 | 0.400 | 0.345 | 0.320 | 0.256 | 0.205 | 0.164 | 0.125 | 0.200 | 0.129 | -0.117 | 0.349 |
57+
| -0.5 | -0.500 | 0.500 | 0.500 | -0.500 | 0.500 | -0.500 | 0.000 | 0.500 | -3.095 | -0.000 | -7.355 |
58+
| -0.4 | -0.400 | 0.345 | 0.320 | -0.256 | 0.205 | -0.164 | 0.000 | 0.200 | -1.751 | 0.000 | -5.925 |
59+
| -0.3 | -0.300 | 0.206 | 0.180 | -0.108 | 0.065 | -0.039 | 0.000 | 0.100 | -0.855 | -0.000 | -4.797 |
60+
| -0.2 | -0.200 | 0.095 | 0.080 | -0.032 | 0.013 | -0.005 | 0.000 | 0.042 | -0.323 | 0.000 | -3.972 |
61+
| -0.1 | -0.100 | 0.024 | 0.020 | -0.004 | 0.001 | -0.000 | 0.000 | 0.010 | -0.066 | -0.000 | -3.450 |
62+
| -0.0 | -0.000 | -0.000 | 0.000 | -0.000 | 0.000 | -0.000 | 0.000 | 0.000 | -0.000 | 0.000 | 0.000 |
63+
| 0.1 | 0.100 | 0.024 | 0.020 | 0.004 | 0.001 | 0.000 | 0.002 | 0.010 | -0.038 | 0.000 | -3.046 |
64+
| 0.2 | 0.200 | 0.095 | 0.080 | 0.032 | 0.013 | 0.005 | 0.008 | 0.042 | -0.093 | -0.004 | -2.347 |
65+
| 0.3 | 0.300 | 0.206 | 0.180 | 0.108 | 0.065 | 0.039 | 0.031 | 0.100 | -0.079 | 0.024 | -2.416 |
66+
| 0.4 | 0.400 | 0.345 | 0.320 | 0.256 | 0.205 | 0.164 | 0.125 | 0.200 | 0.090 | -0.117 | 0.349 |
6767
| 0.5 | 0.500 | 0.500 | 0.500 | 0.500 | 0.500 | 0.500 | 1.500 | 0.500 | 0.500 | 0.500 | 0.500 |
6868
| 0.6 | 0.600 | 0.655 | 0.680 | 0.744 | 0.795 | 0.836 | 1.875 | 0.800 | 0.910 | 1.117 | 0.651 |
6969
| 0.7 | 0.700 | 0.794 | 0.820 | 0.892 | 0.935 | 0.961 | 1.969 | 0.900 | 1.079 | 0.976 | 3.416 |

0 commit comments

Comments
 (0)