Thread work in rustfmt's layout

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
jyvikoandClaude Opus 5.5 committed 2026-10-27 02:28:53 -04:00
1 parent d433ce2c9f
commit fdede5a0ae
6 files changed
+87 -20

No files matched your search

+20 -3
View File
@@ -23,12 +23,22 @@ pub fn sweep_helix(plane: &Plane, region: &Region2, axis_origin: Vec3, axis: Vec
/// `offset(t)` mm away from the axis (negative: towards it) in its half-plane, `offset` piecewise
/// linear through `law`'s (turn, offset) pairs, turns ascending within [0, `turns`]. A thread's
/// groove fading in or out over a runout: SMLib's radial screw sweep.
pub fn sweep_helix_radial(plane: &Plane, region: &Region2, axis_origin: Vec3, axis: Vec3, pitch: f64, turns: f64, law: &[(f64, f64)]) -> Result<Body> {
pub fn sweep_helix_radial(
plane: &Plane,
region: &Region2,
axis_origin: Vec3,
axis: Vec3,
pitch: f64,
turns: f64,
law: &[(f64, f64)],
) -> Result<Body> {
if law.is_empty() {
return sweep_helix(plane, region, axis_origin, axis, pitch, turns);
}
let (k, profile) = helix_profile(plane, region, axis_origin, axis, pitch, turns)?;
if !law.windows(2).all(|w| matches!(w, [a, b] if b.0 > a.0)) || law.iter().any(|(t, o)| !(t.is_finite() && o.is_finite() && *t >= 0.0 && *t <= turns)) {
if !law.windows(2).all(|w| matches!(w, [a, b] if b.0 > a.0))
|| law.iter().any(|(t, o)| !(t.is_finite() && o.is_finite() && *t >= 0.0 && *t <= turns))
{
return Err(KernelError::Invalid("helix: the radial law's turns must ascend within the sweep's turns".into()));
}
crate::smlib_sweeps::screw_radial(plane, &crate::smlib_sweeps::pieces([&profile]), axis_origin, k, pitch, turns, law)
@@ -36,7 +46,14 @@ pub fn sweep_helix_radial(plane: &Plane, region: &Region2, axis_origin: Vec3, ax
/// A helical sweep's axis and profile (the region's outer loop), checked: finite turns and
/// pitch, an area, and a profile that clears itself after one turn.
fn helix_profile(plane: &Plane, region: &Region2, axis_origin: Vec3, axis: Vec3, pitch: f64, turns: f64) -> Result<(Vec3, crate::numbered::NumberedLoop)> {
fn helix_profile(
plane: &Plane,
region: &Region2,
axis_origin: Vec3,
axis: Vec3,
pitch: f64,
turns: f64,
) -> Result<(Vec3, crate::numbered::NumberedLoop)> {
let k = axis.normalized().ok_or_else(|| KernelError::Invalid("helix axis".into()))?;
if !(pitch.is_finite() && turns.is_finite() && turns > 0.0 && turns <= 200.0 && pitch.abs() < 1e7 && axis_origin.is_finite()) {
return Err(KernelError::Invalid("helix: turns must be in (0, 200] and the pitch finite".into()));
+11 -3
View File
@@ -71,8 +71,8 @@ pub(crate) struct Draft {
}
pub(crate) use imp::{
body_from_record, curve, extrude, face_section, loft, loft_rails, loft_to_point, path_curve, project_onto_face, revolve, screw, screw_radial, sphere, sweep,
sweep_controlled,
body_from_record, curve, extrude, face_section, loft, loft_rails, loft_to_point, path_curve, project_onto_face, revolve, screw, screw_radial,
sphere, sweep, sweep_controlled,
};
/// Refuses what no SMLib sweep does, before any work.
@@ -1267,7 +1267,15 @@ mod imp {
/// [`screw`] with the profile moved `offset(t)` mm off the axis at turn t (negative: towards
/// it), piecewise linear through `law`'s (turn, offset) pairs: a groove fading over a runout.
pub(crate) fn screw_radial(plane: &Plane, pieces: &[Piece], origin: Vec3, axis: Vec3, pitch: f64, turns: f64, law: &[(f64, f64)]) -> Result<Body> {
pub(crate) fn screw_radial(
plane: &Plane,
pieces: &[Piece],
origin: Vec3,
axis: Vec3,
pitch: f64,
turns: f64,
law: &[(f64, f64)],
) -> Result<Body> {
let c = curves(plane, pieces)?;
let tolerance = (pitch.abs() * 1e-4).clamp(1e-6, 1e-2);
let brep =
+1 -2
View File
@@ -365,8 +365,7 @@ pub fn material_in_ring(b: &Body, c: &CylinderFace, r_in: f64, r_out: f64, along
if !(r_in >= 0.0 && r_out > r_in && a1 > a0 && r_out.is_finite() && a0.is_finite() && a1.is_finite()) {
return Err(crate::KernelError::Invalid(format!("ring r {r_in}..{r_out} over {a0}..{a1}")));
}
let plane =
Plane::from_normal(c.axis_point + c.axis * a0, *c.axis).ok_or_else(|| crate::KernelError::Invalid("ring axis".into()))?;
let plane = Plane::from_normal(c.axis_point + c.axis * a0, *c.axis).ok_or_else(|| crate::KernelError::Invalid("ring axis".into()))?;
// Circles started at the primitives' odd seam angle, off the frame's axes (as `cylinder`).
let seam = crate::build::SEAM_ANGLE;
let holes = if r_in > 0.0 { vec![Loop2::circle_from(Vec2::ZERO, r_in, seam).reversed()] } else { Vec::new() };