summaryrefslogtreecommitdiff
path: root/core
diff options
context:
space:
mode:
authorBojidar Marinov <bojidar.marinov.bg@gmail.com>2017-05-16 13:56:49 +0300
committerBojidar Marinov <bojidar.marinov.bg@gmail.com>2017-06-22 20:41:52 +0300
commit26a51c3c0b243a0c5a8317f728e256109e458956 (patch)
tree586ebaeb32f88e16852d6fbea01000b675356766 /core
parentf27d2a3355b8c577fccd961d28dd6085887623c2 (diff)
Reimplement for..in range() so that it always results in ints
Fixes #8278, fixup of bfef8de1bc4f7a7b9617a7b181881129033a0b0e
Diffstat (limited to 'core')
-rw-r--r--core/variant_op.cpp42
1 files changed, 22 insertions, 20 deletions
diff --git a/core/variant_op.cpp b/core/variant_op.cpp
index 7b2d0f6886..a463a5a23f 100644
--- a/core/variant_op.cpp
+++ b/core/variant_op.cpp
@@ -2236,30 +2236,30 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const {
return _data._int > 0;
} break;
case REAL: {
- r_iter = 0.0;
+ r_iter = 0;
return _data._real > 0.0;
} break;
case VECTOR2: {
- real_t from = reinterpret_cast<const Vector2 *>(_data._mem)->x;
- real_t to = reinterpret_cast<const Vector2 *>(_data._mem)->y;
+ int64_t from = reinterpret_cast<const Vector2 *>(_data._mem)->x;
+ int64_t to = reinterpret_cast<const Vector2 *>(_data._mem)->y;
r_iter = from;
return from < to;
} break;
case VECTOR3: {
- real_t from = reinterpret_cast<const Vector3 *>(_data._mem)->x;
- real_t to = reinterpret_cast<const Vector3 *>(_data._mem)->y;
- real_t step = reinterpret_cast<const Vector3 *>(_data._mem)->z;
+ int64_t from = reinterpret_cast<const Vector3 *>(_data._mem)->x;
+ int64_t to = reinterpret_cast<const Vector3 *>(_data._mem)->y;
+ int64_t step = reinterpret_cast<const Vector3 *>(_data._mem)->z;
r_iter = from;
if (from == to) {
return false;
} else if (from < to) {
- return step > 0.0;
+ return step > 0;
} else {
- return step < 0.0;
+ return step < 0;
}
//return true;
} break;
@@ -2387,7 +2387,6 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
valid = true;
switch (type) {
case INT: {
-
int64_t idx = r_iter;
idx++;
if (idx >= _data._int)
@@ -2396,33 +2395,36 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
return true;
} break;
case REAL: {
-
- double idx = r_iter;
- idx += 1.0;
+ int64_t idx = r_iter;
+ idx++;
if (idx >= _data._real)
return false;
r_iter = idx;
return true;
} break;
case VECTOR2: {
- real_t idx = r_iter;
- idx += 1.0;
- if (idx >= reinterpret_cast<const Vector2 *>(_data._mem)->y)
+ int64_t to = reinterpret_cast<const Vector3 *>(_data._mem)->y;
+
+ int64_t idx = r_iter;
+ idx++;
+
+ if (idx >= to)
return false;
+
r_iter = idx;
return true;
} break;
case VECTOR3: {
- real_t to = reinterpret_cast<const Vector3 *>(_data._mem)->y;
- real_t step = reinterpret_cast<const Vector3 *>(_data._mem)->z;
+ int64_t to = reinterpret_cast<const Vector3 *>(_data._mem)->y;
+ int64_t step = reinterpret_cast<const Vector3 *>(_data._mem)->z;
- real_t idx = r_iter;
+ int64_t idx = r_iter;
idx += step;
- if (step < 0.0 && idx <= to)
+ if (step < 0 && idx <= to)
return false;
- if (step > 0.0 && idx >= to)
+ if (step > 0 && idx >= to)
return false;
r_iter = idx;