PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Guides: colours follow Crop, Canvas Size and rotations (#7724) (#7725)
David Manncbe6c4e13187
diff --git a/crates/engine/src/canvas_geom.rs b/crates/engine/src/canvas_geom.rsindex 76142f9a7..99f7e4cc8 100644--- a/crates/engine/src/canvas_geom.rs+++ b/crates/engine/src/canvas_geom.rs@@ -156,15 +156,24 @@ pub(crate) fn transform_doc_marks(doc: &mut Document, a: &Affine) {if m1.abs() < EPS && m2.abs() < EPS {g.horizontal.iter_mut().for_each(|y| *y = m3 * *y + ty);g.vertical.iter_mut().for_each(|x| *x = m0 * *x + tx);+ // Colours are keyed by exact position, so they move by the same expressions.+ for c in &mut g.colors {+ c.position = if c.vertical { m0 * c.position + tx } else { m3 * c.position + ty };+ }} else if m0.abs() < EPS && m3.abs() < EPS {// A horizontal guide at y becomes a vertical one at x' = m2·y + tx, and vice versa.let v: Vec<f64> = g.horizontal.iter().map(|y| m2 * y + tx).collect();let h: Vec<f64> = g.vertical.iter().map(|x| m1 * x + ty).collect();g.horizontal = h;g.vertical = v;+ for c in &mut g.colors {+ c.position = if c.vertical { m1 * c.position + ty } else { m2 * c.position + tx };+ c.vertical = !c.vertical;+ }} else {g.horizontal.clear();g.vertical.clear();+ g.colors.clear();}}diff --git a/crates/engine/src/canvas_geom/tests.rs b/crates/engine/src/canvas_geom/tests.rsindex f27d9756f..0dbf03d2e 100644--- a/crates/engine/src/canvas_geom/tests.rs+++ b/crates/engine/src/canvas_geom/tests.rs@@ -263,6 +263,28 @@ fn canvas_size_and_crop_move_vector_geometry() {assert!(mean < 1.0 / 255.0, "{mean}");}+#[test]+fn guide_colours_follow_their_guides() {+ const MAGENTA: [u8; 3] = [255, 0, 255];+ let mut s = Session::new();+ s.execute("file.new", json!({"width": W, "height": H})).unwrap();+ s.execute("view.newGuide", json!({"orientation": "vertical", "position": 20, "color": "#ff00ff"})).unwrap();+ s.execute("view.newGuide", json!({"orientation": "vertical", "position": 30})).unwrap();+ // Crop shifts both guides by 10: the colour goes with the guide at 20, not to the one now there.+ s.execute("image.crop", json!({"x": 10, "y": 0, "width": W - 10, "height": H})).unwrap();+ let g = &doc(&s).guides;+ assert_eq!(g.vertical, vec![10.0, 20.0]);+ assert_eq!((g.color(true, 10.0), g.color(true, 20.0)), (Some(MAGENTA), None));+ // A quarter turn makes it a horizontal guide at y = 10, still magenta.+ s.execute("image.imageRotation.90cw", json!({})).unwrap();+ let g = &doc(&s).guides;+ assert_eq!(g.horizontal, vec![10.0, 20.0]);+ assert_eq!((g.color(false, 10.0), g.color(true, 10.0)), (Some(MAGENTA), None));+ // An arbitrary angle drops the guides, so their colours go too.+ s.execute("image.rotation.arbitrary", json!({"angle": 33})).unwrap();+ assert!(doc(&s).guides.colors.is_empty());+}+#[test]fn image_size_scales_vector_geometry() {let mut s = mixed(8, "rgb");