mirror of
https://github.com/emilk/egui.git
synced 2026-08-31 05:40:03 -04:00
Even better
This commit is contained in:
@@ -1646,6 +1646,8 @@ impl Tessellator {
|
|||||||
let feathering = self.feathering;
|
let feathering = self.feathering;
|
||||||
let pixels_per_point = self.pixels_per_point;
|
let pixels_per_point = self.pixels_per_point;
|
||||||
|
|
||||||
|
let quarter_pixel = 0.25 * feathering; // Used to avoid fence post problem.
|
||||||
|
|
||||||
let [a, b] = &mut points;
|
let [a, b] = &mut points;
|
||||||
if a.x == b.x {
|
if a.x == b.x {
|
||||||
// Vertical line
|
// Vertical line
|
||||||
@@ -1656,14 +1658,16 @@ impl Tessellator {
|
|||||||
|
|
||||||
// Often the ends of the line are exactly on a pixel boundary,
|
// Often the ends of the line are exactly on a pixel boundary,
|
||||||
// but we extend line segments with a cap that is a pixel wide…
|
// but we extend line segments with a cap that is a pixel wide…
|
||||||
// Solution: first shrink the pixel by half a pixel (on each end),
|
// Solution: first shrink the line segment (on each end),
|
||||||
// then round to pixel center!
|
// then round to pixel center!
|
||||||
|
// We shrink by half-a-pixel n total (a quarter on each end),
|
||||||
|
// so that on average we avoid the fence-post-problem after rounding.
|
||||||
if a.y < b.y {
|
if a.y < b.y {
|
||||||
a.y = (a.y + 0.5 * feathering).round_to_pixel_center(pixels_per_point);
|
a.y = (a.y + quarter_pixel).round_to_pixel_center(pixels_per_point);
|
||||||
b.y = (b.y - 0.5 * feathering).round_to_pixel_center(pixels_per_point);
|
b.y = (b.y - quarter_pixel).round_to_pixel_center(pixels_per_point);
|
||||||
} else {
|
} else {
|
||||||
a.y = (a.y - 0.5 * feathering).round_to_pixel_center(pixels_per_point);
|
a.y = (a.y - quarter_pixel).round_to_pixel_center(pixels_per_point);
|
||||||
b.y = (b.y + 0.5 * feathering).round_to_pixel_center(pixels_per_point);
|
b.y = (b.y + quarter_pixel).round_to_pixel_center(pixels_per_point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if a.y == b.y {
|
if a.y == b.y {
|
||||||
@@ -1675,11 +1679,11 @@ impl Tessellator {
|
|||||||
|
|
||||||
// See earlier comment for vertical lines
|
// See earlier comment for vertical lines
|
||||||
if a.x < b.x {
|
if a.x < b.x {
|
||||||
a.x = (a.x + 0.5 * feathering).round_to_pixel_center(pixels_per_point);
|
a.x = (a.x + quarter_pixel).round_to_pixel_center(pixels_per_point);
|
||||||
b.x = (b.x - 0.5 * feathering).round_to_pixel_center(pixels_per_point);
|
b.x = (b.x - quarter_pixel).round_to_pixel_center(pixels_per_point);
|
||||||
} else {
|
} else {
|
||||||
a.x = (a.x - 0.5 * feathering).round_to_pixel_center(pixels_per_point);
|
a.x = (a.x - quarter_pixel).round_to_pixel_center(pixels_per_point);
|
||||||
b.x = (b.x + 0.5 * feathering).round_to_pixel_center(pixels_per_point);
|
b.x = (b.x + quarter_pixel).round_to_pixel_center(pixels_per_point);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user