Skip to content

Commit

Permalink
Fix rounding
Browse files Browse the repository at this point in the history
  • Loading branch information
emilk committed Dec 16, 2024
1 parent a41b732 commit 204318a
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions crates/epaint/src/tessellator.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1277,6 +1277,11 @@ impl Tessellator {
((point * self.pixels_per_point - 0.5).round() + 0.5) / self.pixels_per_point
}

#[inline(always)]
pub fn round_pos_to_pixel(&self, pos: Pos2) -> Pos2 {
pos2(self.round_to_pixel(pos.x), self.round_to_pixel(pos.y))
}

#[inline(always)]
pub fn round_pos_to_pixel_center(&self, pos: Pos2) -> Pos2 {
pos2(
Expand Down Expand Up @@ -1707,8 +1712,8 @@ impl Tessellator {
// We can fix that by rounding the rectangle corners to pixel centers.
// TODO(#5164): maybe do this for all shapes and stroke sizes
Rect {
min: self.round_pos_to_pixel_center(rect.min),
max: self.round_pos_to_pixel_center(rect.max),
min: self.round_pos_to_pixel(rect.min),
max: self.round_pos_to_pixel(rect.max),
}
} else {
rect
Expand Down

0 comments on commit 204318a

Please sign in to comment.