From cf8b043e1f26d28df298b9a9b73b6eedfa118163 Mon Sep 17 00:00:00 2001 From: elwrcl Date: Fri, 2 Oct 2026 18:28:34 +0300 Subject: [PATCH] fix: sharp rectangle corners in the export --- src/editor/export.rs | 13 +++++++++++++ src/editor/shape.rs | 11 +++++++++-- 2 files changed, 22 insertions(+), 2 deletions(-) diff --git a/src/editor/export.rs b/src/editor/export.rs index c1657ce..e313f7b 100644 --- a/src/editor/export.rs +++ b/src/editor/export.rs @@ -109,6 +109,19 @@ mod tests { ); } + #[test] + fn rectangles_have_sharp_corners() { + let base = RgbaImage::from_pixel(60, 40, Rgba([255, 255, 255, 255])); + let rect = Shape { + tool: Tool::Rectangle, + style: Style { color: [255, 0, 0], width: 8.0 }, + points: vec![(10.0, 10.0), (50.0, 30.0)], + }; + let out = render(&base, &[rect]); + // A round join would leave the outer corner (6..7, 6..7) white. + assert_eq!(out.get_pixel(6, 6).0, [255, 0, 0, 255]); + } + #[test] fn highlighter_blends_at_40_percent() { let base = RgbaImage::from_pixel(100, 40, Rgba([0, 0, 255, 255])); diff --git a/src/editor/shape.rs b/src/editor/shape.rs index 0d6bfcf..780161e 100644 --- a/src/editor/shape.rs +++ b/src/editor/shape.rs @@ -154,7 +154,7 @@ pub enum Prim { width: f32, color: [u8; 4], closed: bool, - /// Round caps and joins; false means butt caps. + /// Round caps and joins; false means butt caps and miter joins. round: bool, }, /// A convex polygon. @@ -178,7 +178,14 @@ pub fn geometry(shape: &Shape) -> Vec { Tool::Arrow => arrow(pts[0], pts[1], w, opaque), Tool::Rectangle => { let ((x0, y0), (x1, y1)) = (pts[0], pts[1]); - vec![stroke(vec![(x0, y0), (x1, y0), (x1, y1), (x0, y1)], true)] + // Sharp (miter) corners, as egui draws them while dragging. + vec![Prim::Stroke { + points: vec![(x0, y0), (x1, y0), (x1, y1), (x0, y1)], + width: w, + color: opaque, + closed: true, + round: false, + }] } Tool::Ellipse => { let ((x0, y0), (x1, y1)) = (pts[0], pts[1]);