From e4e0fc96b466708c3c973a28c7438e6b5a647337 Mon Sep 17 00:00:00 2001 From: Emil Ernerfeldt Date: Tue, 4 Feb 2025 15:02:21 +0100 Subject: [PATCH] Avoid numerical precision issues when considering whether to add line caps --- crates/epaint/src/tessellator.rs | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/crates/epaint/src/tessellator.rs b/crates/epaint/src/tessellator.rs index d7446ddfc..1025b39d5 100644 --- a/crates/epaint/src/tessellator.rs +++ b/crates/epaint/src/tessellator.rs @@ -1002,7 +1002,11 @@ fn stroke_and_fill_path( let color_outer = Color32::TRANSPARENT; let color_middle = &stroke.color; - let thin_line = stroke.width <= feathering; + // We add a bit of an epsilon here, because when we round to pixels, + // we can get rounding errors (unless pixels_per_point is an integer). + // And it's better to err on the side of the nicer rendering with line caps + // (the thin-line optimization has no line caps). + let thin_line = stroke.width <= 0.9 * feathering; if thin_line { // If the stroke is painted smaller than the pixel width (=feathering width), // then we risk severe aliasing. @@ -1017,6 +1021,8 @@ fn stroke_and_fill_path( } } + // TODO(emilk): add line caps (if this is an open line). + let opacity = stroke.width / feathering; /*