Merge pull request #8783 from bojidar-bg/fix-range-loop-type

Fix for..in range() resulting in floats instead of ints
This commit is contained in:
Rémi Verschelde 2017-06-24 23:39:55 +02:00 committed by GitHub
commit 9c186a754f
2 changed files with 24 additions and 22 deletions

View File

@ -2236,30 +2236,30 @@ bool Variant::iter_init(Variant &r_iter, bool &valid) const {
return _data._int > 0; return _data._int > 0;
} break; } break;
case REAL: { case REAL: {
r_iter = 0.0; r_iter = 0;
return _data._real > 0.0; return _data._real > 0.0;
} break; } break;
case VECTOR2: { case VECTOR2: {
real_t from = reinterpret_cast<const Vector2 *>(_data._mem)->x; int64_t from = reinterpret_cast<const Vector2 *>(_data._mem)->x;
real_t to = reinterpret_cast<const Vector2 *>(_data._mem)->y; int64_t to = reinterpret_cast<const Vector2 *>(_data._mem)->y;
r_iter = from; r_iter = from;
return from < to; return from < to;
} break; } break;
case VECTOR3: { case VECTOR3: {
real_t from = reinterpret_cast<const Vector3 *>(_data._mem)->x; int64_t from = reinterpret_cast<const Vector3 *>(_data._mem)->x;
real_t to = reinterpret_cast<const Vector3 *>(_data._mem)->y; int64_t to = reinterpret_cast<const Vector3 *>(_data._mem)->y;
real_t step = reinterpret_cast<const Vector3 *>(_data._mem)->z; int64_t step = reinterpret_cast<const Vector3 *>(_data._mem)->z;
r_iter = from; r_iter = from;
if (from == to) { if (from == to) {
return false; return false;
} else if (from < to) { } else if (from < to) {
return step > 0.0; return step > 0;
} else { } else {
return step < 0.0; return step < 0;
} }
//return true; //return true;
} break; } break;
@ -2387,7 +2387,6 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
valid = true; valid = true;
switch (type) { switch (type) {
case INT: { case INT: {
int64_t idx = r_iter; int64_t idx = r_iter;
idx++; idx++;
if (idx >= _data._int) if (idx >= _data._int)
@ -2396,33 +2395,36 @@ bool Variant::iter_next(Variant &r_iter, bool &valid) const {
return true; return true;
} break; } break;
case REAL: { case REAL: {
int64_t idx = r_iter;
double idx = r_iter; idx++;
idx += 1.0;
if (idx >= _data._real) if (idx >= _data._real)
return false; return false;
r_iter = idx; r_iter = idx;
return true; return true;
} break; } break;
case VECTOR2: { case VECTOR2: {
real_t idx = r_iter; int64_t to = reinterpret_cast<const Vector3 *>(_data._mem)->y;
idx += 1.0;
if (idx >= reinterpret_cast<const Vector2 *>(_data._mem)->y) int64_t idx = r_iter;
idx++;
if (idx >= to)
return false; return false;
r_iter = idx; r_iter = idx;
return true; return true;
} break; } break;
case VECTOR3: { case VECTOR3: {
real_t to = reinterpret_cast<const Vector3 *>(_data._mem)->y; int64_t to = reinterpret_cast<const Vector3 *>(_data._mem)->y;
real_t step = reinterpret_cast<const Vector3 *>(_data._mem)->z; int64_t step = reinterpret_cast<const Vector3 *>(_data._mem)->z;
real_t idx = r_iter; int64_t idx = r_iter;
idx += step; idx += step;
if (step < 0.0 && idx <= to) if (step < 0 && idx <= to)
return false; return false;
if (step > 0.0 && idx >= to) if (step > 0 && idx >= to)
return false; return false;
r_iter = idx; r_iter = idx;

View File

@ -2626,7 +2626,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) {
ConstantNode *cn = alloc_node<ConstantNode>(); ConstantNode *cn = alloc_node<ConstantNode>();
switch (args.size()) { switch (args.size()) {
case 1: cn->value = constants[0]; break; case 1: cn->value = (int)constants[0]; break;
case 2: cn->value = Vector2(constants[0], constants[1]); break; case 2: cn->value = Vector2(constants[0], constants[1]); break;
case 3: cn->value = Vector3(constants[0], constants[1], constants[2]); break; case 3: cn->value = Vector3(constants[0], constants[1], constants[2]); break;
} }
@ -2639,7 +2639,7 @@ void GDParser::_parse_block(BlockNode *p_block, bool p_static) {
on->arguments.push_back(tn); on->arguments.push_back(tn);
switch (args.size()) { switch (args.size()) {
case 1: tn->vtype = Variant::REAL; break; case 1: tn->vtype = Variant::INT; break;
case 2: tn->vtype = Variant::VECTOR2; break; case 2: tn->vtype = Variant::VECTOR2; break;
case 3: tn->vtype = Variant::VECTOR3; break; case 3: tn->vtype = Variant::VECTOR3; break;
} }