diff --git a/crates/geom/src/warp.rs b/crates/geom/src/warp.rs index 90c70cc30ff..8c1320cf6a6 100644 --- a/crates/geom/src/warp.rs +++ b/crates/geom/src/warp.rs @@ -836,15 +836,8 @@ impl BezierMesh { *f = f.max((1.0 - interior) * w); } // Every control point moves with the anchor it is closest to. - for j in 0..self.ny() { - for i in 0..nx { - let (ai, aj) = (((i + 1) / 3).min(cols), ((j + 1) / 3).min(rows)); - let k = share[aj * (cols + 1) + ai]; - let p = &mut self.points[j * nx + i]; - p[0] += d[0] * k; - p[1] += d[1] * k; - } - } + let ny = self.ny(); + move_control_points(&mut self.points, nx, ny, cols, rows, &share, d); // Close the gap exactly, with three groups of control points that share the work: // - the four inner points of the grabbed patch (all of it in the middle of the patch, // little near a grid line, where they barely reach the surface); @@ -1022,6 +1015,18 @@ impl BezierMesh { } } +fn move_control_points(points: &mut [[f64; 2]], nx: usize, ny: usize, cols: usize, rows: usize, shares: &[f64], delta: [f64; 2]) { + for j in 0..ny { + for i in 0..nx { + let (ai, aj) = (((i + 1) / 3).min(cols), ((j + 1) / 3).min(rows)); + let share = shares[aj * (cols + 1) + ai]; + let point = &mut points[j * nx + i]; + point[0] += delta[0] * share; + point[1] += delta[1] * share; + } + } +} + /// A complete warp: what Photoshop's `warp` descriptor stores, plus the custom mesh. #[derive(Clone, Debug, PartialEq, Serialize, Deserialize)] #[serde(rename_all = "camelCase")]