mirror of
https://github.com/storytold/photocraft.git
synced 2026-10-14 19:26:51 -04:00
Polygonal Lasso: make the Shift constraint helper visible to its tests; cargo fmt
Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
1 parent
de6addf496
commit
8285fb2ec3
2 files changed
+3
-8
No files matched your search
@@ -4221,7 +4221,7 @@ pub(crate) fn selection_mode(app: &PhotocraftApp, m: egui::Modifiers) -> &'stati
|
||||
|
||||
/// Shift constrains a Polygonal Lasso segment to Photoshop's 45° directions.
|
||||
/// Work in document coordinates so zoom, view rotation and mirroring cannot skew it.
|
||||
fn constrained_polygon_point(from: [f64; 2], point: [f64; 2]) -> [f64; 2] {
|
||||
pub(crate) fn constrained_polygon_point(from: [f64; 2], point: [f64; 2]) -> [f64; 2] {
|
||||
let dx = point[0] - from[0];
|
||||
let dy = point[1] - from[1];
|
||||
if !dx.is_finite() || !dy.is_finite() {
|
||||
@@ -4256,11 +4256,7 @@ fn polygon_click(app: &mut PhotocraftApp, x: f64, y: f64, mods: egui::Modifiers)
|
||||
}
|
||||
// Only constrain segments after the first vertex; the first click still sets selection intent.
|
||||
// Alt-drag is freehand and must not snap to an angle.
|
||||
let point = if mods.shift && !mods.alt {
|
||||
app.ui.polygon.last().copied().map_or([x, y], |last| constrained_polygon_point(last, [x, y]))
|
||||
} else {
|
||||
[x, y]
|
||||
};
|
||||
let point = if mods.shift && !mods.alt { app.ui.polygon.last().copied().map_or([x, y], |last| constrained_polygon_point(last, [x, y])) } else { [x, y] };
|
||||
app.ui.polygon.push(point);
|
||||
}
|
||||
|
||||
|
||||
@@ -367,8 +367,7 @@ fn shift_constrains_polygonal_lasso_segments_but_unmodified_clicks_remain_free()
|
||||
#[test]
|
||||
fn shift_polygonal_lasso_snap_has_all_eight_directions_and_handles_zero_length() {
|
||||
let origin = [200.0, 150.0];
|
||||
let directions = [[40.0, 1.0], [40.0, 25.0], [1.0, 40.0], [-40.0, 25.0],
|
||||
[-40.0, -1.0], [-40.0, -25.0], [-1.0, -40.0], [40.0, -25.0]];
|
||||
let directions = [[40.0, 1.0], [40.0, 25.0], [1.0, 40.0], [-40.0, 25.0], [-40.0, -1.0], [-40.0, -25.0], [-1.0, -40.0], [40.0, -25.0]];
|
||||
for delta in directions {
|
||||
let end = crate::canvas::constrained_polygon_point(origin, [origin[0] + delta[0], origin[1] + delta[1]]);
|
||||
let dx = end[0] - origin[0];
|
||||
|
||||
Reference in new issue
Block a user