fix: sharp rectangle corners in the export
This commit is contained in:
1 parent
9357395976
commit
cf8b043e1f
2 files changed
+22
-2
No files matched your search
@@ -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]));
|
||||
|
||||
+9
-2
@@ -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<Prim> {
|
||||
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]);
|
||||
|
||||
Reference in new issue
Block a user