mirror of
https://github.com/storytold/photocraft.git
synced 2026-11-12 21:23:02 +00:00
fix(ui): round the ruler's Arbitrary angle before the first frame (#13067)
The ruler pre-fill stored the raw straightening angle, and only a drawn frame rounded it, so `ui.dialog.open` then `ui.dialog.confirm` with no frame between them sent 32.1249984 instead of 32.12. Round it in f64 to the field's two decimals where it is filled, on open and on Alt+Reset.
This commit is contained in:
1 parent
7350c8239c
commit
6513ce6e47
2 files changed
+20
-1
No files matched your search
@@ -147,3 +147,19 @@ fn other_number_fields_keep_their_precision() {
|
||||
let x = f["centerX"].as_f64().unwrap();
|
||||
assert!((x - 0.12).abs() < 1e-5, "the Radial Blur centre {x} keeps its two decimals");
|
||||
}
|
||||
|
||||
/// The pre-fill is rounded before any frame draws: `ui.dialog.open` then `ui.dialog.confirm`
|
||||
/// can run without a draw between them, and the 43x27 ruler's raw 32.1249984 must not reach
|
||||
/// the command, after opening or after Alt+Reset.
|
||||
#[test]
|
||||
fn the_ruler_angle_is_rounded_before_the_first_frame() {
|
||||
let mut app = PhotocraftApp::new(photocraft_engine::Session::new(), crate::Services::default());
|
||||
app.run("file.new", json!({"width": 318, "height": 318})).unwrap();
|
||||
app.run("image.analysis.rulerTool", json!({"start": [100, 100], "end": [143, 127]})).unwrap();
|
||||
let id = open(&mut app, "image.rotation.arbitrary").unwrap();
|
||||
let mut f = app.ui.dialog_mut(id).unwrap().fields.clone();
|
||||
assert_eq!(params_of(&f)["angle"].as_f64(), Some(32.12), "undrawn, OK sends the rounded angle");
|
||||
f.insert("angle".into(), json!(5.0));
|
||||
reset_fields(&app, &mut f);
|
||||
assert_eq!(params_of(&f)["angle"].as_f64(), Some(32.12), "undrawn after Alt+Reset, OK sends the rounded angle");
|
||||
}
|
||||
@@ -693,7 +693,10 @@ fn straighten_defaults(app: &PhotocraftApp, fields: &mut Map<String, Value>) {
|
||||
if !rot.is_finite() {
|
||||
return;
|
||||
}
|
||||
fields.insert("angle".into(), json!(rot.abs()));
|
||||
// Rounded here, in f64, to the field's two decimals: `ui.dialog.open` then `ui.dialog.confirm`
|
||||
// can run with no frame drawn between them, and only a drawn frame rounds (#13067).
|
||||
let scale = 10f64.powi(wide_field_decimals("image.rotation.arbitrary", "angle").unwrap_or(2).min(6) as i32);
|
||||
fields.insert("angle".into(), json!((rot.abs() * scale).round() / scale));
|
||||
fields.insert("direction".into(), json!(if rot < 0.0 { "ccw" } else { "cw" }));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user