Crop: the turn readout never shows -0.0° or -180.0° (#7040)

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
David MannandClaude Opus 5.5 committed 2026-10-17 15:45:13 +02:00
1 parent 5f65579ecb
commit 758ad4db44
2 files changed
+27 -2

No files matched your search

+15 -1
View File
@@ -398,6 +398,20 @@ fn draw_marquee_readout(app: &PhotocraftApp, ctx: &egui::Context, cursor: Pos2,
draw_value_readout(app, ctx, "marquee-readout", cursor, ["W:", "H:"], values);
}
/// A turn of `deg` degrees as the readout beside the pointer shows it, to 0.1° in (-180, 180].
/// Rounded first so a hair below zero never reads "-0.0°" and a hair above -180 reads "180.0°".
pub(crate) fn angle_readout(deg: f64) -> String {
let d = (deg * 10.0).round() / 10.0;
let d = if d == 0.0 {
0.0
} else if d == -180.0 {
180.0
} else {
d
};
format!("{d:.1}°")
}
/// A transformation-values readout beside the pointer (a marquee's or the crop frame's size, an
/// angle), unless Preferences › Tools › Show Transformation Values is off, as in Photoshop (#204).
/// The brush HUD isn't one: Show Transformation Values doesn't hide it, so it calls [`draw_readout`].
@@ -4713,7 +4727,7 @@ fn draw_tool_state(app: &PhotocraftApp, painter: &egui::Painter, xf: &ViewXform,
}
// The frame's angle beside the pointer while it turns (#1792).
if let (Some(a), Some(h)) = (crate::crop_ui::turning(app), hover) {
draw_value_readout(app, painter.ctx(), "crop-angle-readout", h, ["Angle:"], [format!("{a:.1}°")]);
draw_value_readout(app, painter.ctx(), "crop-angle-readout", h, ["Angle:"], [angle_readout(a)]);
} else if let (Some([w, h]), Some(at)) = (crate::crop_ui::sizing(app), hover) {
// Its W × H while it is drawn or resized (#1919), like the marquee's.
draw_marquee_readout(app, painter.ctx(), at, size_readout(app, [0.0, 0.0, w, h]));
+12 -1
View File
@@ -156,7 +156,7 @@ pub fn draw(app: &PhotocraftApp, painter: &egui::Painter, to_screen: impl Fn([f6
let (dx, dy) = (b[0] - a[0], b[1] - a[1]);
let deg = (-dy).atan2(dx).to_degrees();
if let Some(h) = hover.filter(|_| deg.is_finite() && (dx != 0.0 || dy != 0.0)) {
crate::canvas::draw_value_readout(app, painter.ctx(), "crop-straighten-readout", h, ["Angle:"], [format!("{deg:.1}°")]);
crate::canvas::draw_value_readout(app, painter.ctx(), "crop-straighten-readout", h, ["Angle:"], [crate::canvas::angle_readout(deg)]);
}
}
@@ -231,6 +231,17 @@ mod tests {
assert_eq!(frame_angle([0.0, 0.0], [f64::INFINITY, 1.0], 1.0), None);
}
#[test]
fn the_angle_readout_never_shows_minus_zero_or_minus_180() {
use crate::canvas::angle_readout;
assert_eq!(angle_readout(-0.03), "0.0°");
assert_eq!(angle_readout(0.0), "0.0°");
assert_eq!(angle_readout(-179.97), "180.0°");
assert_eq!(angle_readout(179.97), "180.0°");
assert_eq!(angle_readout(12.34), "12.3°");
assert_eq!(angle_readout(-12.36), "-12.4°");
}
#[test]
fn the_fitted_frame_is_the_largest_of_its_proportions_inside_the_canvas() {
// Upright, the canvas's own proportions fill it.