diff options
author | Ninni Pipping <over999ships@gmail.com> | 2023-03-14 14:11:05 +0100 |
---|---|---|
committer | Ninni Pipping <over999ships@gmail.com> | 2023-03-14 15:46:45 +0100 |
commit | 10f385fb792dc74ffb8be221fec88ba9ef7aaa25 (patch) | |
tree | eb7bffa9a5a3bd98930f4cab070f5998e17a4dbf /core/variant/array.cpp | |
parent | 79454bfd3b218f5d2b2bb1da2013a3f359615d63 (diff) | |
download | redot-engine-10f385fb792dc74ffb8be221fec88ba9ef7aaa25.tar.gz |
Fix `Array.slice()` rounding for `abs(step) != 1`
Diffstat (limited to 'core/variant/array.cpp')
-rw-r--r-- | core/variant/array.cpp | 2 |
1 files changed, 1 insertions, 1 deletions
diff --git a/core/variant/array.cpp b/core/variant/array.cpp index d156c35343..5215142dd3 100644 --- a/core/variant/array.cpp +++ b/core/variant/array.cpp @@ -466,7 +466,7 @@ Array Array::slice(int p_begin, int p_end, int p_step, bool p_deep) const { ERR_FAIL_COND_V_MSG(p_step > 0 && begin > end, result, "Slice is positive, but bounds is decreasing."); ERR_FAIL_COND_V_MSG(p_step < 0 && begin < end, result, "Slice is negative, but bounds is increasing."); - int result_size = (end - begin) / p_step; + int result_size = (end - begin) / p_step + (((end - begin) % p_step != 0) ? 1 : 0); result.resize(result_size); for (int src_idx = begin, dest_idx = 0; dest_idx < result_size; ++dest_idx) { |