Skip to content

Commit 84f4042

Browse files
committed
Merge pull request godotengine#93740 from markdibarry/alternative-pixel-rounding
Replace pixel rounding with `floor(x + 0.5)`
2 parents a19955e + 6b17d51 commit 84f4042

File tree

4 files changed

+6
-6
lines changed

4 files changed

+6
-6
lines changed

scene/2d/animated_sprite_2d.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -267,7 +267,7 @@ void AnimatedSprite2D::_notification(int p_what) {
267267
}
268268

269269
if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) {
270-
ofs = ofs.round();
270+
ofs = (ofs + Point2(0.5, 0.5)).floor();
271271
}
272272

273273
Rect2 dst_rect(ofs, s);

scene/2d/sprite_2d.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,7 @@ void Sprite2D::_get_rects(Rect2 &r_src_rect, Rect2 &r_dst_rect, bool &r_filter_c
9898
}
9999

100100
if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) {
101-
dest_offset = dest_offset.round();
101+
dest_offset = (dest_offset + Point2(0.5, 0.5)).floor();
102102
}
103103

104104
r_dst_rect = Rect2(dest_offset, frame_size);
@@ -400,7 +400,7 @@ Rect2 Sprite2D::get_rect() const {
400400
}
401401

402402
if (get_viewport() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) {
403-
ofs = ofs.round();
403+
ofs = (ofs + Point2(0.5, 0.5)).floor();
404404
}
405405

406406
if (s == Size2(0, 0)) {

scene/gui/rich_text_label.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1249,7 +1249,7 @@ int RichTextLabel::_draw_line(ItemFrame *p_frame, int p_line, const Vector2 &p_o
12491249
}
12501250

12511251
if (is_inside_tree() && get_viewport()->is_snap_2d_transforms_to_pixel_enabled()) {
1252-
fx_offset = fx_offset.round();
1252+
fx_offset = (fx_offset + Point2(0.5, 0.5)).floor();
12531253
}
12541254

12551255
Vector2 char_off = char_xform.get_origin();

servers/rendering/renderer_canvas_cull.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -284,8 +284,8 @@ void RendererCanvasCull::_cull_canvas_item(Item *p_canvas_item, const Transform2
284284
}
285285

286286
if (snapping_2d_transforms_to_pixel) {
287-
final_xform.columns[2] = final_xform.columns[2].round();
288-
parent_xform.columns[2] = parent_xform.columns[2].round();
287+
final_xform.columns[2] = (final_xform.columns[2] + Point2(0.5, 0.5)).floor();
288+
parent_xform.columns[2] = (parent_xform.columns[2] + Point2(0.5, 0.5)).floor();
289289
}
290290

291291
final_xform = parent_xform * final_xform;

0 commit comments

Comments
 (0)