PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Preserve continuous camera movement in default Crop
bommerts6351ee060967
diff --git a/crates/ui-egui/src/canvas.rs b/crates/ui-egui/src/canvas.rsindex 135db88dc..db8a44bcc 100644--- a/crates/ui-egui/src/canvas.rs+++ b/crates/ui-egui/src/canvas.rs@@ -947,10 +947,16 @@ impl ViewXform {rotation: v.rotation,aspect: app.ui.view.display_aspect(),}- .pixel_aligned(app.canvas_ppp()),+ .pixel_aligned_for(app, app.canvas_ppp()),)}+ fn pixel_aligned_for(self, app: &PhotocraftApp, ppp: f32) -> Self {+ // Default Crop counter-moves the frame and camera with fractional pointer deltas.+ // Preserve that continuous mapping so its fixed frame does not wobble during a drag.+ if crate::crop_mode::moves_image(app) { self } else { self.pixel_aligned(ppp) }+ }+/// At integer physical magnifications, texel edges must land on display pixel edges./// Keep this derived camera shared by images, overlays and input without changing the saved pan.fn pixel_aligned(mut self, ppp: f32) -> Self {@@ -3176,7 +3182,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:let flip = app.ui.view.flip_horizontal;// Canvas geometry (ViewXform, ViewParams, painter rects) is in egui points.let point_zoom = view.zoom / ppp;- let xf = ViewXform { rect, zoom: point_zoom, center: view.center, flip, rotation: view.rotation, aspect }.pixel_aligned(ppp);+ let xf = ViewXform { rect, zoom: point_zoom, center: view.center, flip, rotation: view.rotation, aspect }.pixel_aligned_for(app, ppp);let pixel_grid = app.ui.view.shows(app.ui.view.show.pixel_grid);let response = ui.allocate_rect(rect, Sense::click_and_drag());let stroke_dismissal = primary && crate::shape_stroke_ui::dismiss_from_canvas(app, &response);@@ -4039,7 +4045,7 @@ pub fn canvas_view(app: &mut PhotocraftApp, ui: &mut egui::Ui, idx: usize, rect:ctx.request_repaint();}}- let xf = if crop_camera { ViewXform { center: view.center, rotation: view.rotation, ..xf }.pixel_aligned(ppp) } else { xf };+ let xf = if crop_camera { ViewXform { center: view.center, rotation: view.rotation, ..xf }.pixel_aligned_for(app, ppp) } else { xf };let (img_rect, beyond, layer_edges) = painted.unwrap_or_else(|| paint_canvas(app, ui, &view, xf));if primary && !(hand_pan && response.dragged()) {// The transform preview is image content: it goes under the grid and guides, whichdiff --git a/crates/ui-egui/src/canvas/pixel_alignment_tests.rs b/crates/ui-egui/src/canvas/pixel_alignment_tests.rsindex 1f6859f8b..1e6126da3 100644--- a/crates/ui-egui/src/canvas/pixel_alignment_tests.rs+++ b/crates/ui-egui/src/canvas/pixel_alignment_tests.rs@@ -124,3 +124,13 @@ fn cpu_canvas_paints_its_image_on_physical_pixel_edges() {assert_eq!(app.ui.views[0].center, saved_center);}}++#[test]+fn crop_image_movement_keeps_its_continuous_camera_mapping() {+ let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());+ app.ui.tool = Tool::Crop;+ let xf = xform(1.0, [523.0, 471.0]);+ assert_eq!(xf.pixel_aligned_for(&app, 1.0).center, xf.center);+ app.ui.tool_options.crop_shield.classic_mode = true;+ assert_pixel_edges(xf.pixel_aligned_for(&app, 1.0), 1.0);+}diff --git a/docs/images/cpu-pixel-alignment/README.md b/docs/images/cpu-pixel-alignment/README.mdindex 30c3edd40..d1993a7d1 100644--- a/docs/images/cpu-pixel-alignment/README.md+++ b/docs/images/cpu-pixel-alignment/README.md@@ -5,3 +5,5 @@ Original 200 × 200 pixel crops at screen coordinates (200, 250)–(400, 450) fr`before.png` shows the half-pixel horizontal offset. `after.png` shows the aligned canvas and is byte-for-byte equal to the GPU canvas crop. Their grayscale standard deviations are 17.4105 and 24.6821 respectively. The 901-pixel-wide control stays sharp.The source document fits the offscreen WARP adapter texture limit, so reduced-texture sampling does not mask the pixel-alignment comparison. These captures are original PhotoCraft assets, licensed MIT OR Apache-2.0 (the license files are alongside them).++Default Crop keeps its continuous camera positioning so the crop frame stays fixed during fractional pointer drags. Normal canvas views and Classic Crop use pixel alignment at integral physical magnifications.