mirror of
https://github.com/storytold/photocraft.git
synced 2026-12-02 06:20:48 +01:00
Keep thin layer edge outlines at low zoom
This commit is contained in:
1 parent
b95da03dbc
commit
87cb40df30
2 files changed
+34
-2
No files matched your search
@@ -520,8 +520,17 @@ fn layer_edge_shapes(view: &CanvasView, ppp: f32, edges: &craft::behavior::kurbo
|
||||
.filter_map(|(points, _)| {
|
||||
let mut outer: [Pos2; 4] = points.try_into().ok()?;
|
||||
if view.rotation == 0.0 {
|
||||
for corner in &mut outer {
|
||||
*corner = egui::pos2((corner.x * ppp).round() * pixel, (corner.y * ppp).round() * pixel);
|
||||
let snapped = outer.map(|corner| egui::pos2((corner.x * ppp).round() * pixel, (corner.y * ppp).round() * pixel));
|
||||
// At low zoom a nonempty layer can span less than one device pixel.
|
||||
let snap_x = snapped[0].x != snapped[1].x;
|
||||
let snap_y = snapped[0].y != snapped[3].y;
|
||||
for (corner, snapped) in outer.iter_mut().zip(snapped) {
|
||||
if snap_x {
|
||||
corner.x = snapped.x;
|
||||
}
|
||||
if snap_y {
|
||||
corner.y = snapped.y;
|
||||
}
|
||||
}
|
||||
}
|
||||
let [a, b, c, d] = outer;
|
||||
|
||||
@@ -92,3 +92,26 @@ fn canvas_draws_one_blue_device_pixel_inside_each_targeted_layer() {
|
||||
assert!(blue_meshes(&draw(true, false).shapes).is_empty(), "Layer Edges off draws nothing");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn snapping_keeps_thin_layer_bounds_at_half_zoom() {
|
||||
use craft::behavior::kurbo::BezPath;
|
||||
|
||||
let screen = Rect::from_min_size(Pos2::ZERO, egui::Vec2::splat(400.0));
|
||||
let view = CanvasView::new(screen, Point::new(200.0, 200.0), 0.5);
|
||||
let mut edges = BezPath::new();
|
||||
for [x0, y0, x1, y1] in [[1.0, 11.0, 2.0, 52.0], [11.0, 1.0, 52.0, 2.0]] {
|
||||
edges.move_to((x0, y0));
|
||||
edges.line_to((x1, y0));
|
||||
edges.line_to((x1, y1));
|
||||
edges.line_to((x0, y1));
|
||||
edges.close_path();
|
||||
}
|
||||
let shapes = layer_edge_shapes(&view, 1.0, &edges);
|
||||
assert_eq!(shapes.len(), 2, "neither one-document-pixel target disappears");
|
||||
for (shape, [x0, y0, x1, y1]) in shapes.iter().zip([[100.5, 106.0, 101.0, 126.0], [106.0, 100.5, 126.0, 101.0]]) {
|
||||
let egui::Shape::Mesh(mesh) = shape else { panic!("expected a layer outline mesh") };
|
||||
let [a, b, c, d] = [egui::pos2(x0, y0), egui::pos2(x1, y0), egui::pos2(x1, y1), egui::pos2(x0, y1)];
|
||||
assert_eq!(mesh.vertices[..4].iter().map(|v| v.pos).collect::<Vec<_>>(), [a, b, c, d]);
|
||||
}
|
||||
}
|
||||
Reference in new issue
Block a user