mirror of
https://github.com/bherbruck/solidcraft.git
synced 2026-11-04 02:55:54 +00:00
kernel: clippy's own fixes across the kernel (needless borrows, assign ops, contains)
Machine-applied by cargo clippy --fix: borrows the compiler dereferences at once, an unused import, a manual += , an entry() for contains_key+insert, a needless Ok(?), contains() for iter().any(). No behaviour changes. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_017itGh5fpMEousnZ91cYcVt
This commit is contained in:
@@ -167,7 +167,7 @@ pub(crate) fn curve_derivative(c: &Curve, t: f64) -> Option<Vec3> {
|
||||
let (_, su, sv) = e.derivs(uv[0], uv[1])?;
|
||||
Some(su.cross(sv))
|
||||
};
|
||||
let along = normal(&*surfaces[0])?.cross(normal(&*surfaces[1])?);
|
||||
let along = normal(&surfaces[0])?.cross(normal(&surfaces[1])?);
|
||||
let along = along.normalized()?;
|
||||
if along.dot(curve_tangent(leader, t)?) < 0.0 { along * -1.0 } else { along }
|
||||
}
|
||||
|
||||
@@ -485,7 +485,7 @@ fn newell(ring: &[Vec3]) -> Option<Vec3> {
|
||||
let mut s = Vec3::ZERO;
|
||||
for i in 0..n {
|
||||
let (a, b) = (*ring.get(i)?, *ring.get((i + 1) % n)?);
|
||||
s = s + a.cross(b);
|
||||
s += a.cross(b);
|
||||
}
|
||||
s.normalized()
|
||||
}
|
||||
|
||||
@@ -311,9 +311,9 @@ fn shell(w: &mut W, b: &Brep, si: u32, paint: &HashMap<usize, [f32; 3]>) -> Resu
|
||||
None => {
|
||||
let e = b.edges.get(u.edge as usize).ok_or_else(|| failed(format!("edge {}: no such edge", u.edge)))?;
|
||||
for v in e.vertices {
|
||||
if !vidx.contains_key(&v) {
|
||||
if let std::collections::hash_map::Entry::Vacant(e) = vidx.entry(v) {
|
||||
let p = b.vertices.get(v as usize).ok_or_else(|| failed(format!("vertex {v}: no such vertex")))?.point;
|
||||
vidx.insert(v, verts.len());
|
||||
e.insert(verts.len());
|
||||
verts.push(p);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -69,13 +69,13 @@ pub fn match_surface(body: &Body, faces: &[Vec3], target: &Body, target_pick: &[
|
||||
return Err(KernelError::Invalid("match rebuilds a surface body: this one is closed".into()));
|
||||
}
|
||||
let (record, target_record) = (body.record(), target.record());
|
||||
let face = face_near(&record, faces, body.size() * 0.05 + 1e-6)?;
|
||||
let original = Patch::of(&record, face)?;
|
||||
let face = face_near(record, faces, body.size() * 0.05 + 1e-6)?;
|
||||
let original = Patch::of(record, face)?;
|
||||
let chain = bridge::chain(target, target_pick)?;
|
||||
let line = chain_polyline(&target_record, &chain)?;
|
||||
let line = chain_polyline(target_record, &chain)?;
|
||||
let near = nearest_side(&original, &line)?;
|
||||
let far = near.opposite();
|
||||
let far_edges = side_edges(&record, face, &original, far, body.size() * 1e-6 + 1e-9)?;
|
||||
let far_edges = side_edges(record, face, &original, far, body.size() * 1e-6 + 1e-9)?;
|
||||
let (mid_near, mid_far) = (chain_mid(&line)?, original.at(far, 0.5)?);
|
||||
let leave = (mid_far - mid_near)
|
||||
.normalized()
|
||||
@@ -111,7 +111,7 @@ pub fn match_surface(body: &Body, faces: &[Vec3], target: &Body, target_pick: &[
|
||||
for crown_near in CROWNS {
|
||||
for crown_far in CROWNS {
|
||||
let made = bridge::bridge(&near_frames, &far_frames, [order, Continuity::G1], [crown_near, crown_far])?;
|
||||
let stray = deviation(&Patch::of(&made.record(), 0)?, &original)?;
|
||||
let stray = deviation(&Patch::of(made.record(), 0)?, &original)?;
|
||||
if best.as_ref().is_none_or(|(b, _)| stray < *b) {
|
||||
best = Some((stray, made));
|
||||
}
|
||||
@@ -124,11 +124,11 @@ pub fn match_surface(body: &Body, faces: &[Vec3], target: &Body, target_pick: &[
|
||||
// same way round, which is what a stitch, a thicken or a display of the result reads.
|
||||
let seam = chain_mid(&line)?;
|
||||
let made_record = made.record();
|
||||
let turn = match (Patch::of(&made_record, 0)?.normal_near(seam), Patch::of(&target_record, target_face)?.normal_near(seam)) {
|
||||
let turn = match (Patch::of(made_record, 0)?.normal_near(seam), Patch::of(target_record, target_face)?.normal_near(seam)) {
|
||||
(Some((m, _)), Some((t, _))) => m.dot(t) < 0.0,
|
||||
_ => false,
|
||||
};
|
||||
let kept = crate::surfaces::Parts::of(&made_record, &[(0, turn)])?.canonical()?;
|
||||
let kept = crate::surfaces::Parts::of(made_record, &[(0, turn)])?.canonical()?;
|
||||
let sheet = crate::surfaces::surface_body(&kept.brep)?;
|
||||
let history = History {
|
||||
operands: 2,
|
||||
@@ -147,12 +147,12 @@ pub fn seam_continuity(made: &Body, target: &Body, target_pick: &[Vec3]) -> Resu
|
||||
target.require_brep("match")?;
|
||||
let (record, target_record) = (made.record(), target.record());
|
||||
let chain = bridge::chain(target, target_pick)?;
|
||||
let poly = chain_polyline(&target_record, &chain)?;
|
||||
let poly = chain_polyline(target_record, &chain)?;
|
||||
// The face whose boundary runs along the chain: the one nearest it, so that a body that has
|
||||
// not been matched yet — where the seam is still some way off — can be measured too.
|
||||
let mid = chain_mid(&poly)?;
|
||||
let face = (0..record.faces.len())
|
||||
.filter_map(|f| Patch::of(&record, f).ok().and_then(|p| p.normal_near(mid).map(|(_, d)| (d, p))))
|
||||
.filter_map(|f| Patch::of(record, f).ok().and_then(|p| p.normal_near(mid).map(|(_, d)| (d, p))))
|
||||
.min_by(|a, b| a.0.total_cmp(&b.0))
|
||||
.map(|(_, p)| p)
|
||||
.ok_or_else(|| KernelError::Failed("match: the body has no faces".into()))?;
|
||||
@@ -165,7 +165,7 @@ pub fn seam_continuity(made: &Body, target: &Body, target_pick: &[Vec3]) -> Resu
|
||||
let Some(&(target_face, _)) = candidates.first() else {
|
||||
return Err(KernelError::Invalid("no face of the target holds the picked edges".into()));
|
||||
};
|
||||
let target_patch = Patch::of(&target_record, target_face)?;
|
||||
let target_patch = Patch::of(target_record, target_face)?;
|
||||
let frames = bridge::frames(target, target_face, &chain, leave, STATIONS)?;
|
||||
let size = target.size();
|
||||
let (mut gap, mut deg, mut curv, mut bend) = (0.0f64, 0.0f64, 0.0f64, 0.0f64);
|
||||
@@ -472,7 +472,7 @@ fn support_faces(target: &Body, chain: &Chain, poly: &[Vec3], leave: Vec3) -> Re
|
||||
if !chain.iter().all(|(e, _)| bounds(f, *e)) {
|
||||
continue;
|
||||
}
|
||||
let Some((n, d)) = Patch::of(&r, f).ok().and_then(|p| p.normal_near(mid)) else { continue };
|
||||
let Some((n, d)) = Patch::of(r, f).ok().and_then(|p| p.normal_near(mid)) else { continue };
|
||||
if d > tol {
|
||||
continue;
|
||||
}
|
||||
@@ -505,13 +505,13 @@ fn supply_order(target: &Body, candidates: &[(usize, f64)], chain: &Chain, leave
|
||||
}
|
||||
let r = target.record();
|
||||
let size = target.size();
|
||||
let first_patch = Patch::of(&r, first)?;
|
||||
let first_patch = Patch::of(r, first)?;
|
||||
let primary: Vec<Frame> = bridge::frames(target, first, chain, leave, STATIONS)?;
|
||||
for &other in keep.iter().skip(1) {
|
||||
// A face that cannot be read along the whole chain says nothing here: the face the match
|
||||
// is built on is the one that must be able to supply it.
|
||||
let Ok(other_frames) = bridge::frames(target, other, chain, leave, STATIONS) else { continue };
|
||||
let other_patch = Patch::of(&r, other)?;
|
||||
let other_patch = Patch::of(r, other)?;
|
||||
let mut worst_deg = 0.0f64;
|
||||
let mut worst = 0.0f64;
|
||||
let mut worst_change = 0.0f64;
|
||||
|
||||
@@ -72,9 +72,9 @@ fn edge_at(body: &Body, p: Vec3) -> Chain {
|
||||
/// How far the rebuilt face's far boundary lies from the original one, in mm: the far row of the
|
||||
/// rebuilt surface sampled at its own stations, against the original boundary edge's own points.
|
||||
fn far_drift(made: &Body, sheet: &Body, far_mid: Vec3) -> f64 {
|
||||
let patch = Patch::of(&made.record(), 0).unwrap();
|
||||
let patch = Patch::of(made.record(), 0).unwrap();
|
||||
let ((u0, u1), (_, v1)) = (patch.ranges[0], patch.ranges[1]);
|
||||
let poly = chain_polyline(&sheet.record(), &edge_at(sheet, far_mid)).unwrap();
|
||||
let poly = chain_polyline(sheet.record(), &edge_at(sheet, far_mid)).unwrap();
|
||||
let mut worst = 0.0f64;
|
||||
for k in 0..=8 {
|
||||
let p = patch.surface.point([u0 + (u1 - u0) * k as f64 / 8.0, v1]).unwrap();
|
||||
@@ -87,7 +87,7 @@ fn far_drift(made: &Body, sheet: &Body, far_mid: Vec3) -> f64 {
|
||||
/// point, the unit tangent, the curvature vector and the change of that curvature, read off the
|
||||
/// finished surface (never from the construction).
|
||||
fn seam_at(body: &Body, t: f64) -> (Vec3, Vec3, Vec3, Vec3) {
|
||||
Patch::of(&body.record(), 0).unwrap().seam_shape(Side::V0, t).unwrap()
|
||||
Patch::of(body.record(), 0).unwrap().seam_shape(Side::V0, t).unwrap()
|
||||
}
|
||||
|
||||
/// The stations a seam is measured at, as fractions of its length.
|
||||
@@ -122,7 +122,7 @@ fn a_g2_match_meets_a_cylinder_with_its_own_curvature() {
|
||||
println!("g2: far boundary drift {drift:e} mm");
|
||||
assert!(drift < 1e-9, "the far boundary drifted {drift:e} mm");
|
||||
// The interior stays near the original: the crowning that leaves it closest.
|
||||
let stray = deviation(&Patch::of(&made.record(), 0).unwrap(), &Patch::of(&sheet.record(), 0).unwrap()).unwrap();
|
||||
let stray = deviation(&Patch::of(made.record(), 0).unwrap(), &Patch::of(sheet.record(), 0).unwrap()).unwrap();
|
||||
println!("g2: interior stray {stray:.6} mm rms");
|
||||
// The seam moved 1 mm, so the face cannot be closer than that at the seam itself: over the
|
||||
// whole face the root mean square distance is well under half of it.
|
||||
|
||||
@@ -91,7 +91,7 @@ pub fn untrim(body: &Body, face: usize, holes: UntrimHoles, outer: bool, in_plac
|
||||
(Some(ob), Some(or)) => r.history().map_err(|e| failed("history", e))?.history(&[ob], &or).ok().map(|mut h| {
|
||||
// The untrimmed face is the face it was, bounded differently.
|
||||
for p in &mut h.faces {
|
||||
if p.origins.iter().any(|o| *o == FaceOrigin::Face { operand: 0, face }) {
|
||||
if p.origins.contains(&FaceOrigin::Face { operand: 0, face }) {
|
||||
p.change = Change::Modified;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user