PhotoCraft: An open-source, photo editor written by scratch in pure Rust
Merge main into integration-batch-7
aiongg7aaa59712a3f
diff --cc Cargo.lockindex 97f6aca6c,1df0af69a..69a1e38e9--- a/Cargo.lock+++ b/Cargo.lock@@@ -4783,10 -4783,9 +4784,10 @@@ dependencies =[[package]]name = "photocraft-compose"- version = "0.13.0"+ version = "0.15.0"dependencies = ["criterion",+ "photocraft-cms","photocraft-color","photocraft-doc","photocraft-geom",diff --cc crates/geom/src/warp.rsindex f22e1945b,4e10ed8c0..cbbd74619--- a/crates/geom/src/warp.rs+++ b/crates/geom/src/warp.rs@@@ -1063,11 -961,32 +1078,32 @@@ impl Warppub fn is_identity(&self) -> bool {match self.style {WarpStyle::None => true,- WarpStyle::Custom => match &self.mesh {+ WarpStyle::Custom | WarpStyle::Cylinder => match &self.mesh {None => true,Some(m) => {- let id = BezierMesh::fit(&|s, t| self.box_point(s, t), m.us.clone(), m.vs.clone());- m.points.iter().zip(&id.points).all(|(a, b)| (a[0] - b[0]).abs() < 1e-9 && (a[1] - b[1]).abs() < 1e-9)+ if !m.is_valid() {+ return false;+ }+ let nx = m.nx();+ let (pc, pr) = (m.us.len() - 1, m.vs.len() - 1);+ for pj in 0..pr {+ for j in 0..4 {+ let v = m.vs[pj] + (m.vs[pj + 1] - m.vs[pj]) * j as f64 / 3.0;+ for pi in 0..pc {+ for i in 0..4 {+ let u = m.us[pi] + (m.us[pi + 1] - m.us[pi]) * i as f64 / 3.0;+ let expected = self.box_point(u, v);+ let actual = m.points[(3 * pj + j) * nx + 3 * pi + i];+ // Relative to the magnitude so the fit's rounding at large origins isn't rejected.+ let tol = |e: f64| (1e-9 * e.abs().max(1.0)).min(1e-6);+ if (actual[0] - expected[0]).abs() >= tol(expected[0]) || (actual[1] - expected[1]).abs() >= tol(expected[1]) {+ return false;+ }+ }+ }+ }+ }+ true}},_ => self.style_warp().is_none(),@@@ -1502,92 -1421,37 +1538,126 @@@ mod testsassert!((ob[0] - 10.0).abs() < 1e-9 && (ob[3] - 70.0).abs() < 1e-9);}+ /// A cylinder over a 1000 × 1000 source like #4112's: silhouettes at x 100 and 900, edges at+ /// y 200 (top) and 800 (bottom), ellipses 0.3 deep, half wrapped round.+ const CYL: [f64; 7] = [100.0, 800.0, 900.0, 200.0, 0.3, 0.3, 0.5];++ #[test]+ fn cylinder_style_is_read_and_named_but_not_a_bend_preset() {+ for s in ["cylinder", "warpCylinder", "Cylinder"] {+ assert_eq!(WarpStyle::parse(s), Some(WarpStyle::Cylinder), "{s}");+ }+ assert_eq!(WarpStyle::Cylinder.psd_name(), "warpCylinder");+ assert_eq!(WarpStyle::Cylinder.id(), "cylinder");+ assert!(!WarpStyle::Cylinder.is_preset());+ assert!(StyleWarp::new(WarpStyle::Cylinder, 50.0, 0.0, 0.0, false, B).is_none());+ // The Warp menus list what they can edit.+ assert!(WarpStyle::all().all(|s| s != WarpStyle::Cylinder));+ assert_eq!(WarpStyle::all().filter(|s| s.is_preset()).count(), 15);+ }++ #[test]+ fn cylinder_values_that_describe_no_cylinder_are_refused() {+ assert!(cylinder_mesh(&CYL[..6]).is_none(), "six values");+ assert!(cylinder_mesh(&[CYL.as_slice(), &[0.0]].concat()).is_none(), "eight values");+ for i in 0..7 {+ for bad in [f64::NAN, f64::INFINITY] {+ let mut v = CYL;+ v[i] = bad;+ assert!(cylinder_mesh(&v).is_none(), "value {i} = {bad}");+ }+ }+ let mut v = CYL;+ v[2] = v[0];+ assert!(Warp::cylinder(&v, [0.0, 0.0, 1000.0, 1000.0]).is_none(), "no width");+ v[2] = 50.0;+ assert!(Warp::cylinder(&v, [0.0, 0.0, 1000.0, 1000.0]).is_none(), "right silhouette left of the left one");+ }++ #[test]+ fn cylinder_wraps_the_contents_between_its_silhouettes() {+ let w = Warp::cylinder(&CYL, [0.0, 0.0, 1000.0, 1000.0]).unwrap();+ assert_eq!(w.style, WarpStyle::Cylinder);+ assert_eq!(w.values, CYL);+ assert!(!w.is_identity());+ let m = w.mesh.as_ref().unwrap();+ assert_eq!((m.nx(), m.ny()), (13, 4));+ let [ul, ..] = cylinder_shape(0.5);+ assert!((m.us[1] - ul).abs() < 1e-12 && (m.us[3] - (1.0 - ul)).abs() < 1e-12);+ // The middle of the contents is at the front: centred, on the ellipses' near side.+ assert!(close(w.map(500.0, 0.0), (500.0, 200.0 + 0.3 * 400.0), 1e-9));+ assert!(close(w.map(500.0, 1000.0), (500.0, 800.0 + 0.3 * 400.0), 1e-9));+ // What wraps round the back lies on the silhouettes, at the edges' ends.+ for x in [0.0, ul * 500.0, ul * 1000.0] {+ assert!(close(w.map(x, 0.0), (100.0, 200.0), 1e-9), "{x}");+ assert!(close(w.map(1000.0 - x, 1000.0), (900.0, 800.0), 1e-9), "{x}");+ }+ // Across the front x only grows, and the two halves mirror each other.+ let mut last = f64::MIN;+ for i in 0..=200 {+ let x = 1000.0 * (ul + (1.0 - 2.0 * ul) * f64::from(i) / 200.0);+ let (px, py) = w.map(x, 400.0);+ assert!(px >= last - 1e-9, "x {x}");+ last = px;+ let (qx, qy) = w.map(1000.0 - x, 400.0);+ assert!(close((px - 500.0, py), (500.0 - qx, qy), 1e-9), "x {x}");+ }+ // Every point stays inside the control-point box the placement frames.+ let cb = m.control_bounds();+ let ob = w.output_bounds();+ assert!(ob[0] >= cb[0] - 1e-9 && ob[1] >= cb[1] - 1e-9 && ob[2] <= cb[2] + 1e-9 && ob[3] <= cb[3] + 1e-9);+ assert!((cb[0] - 100.0).abs() < 1e-9 && (cb[2] - 900.0).abs() < 1e-9);+ // The box's bottom is the lower ellipse's deepest control point (`my` > 1).+ assert!((cb[3] - (800.0 + 0.3 * 400.0 * cylinder_shape(0.5)[3])).abs() < 1e-9);+ assert_eq!(w.to_mesh(4, 4), *m, "a cylinder is its own mesh");+ }++ #[test]+ fn cylinder_shape_follows_the_measured_rows() {+ assert_eq!(cylinder_shape(0.0), CYLINDER_SHAPE[0]);+ assert_eq!(cylinder_shape(1.0), CYLINDER_SHAPE[40]);+ assert_eq!(cylinder_shape(-3.0), CYLINDER_SHAPE[0]);+ assert_eq!(cylinder_shape(7.0), CYLINDER_SHAPE[40]);+ assert_eq!(cylinder_shape(f64::NAN), CYLINDER_SHAPE[0]);+ let mid = cylinder_shape(0.0125);+ for k in 0..4 {+ assert!((mid[k] - (CYLINDER_SHAPE[0][k] + CYLINDER_SHAPE[1][k]) / 2.0).abs() < 1e-12);+ }+ // The more it wraps, the less of the contents is on the back.+ assert!(CYLINDER_SHAPE.windows(2).all(|r| r[1][0] < r[0][0]));+ }+++ #[test]+ fn is_identity_rejects_malformed_custom_mesh_without_allocating() {+ let us: Vec<f64> = (0..=1000).map(|i| i as f64 / 1000.0).collect();+ let vs: Vec<f64> = (0..=1000).map(|i| i as f64 / 1000.0).collect();+ let malformed = BezierMesh { us, vs, points: Vec::new() };+ assert!(!malformed.is_valid());+ let w = Warp::custom(malformed.clone(), B);+ assert!(!w.is_identity());+ assert_eq!(malformed.eval(0.5, 0.5), [0.0, 0.0]);+ }++ #[test]+ fn locate_binary_search_matches_linear_scan() {+ let knots = [0.0, 0.1, 0.25, 0.5, 0.85, 1.0];+ let linear = |s: f64| {+ let n = knots.len() - 1;+ let s = if s.is_finite() { s.clamp(0.0, 1.0) } else { 0.0 };+ let mut i = 0;+ while i + 1 < n && s > knots[i + 1] {+ i += 1;+ }+ let w = knots[i + 1] - knots[i];+ (i, if w > 0.0 { (s - knots[i]) / w } else { 0.0 })+ };+ for k in -10..=110 {+ let s = k as f64 / 100.0;+ assert_eq!(BezierMesh::locate(&knots, s), linear(s), "s={s}");+ }+ for &s in &knots {+ assert_eq!(BezierMesh::locate(&knots, s), linear(s), "knot={s}");+ }+ assert_eq!(BezierMesh::locate(&knots, f64::NAN), linear(f64::NAN));+ }}diff --cc crates/text/src/layout.rsindex 061f2ac67,5809e360e..4936b33c6--- a/crates/text/src/layout.rs+++ b/crates/text/src/layout.rs@@@ -681,11 -673,10 +682,10 @@@ impl Layouterlet (line_origin, line_len) = if vertical { (box_rect.1, box_rect.3) } else { (box_rect.0, box_rect.2) };let avail = if is_box { Some((line_len - indent_start - indent_end).max(1.0)) } else { None };// Horizontal scale is applied after shaping, so paragraph text breaks at the box- // width divided by it (#5565). Mixed scales break at the largest, so no line- // overflows the box.- let break_scale = if is_box {+ // (or area span) width divided by it (#5565). Mixed scales break at the largest, so+ // no line overflows the box.+ let break_scale = if wraps {- let si0 = style_at(prange.start);- (0..out.styles.len())+ (si0..si_end).filter(|&ri| {let rs = run_starts.get(ri).copied().unwrap_or(0);let end = rs.saturating_add(runs.get(ri).map_or(0, |r| r.len));