Rotate Canvas Arbitrary: keep the angle at full precision, so rotated crops land on the pixel (#7369) (#7370)

rotate_arbitrary read `angle` as f32. rotated_crop sizes its canvas with
rotated_size at f64 and passes the angle through JSON; near a whole-pixel
ceil boundary the f32 angle grew the canvas 1 px more (1000x1000 at
0.11470651449337071: 1003 instead of 1002), shifting the crop by 1 px.

Co-authored-by: Claude Opus 5.5 <[email protected]>
This commit is contained in:
David MannandClaude Opus 5.5 authored and GitHub committed 2026-10-18 10:39:29 -04:00
1 parent fb6f8b4fa6
commit a4c7b5ef89
2 files changed
+14 -1

No files matched your search

+2 -1
View File
@@ -63,7 +63,8 @@ pub fn rotated_size(size: Size, deg: f64) -> Size {
pub(crate) fn rotate_arbitrary(s: &mut Session, p: &Value) -> Result<Value> {
const CMD: &str = "image.rotation.arbitrary";
let angle = f64::from(num(p, "angle", 0.0));
// At full precision: an f32 angle can grow the canvas 1 px past what `rotated_size` gives callers.
let angle = p.get("angle").and_then(Value::as_f64).unwrap_or(0.0);
if !angle.is_finite() || angle.abs() > 3600.0 {
return Err(bad(CMD, "angle out of range"));
}
+12
View File
@@ -81,6 +81,18 @@ fn rotate_arbitrary_other_modes() {
}
}
#[test]
fn rotate_arbitrary_keeps_the_full_precision_angle() {
// Rounded to f32 this angle crosses a whole pixel: 1003 px instead of 1002, so a rotated crop
// that sized its canvas with `rotated_size` at f64 would land 1 px off.
let angle = 0.114_706_514_493_370_71;
let mut s = Session::new();
s.execute("file.new", json!({"width": 1000, "height": 1000})).unwrap();
let r = s.execute("image.rotation.arbitrary", json!({"angle": angle})).unwrap();
assert_eq!(rotated_size(Size::new(1000, 1000), angle), Size::new(1002, 1002));
assert_eq!((r["width"].as_u64(), r["height"].as_u64()), (Some(1002), Some(1002)));
}
#[test]
fn rotate_arbitrary_rotates_grouped_locked_children_and_preserves_lock() {
let mut s = Session::new();