Skip to content

Commit

Permalink
Replace floor() with round() in pixel snap to transform
Browse files Browse the repository at this point in the history
  • Loading branch information
KeyboardDanni committed Jan 10, 2024
1 parent 3524346 commit c329467
Show file tree
Hide file tree
Showing 4 changed files with 6 additions and 6 deletions.
2 changes: 1 addition & 1 deletion scene/2d/animated_sprite_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ void AnimatedSprite2D::_notification(int p_what) {
}

if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) {
ofs = ofs.floor();
ofs = ofs.round();
}
Rect2 dst_rect(ofs, s);

Expand Down
4 changes: 2 additions & 2 deletions scene/2d/sprite_2d.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ void Sprite2D::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_c
}

if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) {
dest_offset = dest_offset.floor();
dest_offset = dest_offset.round();
}

r_dst_rect = Rect2(dest_offset, frame_size);
Expand Down Expand Up @@ -402,7 +402,7 @@ Rect2 Sprite2D::get_rect() const {
}

if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) {
ofs = ofs.floor();
ofs = ofs.round();
}

if (s == Size2(0, 0)) {
Expand Down
2 changes: 1 addition & 1 deletion servers/rendering/renderer_canvas_cull.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -249,7 +249,7 @@ void RendererCanvasCull::_cull_canvas_item(Item *p_canvas_item, const Transform2

Transform2D xform = ci->xform;
if (snapping_2d_transforms_to_pixel) {
xform.columns[2] = xform.columns[2].floor();
xform.columns[2] = xform.columns[2].round();
}
xform = p_transform * xform;

Expand Down
4 changes: 2 additions & 2 deletions servers/rendering/renderer_viewport.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ static Transform2D _canvas_get_transform(RendererViewport::Viewport *p_viewport,
if (p_viewport->canvas_map.has(p_canvas->parent)) {
Transform2D c_xform = p_viewport->canvas_map[p_canvas->parent].transform;
if (p_viewport->snap_2d_transforms_to_pixel) {
c_xform.columns[2] = c_xform.columns[2].floor();
c_xform.columns[2] = c_xform.columns[2].round();
}
xf = xf * c_xform;
scale = p_canvas->parent_scale;
Expand All @@ -53,7 +53,7 @@ static Transform2D _canvas_get_transform(RendererViewport::Viewport *p_viewport,
Transform2D c_xform = p_canvas_data->transform;

if (p_viewport->snap_2d_transforms_to_pixel) {
c_xform.columns[2] = c_xform.columns[2].floor();
c_xform.columns[2] = c_xform.columns[2].round();
}

xf = xf * c_xform;
Expand Down

0 comments on commit c329467

Please sign in to comment.