Merge pull request #282 from RameshRavone/patch-3

Fix snapped from Vector2
pull/286/head
Bastiaan Olij 2019-05-02 23:00:25 +10:00 committed by GitHub
commit 877de75d8b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 5 additions and 7 deletions

View File

@ -208,7 +208,11 @@ struct Vector2 {
return Vector2(::floor(x), ::floor(y));
}
inline Vector2 snapped(const Vector2 &p_by) const;
inline Vector2 snapped(const Vector2 &p_by) const {
return Vector2(
p_by.x != 0 ? ::floor(x / p_by.x + 0.5) * p_by.x : x,
p_by.y != 0 ? ::floor(y / p_by.y + 0.5) * p_by.y : y);
}
inline real_t aspect() const { return width / height; }

View File

@ -54,12 +54,6 @@ Vector2 Vector2::cubic_interpolate(const Vector2 &p_b, const Vector2 &p_pre_a, c
return out;
}
Vector2 Vector2::snapped(const Vector2 &p_by) const {
return Vector2(
p_by.x != 0 ? ::floor(x / p_by.x + 0.5) * p_by.x : x,
p_by.y != 0 ? ::floor(y / p_by.y + 0.5) * p_by.y : y);
}
Vector2::operator String() const {
return String::num(x) + ", " + String::num(y);
}