Skip to content

LightCraft: An open-source non-destructive photo editor written by scratch in pure Rust

Merge PR #773

Claude5350a8ed7060
diff --cc crates/ui-egui/src/panels/detail.rs
index 8ec6a8114,89ed1eadd..ebdf174ac
--- a/crates/ui-egui/src/panels/detail.rs
+++ b/crates/ui-egui/src/panels/detail.rs
@@@ -2203,41 -2158,8 +2218,42 @@@ fn straighten_overlay(app: &mut Lightcr
#[cfg(test)]
mod tests {
+ /// The rotation pointer's arc bulges away from the side of the crop box it is on, and follows
+ /// a box that is itself rotated.
+ #[test]
+ fn rotate_cursor_faces_away_from_the_crop_box() {
+ use egui::{Pos2, pos2};
+ use std::f32::consts::{FRAC_PI_2, FRAC_PI_4, PI};
+ let near = |a: f32, b: f32| ((a - b + PI).rem_euclid(2.0 * PI) - PI).abs() < 1e-3;
+ let pts = [pos2(100.0, 100.0), pos2(300.0, 100.0), pos2(300.0, 200.0), pos2(100.0, 200.0)];
+ let turn = |x: f32, y: f32| super::rotate_cursor_turn(&pts, pos2(x, y), false);
+ assert!(near(turn(200.0, 80.0), 0.0), "above: as drawn");
+ assert!(near(turn(320.0, 150.0), FRAC_PI_2), "right");
+ assert!(near(turn(200.0, 230.0), PI), "below");
+ assert!(near(turn(70.0, 150.0), -FRAC_PI_2), "left");
+ assert!(near(turn(290.0, 60.0), 0.0), "above the top edge near its end: still up");
+ // off each corner: diagonally out from it
+ assert!(near(turn(80.0, 80.0), -FRAC_PI_4), "top-left corner");
+ assert!(near(turn(320.0, 80.0), FRAC_PI_4), "top-right corner");
+ assert!(near(turn(320.0, 220.0), 3.0 * FRAC_PI_4), "bottom-right corner");
+ assert!(near(turn(80.0, 220.0), -3.0 * FRAC_PI_4), "bottom-left corner");
+ assert!(near(super::rotate_cursor_turn(&pts, pos2(200.0, 110.0), true), 0.0), "dragged back over the top edge: still up");
+ // a box turned 90°: its top edge is now on the right
+ let turned = [pts[3], pts[0], pts[1], pts[2]].map(|p| pos2(400.0 - p.y, p.x));
+ assert!(near(super::rotate_cursor_turn(&turned, pos2(420.0, 200.0), false), FRAC_PI_2));
+ // a box turned 30°: straight out from its top edge is 30° clockwise of up
+ let c = pos2(200.0, 150.0);
+ let rot = |p: Pos2| {
+ let (s, co) = (30f32.to_radians().sin(), 30f32.to_radians().cos());
+ let d = p - c;
+ pos2(c.x + d.x * co - d.y * s, c.y + d.x * s + d.y * co)
+ };
+ let tilted = pts.map(rot);
+ assert!(near(super::rotate_cursor_turn(&tilted, rot(pos2(200.0, 60.0)), false), 30f32.to_radians()));
+ }
+
- use super::{film_label, texture_side};
+ use super::{film_label, flipped_corners, texture_side};
+ use egui::pos2;
/// Issue #652: a native host reports the GPU's texture limit in the first frame's input only.
/// The loupe must still know it in every later frame (it read the raw input, found nothing and
@@@ -2266,22 -2188,20 +2282,38 @@@
assert_eq!(film_label("DSC_0001"), "DSC_0001");
assert_eq!(film_label(""), "");
}
+
+ /// With the photo flipped, the crop box's corners reach the screen mirrored; the dimming
+ /// outside the box pairs each photo corner with the box corner on the same side of the screen
+ /// (it used to pair them in data order, so a flipped photo was dimmed inside the box).
+ #[test]
+ fn flipped_crop_box_corners_come_in_screen_order() {
+ let screen = [pos2(10.0, 10.0), pos2(90.0, 10.0), pos2(90.0, 50.0), pos2(10.0, 50.0)];
+ // data order (top-left, top-right, bottom-right, bottom-left) as each flip shows it
+ let h = [screen[1], screen[0], screen[3], screen[2]];
+ let v = [screen[3], screen[2], screen[1], screen[0]];
+ let hv = [screen[2], screen[3], screen[0], screen[1]];
+ assert_eq!(flipped_corners(&screen, false, false), screen);
+ assert_eq!(flipped_corners(&h, true, false), screen);
+ assert_eq!(flipped_corners(&v, false, true), screen);
+ assert_eq!(flipped_corners(&hv, true, true), screen);
+ }
}
+
+#[cfg(test)]
+mod wheel_zoom_tests {
+ use super::*;
+
+ fn wheel(unit: egui::MouseWheelUnit, y: f32, modifiers: egui::Modifiers) -> egui::Event {
+ egui::Event::MouseWheel { unit, delta: egui::vec2(0.0, y), phase: egui::TouchPhase::Move, modifiers }
+ }
+
+ #[test]
+ fn only_notched_unmodified_wheels_count() {
+ let m = egui::Modifiers::NONE;
+ assert_eq!(wheel_notches(&[wheel(egui::MouseWheelUnit::Line, 1.0, m), wheel(egui::MouseWheelUnit::Line, 2.0, m)]), 3.0);
+ assert_eq!(wheel_notches(&[wheel(egui::MouseWheelUnit::Point, 40.0, m)]), 0.0);
+ assert_eq!(wheel_notches(&[wheel(egui::MouseWheelUnit::Line, 1.0, egui::Modifiers::CTRL)]), 0.0);
+ assert_eq!(wheel_notches(&[wheel(egui::MouseWheelUnit::Line, f32::NAN, m)]), 0.0);
+ }
+}