diff --git a/crates/kernel/src/body.rs b/crates/kernel/src/body.rs index 4d3803cda..5b2b5e6af 100644 --- a/crates/kernel/src/body.rs +++ b/crates/kernel/src/body.rs @@ -940,7 +940,10 @@ impl Body { } } match self.meshes.as_ref().filter(|m| std::sync::Arc::ptr_eq(&m.record, &self.record)) { - Some(memo) => Ok(Mesh::clone(&remembered(&memo.made, t, || self.mesh_of(&self.mesh_plan_untimed(t)?))?)), + Some(memo) => { + let kept: std::sync::Arc = remembered(&memo.made, t, || self.mesh_of(&self.mesh_plan_untimed(t)?))?; + Ok(Mesh::clone(&kept)) + } None => self.mesh_of(&self.mesh_plan_untimed(t)?), } } diff --git a/crates/kernel/src/bridge.rs b/crates/kernel/src/bridge.rs index 4f66db2b6..7f2f0677e 100644 --- a/crates/kernel/src/bridge.rs +++ b/crates/kernel/src/bridge.rs @@ -186,7 +186,7 @@ impl ChainLine { } curves.push((c, [a, z])); } - let closed = closes(&r, chain); + let closed = closes(r, chain); if closed && let Some(first) = samples.first().copied() { push(&mut samples, first.p, chain.len().saturating_sub(1), first.t); } @@ -322,7 +322,7 @@ pub fn frames(body: &Body, face: usize, chain: &Chain, leave: Vec3, count: usize let line = ChainLine::of(body, chain)?; let stations = line.stations(count, 0.0, false)?; let r = body.record(); - frames_on(&r, &vec![face; chain.len()], &stations, &line, leave) + frames_on(r, &vec![face; chain.len()], &stations, &line, leave) } /// The frames at `stations` (points on `line`, each with the index of the chain edge it is on), @@ -392,7 +392,7 @@ pub fn frames_across(body: &Body, face: usize, stations: &[(Vec3, Vec3)], length return Err(KernelError::Invalid("frames across a boundary need at most 65536 stations on a boundary of finite size".into())); } let r = body.record(); - let support = Support::of(&r, face, length)?; + let support = Support::of(r, face, length)?; let outward = if support.forward { 1.0 } else { -1.0 }; let mut walk = Walk::new(length); let mut out = Vec::with_capacity(stations.len()); @@ -917,13 +917,13 @@ pub fn blend_between( (mid_a - mid_b).normalized().ok_or_else(|| KernelError::Invalid("the two boundaries coincide: there is nothing to blend".into()))?, ), }; - let faces_a = support_faces(&record_a, &chain_a, leave_a, a.size())?; - let faces_b = support_faces(&record_b, &chain_b, leave_b, b.size())?; + let faces_a = support_faces(record_a, &chain_a, leave_a, a.size())?; + let faces_b = support_faces(record_b, &chain_b, leave_b, b.size())?; let (start_a, backwards_a) = seam.map_or((0.0, false), |[p, _]| line_a.start_at_seam(p)); let stations_a = line_a.stations(samples, start_a, backwards_a)?; let stations_b = pair_with(&stations_a, &line_b, seam.map(|[_, q]| q))?; - let frames_a = frames_on(&record_a, &faces_a, &stations_a, &line_a, leave_a)?; - let frames_b = frames_on(&record_b, &faces_b, &stations_b, &line_b, leave_b)?; + let frames_a = frames_on(record_a, &faces_a, &stations_a, &line_a, leave_a)?; + let frames_b = frames_on(record_b, &faces_b, &stations_b, &line_b, leave_b)?; let made = bridge(&frames_a, &frames_b, orders, crown)?; let gap = boundary_gap(&made, &line_a, false)?.max(boundary_gap(&made, &line_b, true)?); // The blend's face is new to the operation over `[a, b]`. diff --git a/crates/kernel/src/loft_rails.rs b/crates/kernel/src/loft_rails.rs index 5c65c5f1e..6f6d2b460 100644 --- a/crates/kernel/src/loft_rails.rs +++ b/crates/kernel/src/loft_rails.rs @@ -36,7 +36,7 @@ impl Section { /// The sketch segments `segs` on `plane` as a section (their exact record curves), segment i /// standing for the profile segments `numbers[i]`. pub(crate) fn of(plane: &Plane, segs: &[Seg2], numbers: Vec>) -> Result
{ - let curves = segs.iter().map(|s| Ok(nurbs(&crate::freeform::segment(plane, s)?.0)?)).collect::>>()?; + let curves = segs.iter().map(|s| nurbs(&crate::freeform::segment(plane, s)?.0)).collect::>>()?; Ok(Section { plane: *plane, curves, numbers }) } } diff --git a/crates/kernel/src/smlib_sweeps.rs b/crates/kernel/src/smlib_sweeps.rs index ed4055527..72074cc5f 100644 --- a/crates/kernel/src/smlib_sweeps.rs +++ b/crates/kernel/src/smlib_sweeps.rs @@ -284,7 +284,7 @@ mod imp { let brep = Brep::make_sphere(p(center), radius).map_err(|e| failed("sphere", e))?; let body = body_of(&brep, "sphere")?; let faces = body.face_count(); - record::attach(body, &[], Some(vec![record::profile(&[0usize]); faces]), Default::default()) + Ok(record::attach(body, &[], Some(vec![record::profile(&[0usize]); faces]), &[])) } /// A point a wall is known by: on its edge in the start plane, or inside it; and the piece @@ -407,7 +407,7 @@ mod imp { } fn with_history(body: Body, roles: &[Role], pieces: &[Piece]) -> Result { - record::attach(body, &[], Some(history(roles, pieces)), Default::default()) + Ok(record::attach(body, &[], Some(history(roles, pieces)), &[])) } /// The profile `pieces` on `plane`, moved `from` along its normal, extruded `distance` diff --git a/crates/kernel/src/surface_ruled.rs b/crates/kernel/src/surface_ruled.rs index c5495e8c6..272bff8d3 100644 --- a/crates/kernel/src/surface_ruled.rs +++ b/crates/kernel/src/surface_ruled.rs @@ -481,7 +481,7 @@ impl Strip { let mut uses: Vec<(b::Curve, [f64; 2], [u32; 2], bool, Option)> = Vec::new(); let ruled = matches!(self.kind, Kind::Ruled); uses.push((base, base_iv, [corners[0], corners[1]], true, ruled.then_some(([u0, 0.0], [u1, 0.0])))); - let mut chain_up = |pts: &[Vec3], from: u32, u: f64, parts: &mut Parts, uses: &mut Vec<_>| -> Result { + let chain_up = |pts: &[Vec3], from: u32, u: f64, parts: &mut Parts, uses: &mut Vec<_>| -> Result { let mut at = from; for w in pts.windows(2) { let next = vertex(w[1], parts)?; diff --git a/crates/kernel/src/surface_trim.rs b/crates/kernel/src/surface_trim.rs index c63423d68..ca945ee0d 100644 --- a/crates/kernel/src/surface_trim.rs +++ b/crates/kernel/src/surface_trim.rs @@ -67,7 +67,7 @@ pub fn trim_keep(body: &Body, tool: &SplitTool, keep: TrimKeep) -> Result let (split, _) = crate::splitface::split_any(body, &all, tool)?; let kept: Vec = match keep { TrimKeep::Side(p) if crate::splitface::field_count(tool)? == 1 => { - let side = ToolSide::of(tool)?; + let side = ToolSide::of(tool, body)?; let want = side.at(p); if !want.is_finite() { return Err(KernelError::Invalid("the side of the tool the point is on can't be told".into())); @@ -162,7 +162,7 @@ pub fn mutual_trim(a: &Body, b: &Body, keep_a: TrimKeep, keep_b: TrimKeep, exten /// `x` trimmed by `tool` where the tool crosses it; whole where it ends on the tool; extended to /// the tool first (when `extend`) where it stops short of it. fn cut_by(x: &Body, tool: &SplitTool, keep: TrimKeep, extend: bool, name: &str) -> Result { - let side = ToolSide::of(tool)?; + let side = ToolSide::of(tool, x)?; let size = x.size(); let touch = size * 1e-6 + 1e-9; let m = x.mesh(&crate::MeshTolerance::chord(size * 2e-3))?; diff --git a/crates/kernel/src/surfaces.rs b/crates/kernel/src/surfaces.rs index f913517cc..78546a74a 100644 --- a/crates/kernel/src/surfaces.rs +++ b/crates/kernel/src/surfaces.rs @@ -302,7 +302,7 @@ pub(crate) fn surface_body(r: &Brep) -> Result { pub(crate) fn all_new(body: Body, operands: &[&Body]) -> Result { let r = body.record(); let faces = vec![record::generated(Vec::new()); r.faces.len()]; - let h = record_history(&r, operands.len(), faces, |_, _, _| Vec::new()); + let h = record_history(r, operands.len(), faces, |_, _, _| Vec::new()); body.with_history_counts(h, &record::counts(operands)) } @@ -469,15 +469,6 @@ pub fn patch_edges(body: &Body, at: &[Vec3]) -> Result { crate::fill::patch_loop(body, at, 0.0) } -/// The edges of `body` picked by points on them, chained into one closed loop (each turned to run -/// along it). -pub(crate) fn picked_loop(body: &Body, at: &[Vec3]) -> Result { - match picked_chain(body, at)? { - (chain, true) => Ok(chain), - (_, false) => Err(invalid("the edges do not form a closed loop")), - } -} - /// The edges of `body` picked by points on them, chained end to end (each turned to run along the /// chain), and whether the chain closes: a closed loop starts with the last edge picked; an open /// chain runs from the free end met first in pick order. Edges that branch, or form more than one @@ -574,7 +565,7 @@ pub fn copy_faces(body: &Body, at: &[Vec3]) -> Result { } let chosen = picked_faces(body, at)?; let r = body.record(); - taken(body, &r, &chosen.into_iter().map(|f| (f, false)).collect::>()) + taken(body, r, &chosen.into_iter().map(|f| (f, false)).collect::>()) } /// A body's faces taken apart: each picked face (by points on it; every face when none are given) @@ -587,9 +578,9 @@ pub fn unstitch(body: &Body, at: &[Vec3]) -> Result<(Vec, Option)> { return Err(invalid("the body has one face: nothing to unstitch")); } let chosen = picked_faces(body, at)?; - let pieces = chosen.iter().map(|f| taken(body, &r, &[(*f, false)])).collect::>>()?; + let pieces = chosen.iter().map(|f| taken(body, r, &[(*f, false)])).collect::>>()?; let rest: Vec<(usize, bool)> = (0..r.faces.len()).filter(|f| !chosen.contains(f)).map(|f| (f, false)).collect(); - let rest = if rest.is_empty() { None } else { Some(taken(body, &r, &rest)?) }; + let rest = if rest.is_empty() { None } else { Some(taken(body, r, &rest)?) }; Ok((pieces, rest)) } @@ -603,7 +594,7 @@ pub fn reverse_faces(body: &Body, at: &[Vec3]) -> Result { } let chosen = picked_faces(body, at)?; let r = body.record(); - taken(body, &r, &(0..r.faces.len()).map(|f| (f, chosen.contains(&f))).collect::>()) + taken(body, r, &(0..r.faces.len()).map(|f| (f, chosen.contains(&f))).collect::>()) } /// A body with some of its faces (indices in its face order) taken away and the gap left open: a @@ -619,7 +610,7 @@ pub fn remove_faces(body: &Body, faces: &[usize]) -> Result { if left.is_empty() { return Err(invalid("that would delete every face of the body")); } - taken(body, &r, &left) + taken(body, r, &left) } /// `h`, a history over one record whose faces and edges came from the parts `c` numbers, carried @@ -763,9 +754,9 @@ pub fn thicken(body: &Body, thickness: f64, symmetric: bool) -> Result { pub(crate) fn offset_faces(body: &Body, picked: &[usize], distance: f64, tolerance: f64) -> Result { let r = body.record(); if distance == 0.0 { - return taken(body, &r, &picked.iter().map(|f| (*f, false)).collect::>()); + return taken(body, r, &picked.iter().map(|f| (*f, false)).collect::>()); } - let moved = picked.iter().map(|f| imp::offset_face(&r, *f, distance)).collect::>>()?; + let moved = picked.iter().map(|f| imp::offset_face(r, *f, distance)).collect::>>()?; let (parts, offsets) = Parts::joined(&moved.iter().collect::>())?; let c = parts.canonical()?; let (result, h) = imp::stitched(&c.brep, tolerance.max(c.brep.tolerance))?; @@ -774,7 +765,7 @@ pub(crate) fn offset_faces(body: &Body, picked: &[usize], distance: f64, toleran .and_then(|h| carried(&h, &c, &offsets, 1, offset)) .map(|h| h.faces.into_iter().map(|f| FaceProv { change: Change::Generated, ..f }).collect::>()); let rec = result.record(); - let h = faces.map(|faces| record_history(&rec, 1, faces, |_, between, faces| record::meeting(between, faces))); + let h = faces.map(|faces| record_history(rec, 1, faces, |_, between, faces| record::meeting(between, faces))); Ok(result.with_checked_history(h, &record::counts(&[body]))) } @@ -850,7 +841,7 @@ pub fn extend(body: &Body, at: &[Vec3], distance: f64) -> Result { .collect::>>()?; let loops = vec![b::Loop::Edges { edges }]; let domain = uv_box(&loops).ok_or_else(|| invalid("the extended face has no area"))?; - let forward = face_sides(&r).first().copied().unwrap_or(true); + let forward = face_sides(r).first().copied().unwrap_or(true); parts.faces.push((b::Face { surface, domain, loops }, forward)); let c = parts.canonical()?; let h = record_history(&c.brep, 1, vec![record::from_face(0, 0, Change::Modified)], |e, _, _| {