summaryrefslogtreecommitdiffstats
path: root/scene/2d
diff options
context:
space:
mode:
authorkleonc <9283098+kleonc@users.noreply.github.com>2021-05-02 23:34:51 +0200
committerkleonc <9283098+kleonc@users.noreply.github.com>2021-05-02 23:34:51 +0200
commitf1420c7cbfa778da0b2f1e35373044cd0e59b9d0 (patch)
treeec02c21f7a1c08fc5c73a232a196c598e94a82bb /scene/2d
parent8abd50359ba7b5af38a4ceedba287b4459e5f925 (diff)
downloadredot-engine-f1420c7cbfa778da0b2f1e35373044cd0e59b9d0.tar.gz
TileMap::world_to_map Ensure half offset is added according to the returned value
Decide whether half offset should be added based on the value used for calculating the return value of this method.
Diffstat (limited to 'scene/2d')
-rw-r--r--scene/2d/tile_map.cpp11
1 files changed, 6 insertions, 5 deletions
diff --git a/scene/2d/tile_map.cpp b/scene/2d/tile_map.cpp
index 4565543ec3..532a795b7c 100644
--- a/scene/2d/tile_map.cpp
+++ b/scene/2d/tile_map.cpp
@@ -1526,6 +1526,12 @@ Vector2 TileMap::map_to_world(const Vector2 &p_pos, bool p_ignore_ofs) const {
Vector2 TileMap::world_to_map(const Vector2 &p_pos) const {
Vector2 ret = get_cell_transform().affine_inverse().xform(p_pos);
+ // Account for precision errors on the border (GH-23250).
+ // 0.00005 is 5*CMP_EPSILON, results would start being unpredictable if
+ // cell size is > 15,000, but we can hardly have more precision anyway with
+ // floating point.
+ ret += Vector2(0.00005, 0.00005);
+
switch (half_offset) {
case HALF_OFFSET_X: {
if (int(floor(ret.y)) & 1) {
@@ -1552,11 +1558,6 @@ Vector2 TileMap::world_to_map(const Vector2 &p_pos) const {
}
}
- // Account for precision errors on the border (GH-23250).
- // 0.00005 is 5*CMP_EPSILON, results would start being unpredictable if
- // cell size is > 15,000, but we can hardly have more precision anyway with
- // floating point.
- ret += Vector2(0.00005, 0.00005);
return ret.floor();
}