diff --git a/assets/locales/pending/pipe-threads.json b/assets/locales/pending/pipe-threads.json new file mode 100644 index 000000000..63203d894 --- /dev/null +++ b/assets/locales/pending/pipe-threads.json @@ -0,0 +1,44 @@ +{ + "en": { + "thread.form_bspp": "Pipe G (ISO 228-1)", + "thread.form_bspt": "Pipe taper R, Rc (ISO 7-1)", + "thread.form_npt": "Pipe taper NPT (ASME B1.20.1)", + "thread.form_rp": "Pipe Rp (ISO 7-1)" + }, + "ar": { + "thread.form_bspp": "سن أنابيب G (ISO 228-1)", + "thread.form_bspt": "سن أنابيب مخروطي R، Rc (ISO 7-1)", + "thread.form_npt": "سن أنابيب مخروطي NPT (ASME B1.20.1)", + "thread.form_rp": "سن أنابيب داخلي متوازٍ Rp (ISO 7-1)" + }, + "he": { + "thread.form_bspp": "תבריג צנרת G (ISO 228-1)", + "thread.form_bspt": "תבריג צנרת קוני R, Rc (ISO 7-1)", + "thread.form_npt": "תבריג צנרת קוני NPT (ASME B1.20.1)", + "thread.form_rp": "תבריג צנרת פנימי מקביל Rp (ISO 7-1)" + }, + "ja": { + "thread.form_bspp": "管用平行ねじ G(ISO 228-1)", + "thread.form_bspt": "管用テーパねじ R、Rc(ISO 7-1)", + "thread.form_npt": "管用テーパねじ NPT(ASME B1.20.1)", + "thread.form_rp": "管用平行めねじ Rp(ISO 7-1)" + }, + "zh": { + "thread.form_bspp": "管螺纹 G(ISO 228-1)", + "thread.form_bspt": "圆锥管螺纹 R、Rc(ISO 7-1)", + "thread.form_npt": "圆锥管螺纹 NPT(ASME B1.20.1)", + "thread.form_rp": "圆柱内管螺纹 Rp(ISO 7-1)" + }, + "de": { + "thread.form_bspp": "Rohrgewinde G (ISO 228-1)", + "thread.form_bspt": "Kegeliges Rohrgewinde R, Rc (ISO 7-1)", + "thread.form_npt": "Kegeliges Rohrgewinde NPT (ASME B1.20.1)", + "thread.form_rp": "Zylindrisches Innenrohrgewinde Rp (ISO 7-1)" + }, + "ko": { + "thread.form_bspp": "관용 평행나사 G (ISO 228-1)", + "thread.form_bspt": "관용 테이퍼나사 R, Rc (ISO 7-1)", + "thread.form_npt": "관용 테이퍼나사 NPT (ASME B1.20.1)", + "thread.form_rp": "관용 평행 암나사 Rp (ISO 7-1)" + } +} diff --git a/assets/locales/pending/thread-ends.json b/assets/locales/pending/thread-ends.json new file mode 100644 index 000000000..e4f73990b --- /dev/null +++ b/assets/locales/pending/thread-ends.json @@ -0,0 +1,65 @@ +{ + "en": { + "thread.chamfer_depth_needed": "required for this form", + "thread.end_square": "Square", + "thread.fade_short": "1.25 P (ISO 3508)", + "thread.fade_standard": "2.5 P (ISO 3508)", + "ui.end": "End", + "ui.fade": "Fade", + "ui.fade_length": "Fade Length" + }, + "ar": { + "thread.chamfer_depth_needed": "مطلوب لهذا الشكل", + "thread.end_square": "قائمة", + "thread.fade_short": "1.25 P (ISO 3508)", + "thread.fade_standard": "2.5 P (ISO 3508)", + "ui.end": "النهاية", + "ui.fade": "تلاشٍ", + "ui.fade_length": "طول التلاشي" + }, + "he": { + "thread.chamfer_depth_needed": "נדרש לצורה זו", + "thread.end_square": "ישר", + "thread.fade_short": "1.25 P (ISO 3508)", + "thread.fade_standard": "2.5 P (ISO 3508)", + "ui.end": "סוף", + "ui.fade": "דעיכה", + "ui.fade_length": "אורך דעיכה" + }, + "ja": { + "thread.chamfer_depth_needed": "この形状では必須", + "thread.end_square": "直角", + "thread.fade_short": "1.25 P(ISO 3508)", + "thread.fade_standard": "2.5 P(ISO 3508)", + "ui.end": "終端", + "ui.fade": "切り上げ", + "ui.fade_length": "切り上げ長さ" + }, + "zh": { + "thread.chamfer_depth_needed": "此牙型必填", + "thread.end_square": "直角", + "thread.fade_short": "1.25 P(ISO 3508)", + "thread.fade_standard": "2.5 P(ISO 3508)", + "ui.end": "末端", + "ui.fade": "收尾", + "ui.fade_length": "收尾长度" + }, + "de": { + "thread.chamfer_depth_needed": "für diese Form erforderlich", + "thread.end_square": "Rechtwinklig", + "thread.fade_short": "1,25 P (ISO 3508)", + "thread.fade_standard": "2,5 P (ISO 3508)", + "ui.end": "Ende", + "ui.fade": "Auslauf", + "ui.fade_length": "Auslauflänge" + }, + "ko": { + "thread.chamfer_depth_needed": "이 형상에 필요", + "thread.end_square": "직각", + "thread.fade_short": "1.25 P (ISO 3508)", + "thread.fade_standard": "2.5 P (ISO 3508)", + "ui.end": "끝", + "ui.fade": "페이드", + "ui.fade_length": "페이드 길이" + } +} diff --git a/crates/doc/src/document.rs b/crates/doc/src/document.rs index ce847c458..26951d142 100644 --- a/crates/doc/src/document.rs +++ b/crates/doc/src/document.rs @@ -868,9 +868,8 @@ pub enum FeatureKind { /// Starts (1 to 8): the lead is starts × pitch (unless `designation` gives the lead). #[serde(default = "crate::thread_forms::one_start", skip_serializing_if = "crate::thread_forms::is_one_start")] starts: u32, - /// Runout lengths at the thread's start and end (a groove that fades out). - #[serde(default, skip_serializing_if = "Option::is_none")] - ease_in: Option, + /// The runout at the thread's inner end, the one away from where it starts (a groove + /// that fades out); none: the groove stops square there. #[serde(default, skip_serializing_if = "Option::is_none")] ease_out: Option, /// The chamfered tip at the thread's free end (ISO 4753). diff --git a/crates/doc/src/eval_thread.rs b/crates/doc/src/eval_thread.rs index 8c603b134..dd864c17d 100644 --- a/crates/doc/src/eval_thread.rs +++ b/crates/doc/src/eval_thread.rs @@ -83,9 +83,9 @@ pub(super) struct ThreadAsk<'a> { pub from: Option, /// A modelled thread needs to know how each of its ends meets the face's ends. pub modeled: bool, - /// Runouts at the end the thread starts from and at the other, each as (mm, pitches): its - /// length is mm + pitches x the pitch. - pub ease: [(f64, f64); 2], + /// The runout at the end away from where the thread starts, as (mm, pitches): its length + /// is mm + pitches x the pitch. The start never fades: it runs off its free end. + pub ease_out: (f64, f64), /// A tapped hole's thread: `designation` is a catalogue size (ISO metric, or a catalogued /// UNC/UNF, G or Rp size), and a size that is not metric fits the hole drilled for it. pub tapped: bool, @@ -118,12 +118,20 @@ pub(super) struct ThreadOn { } /// The free-end test of a face's two ends (`side` 0 at its start, 1 at its end), each made -/// once: whether any material lies past the end, over the axial span the groove's one-pitch -/// overrun reaches beyond its first pitch, within the radii the groove cuts. +/// once. The groove's one-pitch overrun past a free end reaches 1.5 pitches past it. An end is +/// closed when, within that reach, material lies outside the face's cylinder (inside it, for a +/// hole) at the radii the groove cuts beyond the face: a shoulder, a plate, a head, a blind +/// hole's bottom, however thin, the material stepping out past the face. It is closed too when +/// material lies in the groove's band of radii beyond its first pitch: the face's cylinder going +/// on past a split. A chamfer, a neck, a countersink or a counterbore steps the other way and +/// leaves the end free: the groove runs out through it. struct FaceEnds<'a> { body: &'a Body, cyl: &'a kernel::CylinderFace, band: (f64, f64), + /// The radii the groove cuts beyond the face's own: from it out to the groove's outer edge + /// (external), or in to its inner edge (internal). + beyond: (f64, f64), pitch: f64, free: [Option; 2], } @@ -134,11 +142,13 @@ impl FaceEnds<'_> { return Ok(*f); } let p = self.pitch; - let along = if side == 0 { (self.cyl.start - 1.5 * p, self.cyl.start - p) } else { (self.cyl.end + p, self.cyl.end + 1.5 * p) }; - // Material that only touches the band's rims (a counterbore as wide as the thread) is - // not in the groove's way. + let past = + |from: f64, to: f64| if side == 0 { (self.cyl.start - to, self.cyl.start - from) } else { (self.cyl.end + from, self.cyl.end + to) }; + // Material that only touches the band's rims (a counterbore as wide as the thread, the + // face's own end) is not in the groove's way. let e = p * 1e-3; - let free = !kernel::material_in_ring(self.body, self.cyl, self.band.0 + e, self.band.1 - e, along)?; + let stepped_out = kernel::material_in_ring(self.body, self.cyl, self.beyond.0 + e, self.beyond.1 - e, past(e, 1.5 * p))?; + let free = !stepped_out && !kernel::material_in_ring(self.body, self.cyl, self.band.0 + e, self.band.1 - e, past(p, 1.5 * p))?; if let Some(slot) = self.free.get_mut(side) { *slot = Some(free); } @@ -206,6 +216,12 @@ pub(super) fn thread_on(st: &ModelState, feature: u64, p: Vec3, ask: &ThreadAsk) if ask.hand == ThreadHand::Both { return Err(DocError::Invalid("a pipe thread turns one way: right or left".into())); } + // ISO 7-1's Rp is the parallel internal thread an R screws into; there is no external Rp. + if form == ThreadForm::Rp && !cyl.internal { + return Err(DocError::Invalid(format!( + "`{designation}` on this shaft: Rp is an internal thread (ISO 7-1); an external pipe thread is R (taper, ISO 7-1) or G (ISO 228-1)" + ))); + } // ISO 7-1 names the internal taper thread Rc and the external one R. if form == ThreadForm::Bspt { if let Some(given) = ask.designation @@ -240,7 +256,10 @@ pub(super) fn thread_on(st: &ModelState, feature: u64, p: Vec3, ask: &ThreadAsk) (form.groove(major, pitch, false).root_r, major / 2.0) }; let band = (cyl.radius.min(r_lo), cyl.radius.max(r_hi)); - let mut ends = FaceEnds { body: &mb.body, cyl: &cyl, band, pitch, free: [None; 2] }; + // As far beyond the face as the groove's section reaches ([`thread_grooves`]). + let beyond = + if cyl.internal { ((cyl.radius.min(r_lo) - 0.1 * pitch).max(0.0), cyl.radius) } else { (cyl.radius, cyl.radius.max(r_hi) + 0.05 * pitch) }; + let mut ends = FaceEnds { body: &mb.body, cyl: &cyl, band, beyond, pitch, free: [None; 2] }; let (lo, hi) = (cyl.start, cyl.end); let along = |q: Vec3| (q - cyl.axis_point).dot(cyl.axis); let span = |side: usize, to: f64| -> Result<(f64, f64)> { @@ -289,10 +308,9 @@ pub(super) fn thread_on(st: &ModelState, feature: u64, p: Vec3, ask: &ThreadAsk) (a, b, side) } }; - // The runout at each end of the axis: ease in where the thread starts from. - let len = |(mm, pitches): (f64, f64)| mm + pitches * pitch; - let (e_in, e_out) = (len(ask.ease[0]), len(ask.ease[1])); - let ease = if side == 0 { [e_in, e_out] } else { [e_out, e_in] }; + // The runout at each end of the axis: only at the end away from where it starts. + let e_out = ask.ease_out.0 + ask.ease_out.1 * pitch; + let ease = if side == 0 { [0.0, e_out] } else { [e_out, 0.0] }; if ease.iter().any(|e| !(*e >= 0.0 && e.is_finite())) { return Err(DocError::Invalid("a runout length must be positive".into())); } @@ -534,7 +552,7 @@ fn thread_grooves( law.extend([(turns - r_out, 0.0), (turns, out)]); } if r_in > 0.0 && r_out > 0.0 && !(turns - r_out > r_in + 1e-9) || r_in.max(r_out) > turns { - return Err(DocError::Invalid(format!("the runouts ({} and {} mm) are longer than the thread", show_mm(ease[0]), show_mm(ease[1])))); + return Err(DocError::Invalid(format!("the runout ({} mm) is longer than the thread", show_mm(ease[0].max(ease[1]))))); } if taper_rate != 0.0 { law = with_taper(&law, turns, taper_rate); @@ -657,7 +675,6 @@ pub(super) fn eval(doc: &Document, vals: &BTreeMap, f: &Feature, form, hand, starts, - ease_in, ease_out, tip, chamfer_angle, @@ -687,7 +704,7 @@ pub(super) fn eval(doc: &Document, vals: &BTreeMap, f: &Feature, extent, from: from.map(|q| q.0), modeled: *modeled, - ease: [(0.0, 0.0); 2], + ease_out: (0.0, 0.0), tapped: false, }; // ISO 3508's runouts: standard 2.5 P, short 1.25 P. @@ -699,14 +716,11 @@ pub(super) fn eval(doc: &Document, vals: &BTreeMap, f: &Feature, Some(crate::ThreadRunout::Length { length }) => (val(vals, length, Kind::Length)?, 0.0), }) }; - if (ease_in.is_some() || ease_out.is_some()) && !*modeled { + if ease_out.is_some() && !*modeled { return Err(DocError::Invalid("a runout is cut only on a modelled thread".into())); } - let ask = ThreadAsk { ease: [runout(ease_in)?, runout(ease_out)?], ..ask }; + let ask = ThreadAsk { ease_out: runout(ease_out)?, ..ask }; let ThreadOn { info: t, cyl, ends, steep, ease, from: from_side } = thread_on(st, f.id, face.0, &ask)?; - if *tip != ThreadTip::None && t.form.is_taper() { - return Err(DocError::Invalid("not supported yet: a chamfered tip on a taper pipe thread".into())); - } if !*modeled { st.threads.push(t); return Ok(()); @@ -747,7 +761,7 @@ pub(super) fn eval(doc: &Document, vals: &BTreeMap, f: &Feature, if *tip != ThreadTip::None { let angle = chamfer_angle.as_deref().map(|e| val(vals, e, Kind::Angle)).transpose()?; let depth = chamfer_depth.as_deref().map(|e| val(vals, e, Kind::Length)).transpose()?; - for cone in tip_cones(&t, radius, ends, (*tip, from_side), angle, depth)? { + for cone in tip_cones(&t, radius, ends, (*tip, from_side), angle, depth, taper)? { let faces = cone.face_count(); let cut = kernel::boolean(&nb.body, &cone, BoolOp::Cut)?.ok_or_else(|| DocError::Invalid("the chamfer removed everything".into()))?; let unnamed = crate::lineage::Lineage::unnamed_faces(faces); @@ -769,7 +783,9 @@ pub(super) fn eval(doc: &Document, vals: &BTreeMap, f: &Feature, /// that bound, d3 = d - 1.226869 P (ISO 724, the rounded root of the design profile). It lies /// below the modelled basic root d1, so the cone crosses the root cylinder and leaves a whole /// ring on the end; one ending on the root itself would pinch to nothing wherever the groove -/// reaches the end. ISO 4753 is for ISO metric threads: other forms give `depth`. +/// reaches the end. ISO 4753 is for ISO metric threads: other forms give `depth`. A taper +/// thread's `taper` (its major diameter where it starts, the end it starts from) puts each end's +/// major diameter where the taper has it there, and `depth` is measured from that. fn tip_cones( t: &ThreadInfo, radius: f64, @@ -777,6 +793,7 @@ fn tip_cones( (tip, from): (ThreadTip, usize), angle: Option, depth: Option, + taper: Option<(f64, usize)>, ) -> Result> { if t.internal { return Err(DocError::Invalid("a chamfered tip is for an external thread (ISO 4753); countersink the hole's entry instead".into())); @@ -786,7 +803,12 @@ fn tip_cones( if !(a > 1f64.to_radians() && a < 89f64.to_radians()) { return Err(DocError::Invalid("the chamfer's angle to the axis must be between 1° and 89°".into())); } - let r_top = radius.max(t.major_diameter / 2.0); + // The major diameter at each end of the axis: a taper's grows 1 in 16 from where it starts. + let major = |side: usize| match taper { + Some((d0, start)) if side == start => d0, + Some((d0, _)) => d0 + (t.end - t.start) / 16.0, + None => t.major_diameter, + }; let depth = match (depth, t.form) { (Some(d), _) => d, // ISO 724: d3 = d1 - H/6 = d - 2 (17/24) H. @@ -799,14 +821,14 @@ fn tip_cones( ))); } }; - let r_f = t.major_diameter / 2.0 - depth; - if !(depth > 0.0 && r_f > 1e-3) { - return Err(DocError::Invalid(format!("the chamfer's depth must be between 0 and {} mm", show_mm(t.major_diameter / 2.0)))); + let smallest = major(0).min(major(1)) / 2.0; + if !(depth > 0.0 && smallest - depth > 1e-3) { + return Err(DocError::Invalid(format!("the chamfer's depth must be between 0 and {} mm", show_mm(smallest)))); } let k = *t.axis; let u = k.cross(if k.x.abs() < 0.9 { Vec3::new(1.0, 0.0, 0.0) } else { Vec3::new(0.0, 1.0, 0.0) }); let u = u.normalized().ok_or_else(|| DocError::Invalid("thread axis".into()))?; - let (r_out, slope) = (r_top + 0.1 * t.pitch, a.tan()); + let slope = a.tan(); // Past the end only the radii the groove's overrun already reaches (r >= d_f / 2), so // nothing past a free end beyond the thread is touched. let e = 0.5 * t.pitch; @@ -819,6 +841,8 @@ fn tip_cones( if !free(side) || (tip == ThreadTip::Start && side != from) { continue; } + let r_f = major(side) / 2.0 - depth; + let r_out = radius.max(major(side) / 2.0) + 0.1 * t.pitch; // In the plane: x radial, y outward along the axis from the end. let plane = Plane { origin: t.axis_point + k * at, x: u, y: out_dir }; let pts = [Vec2::new(r_f, 0.0), Vec2::new(r_f, e), Vec2::new(r_out, e), Vec2::new(r_out, -(r_out - r_f) / slope)]; diff --git a/crates/doc/src/format/pending/pipe-threads.rs b/crates/doc/src/format/pending/pipe-threads.rs index b7ad990b4..f8ce7a9aa 100644 --- a/crates/doc/src/format/pending/pipe-threads.rs +++ b/crates/doc/src/format/pending/pipe-threads.rs @@ -1,4 +1,5 @@ -//! A thread's `form` may be `bspp` (ISO 228-1 parallel pipe thread, `G 1/2`), `bspt` (ISO 7-1 +//! A thread's `form` may be `bspp` (ISO 228-1 parallel pipe thread, `G 1/2`), `rp` (ISO 7-1's +//! parallel internal thread, `Rp 1/2`), `bspt` (ISO 7-1 //! taper, `R 1/2` external, `Rc 1/2` internal) or `npt` (ASME B1.20.1 taper, `1/2-14 NPT`). An //! older design has none of them and needs no rewrite. The last release refuses a design saved //! with this (the newer format number). diff --git a/crates/doc/src/format/pending/thread-ends.rs b/crates/doc/src/format/pending/thread-ends.rs index 95da1e6a6..e38d201c0 100644 --- a/crates/doc/src/format/pending/thread-ends.rs +++ b/crates/doc/src/format/pending/thread-ends.rs @@ -1,10 +1,11 @@ -//! A modelled thread saves how its ends are finished: `ease_in` and `ease_out`, the runout at the -//! end it starts from and at the other (`standard` 2.5 P, `short` 1.25 P or `{length}`, ISO -//! 3508), and `tip`, which free ends are chamfered (`start`: the end it starts from, `both`: each -//! free end; ISO 4753), with `chamfer_angle` and `chamfer_depth`. Without them, as in an older -//! design, the groove stops square and no end is chamfered. Designs saved while `tip` read -//! `chamfer` (every free end) are rewritten as they open to `both`. The last release refuses a -//! design saved with this (the newer format number). +//! A modelled thread saves how its ends are finished: `ease_out`, the runout at the inner end, +//! away from where it starts (`standard` 2.5 P, `short` 1.25 P or `{length}`, ISO 3508), and +//! `tip`, which free ends are chamfered (`start`: the end it starts from, `both`: each free end; +//! ISO 4753), with `chamfer_angle` and `chamfer_depth`. Without them, as in an older design, the +//! groove stops square and no end is chamfered. Designs saved while these were being made are +//! rewritten as they open: `tip: chamfer` (every free end) becomes `both`, and an `ease_in` (a +//! runout at the start, which now always runs off its free end) is dropped. The last release +//! refuses a design saved with this (the newer format number). use serde_json::Value; pub fn step(v: &mut Value) -> crate::Result<()> { @@ -19,6 +20,7 @@ pub fn step(v: &mut Value) -> crate::Result<()> { if object.get("tip").and_then(Value::as_str) == Some("chamfer") { object.insert("tip".into(), Value::String("both".into())); } + object.remove("ease_in"); } Ok(()) } @@ -28,14 +30,16 @@ mod tests { use serde_json::json; #[test] - fn a_chamfered_tip_becomes_both_ends() { + fn a_chamfered_tip_becomes_both_ends_and_the_start_runout_goes() { let mut v = json!({"features": [ - {"type": "thread", "designation": "M10", "modeled": true, "tip": "chamfer"}, + {"type": "thread", "designation": "M10", "modeled": true, "tip": "chamfer", "ease_in": "standard", "ease_out": "short"}, {"type": "thread", "designation": "M10", "modeled": true}, {"type": "chamfer", "tip": "chamfer"} ]}); super::step(&mut v).unwrap(); assert_eq!(v["features"][0]["tip"], json!("both")); + assert!(v["features"][0].get("ease_in").is_none()); + assert_eq!(v["features"][0]["ease_out"], json!("short")); assert!(v["features"][1].get("tip").is_none()); assert_eq!(v["features"][2]["tip"], json!("chamfer"), "only threads"); let mut empty = json!({"name": "Untitled"}); diff --git a/crates/doc/src/thread_forms.rs b/crates/doc/src/thread_forms.rs index 35f2462b0..79202608b 100644 --- a/crates/doc/src/thread_forms.rs +++ b/crates/doc/src/thread_forms.rs @@ -28,6 +28,9 @@ pub enum ThreadForm { Square, /// Parallel pipe thread, 55° (ISO 228-1, the Whitworth form with H = 0.960491 P): `G 1/2`. Bspp, + /// Parallel internal pipe thread, 55° (ISO 7-1's Rp, the parallel form with H = 0.960491 P at + /// the gauge diameters): `Rp 1/2`, which a taper external `R` thread screws into. + Rp, /// Taper pipe thread, 55°, taper 1 in 16 (ISO 7-1, H = 0.960237 P): `R 1/2` external, `Rc 1/2` /// internal. Bspt, @@ -239,7 +242,7 @@ impl GrooveProfile { } impl ThreadForm { - pub const ALL: [ThreadForm; 9] = [ + pub const ALL: [ThreadForm; 10] = [ ThreadForm::Metric, ThreadForm::Trapezoidal, ThreadForm::Acme, @@ -247,6 +250,7 @@ impl ThreadForm { ThreadForm::ButtressAsme, ThreadForm::Square, ThreadForm::Bspp, + ThreadForm::Rp, ThreadForm::Bspt, ThreadForm::Npt, ]; @@ -260,6 +264,7 @@ impl ThreadForm { ThreadForm::ButtressAsme => "buttress_asme", ThreadForm::Square => "square", ThreadForm::Bspp => "bspp", + ThreadForm::Rp => "rp", ThreadForm::Bspt => "bspt", ThreadForm::Npt => "npt", } @@ -279,7 +284,7 @@ impl ThreadForm { ThreadForm::ButtressAsme => "ASME B1.9", ThreadForm::Square => "none", ThreadForm::Bspp => "ISO 228-1", - ThreadForm::Bspt => "ISO 7-1", + ThreadForm::Rp | ThreadForm::Bspt => "ISO 7-1", ThreadForm::Npt => "ASME B1.20.1", } } @@ -292,7 +297,7 @@ impl ThreadForm { /// The pipe sizes of a pipe-thread form (ISO 228-1's G sizes are ISO 7-1's gauge diameters). pub fn pipe_sizes(self) -> Vec { match self { - ThreadForm::Bspp | ThreadForm::Bspt => crate::pipe_thread_sizes::iso_7_1().collect(), + ThreadForm::Bspp | ThreadForm::Rp | ThreadForm::Bspt => crate::pipe_thread_sizes::iso_7_1().collect(), ThreadForm::Npt => crate::pipe_thread_sizes::npt().collect(), _ => Vec::new(), } @@ -327,6 +332,8 @@ impl ThreadForm { Some(ThreadForm::Buttress) } else if t.starts_with('M') { Some(ThreadForm::Metric) + } else if t.strip_prefix("RP").is_some_and(then_size) { + Some(ThreadForm::Rp) } else if t.strip_prefix("RC").or_else(|| t.strip_prefix('R')).is_some_and(then_size) { Some(ThreadForm::Bspt) } else if t.strip_prefix('G').is_some_and(then_size) { @@ -345,7 +352,9 @@ impl ThreadForm { ThreadForm::Buttress => ISO_2902_MEDIUM.iter().copied().filter(|(d, _)| *d >= 10.0).collect(), ThreadForm::Acme => ACME_SIZES.iter().map(|(_, d, n)| (d * INCH, INCH / n)).collect(), ThreadForm::ButtressAsme | ThreadForm::Square => Vec::new(), - ThreadForm::Bspp | ThreadForm::Bspt | ThreadForm::Npt => self.pipe_sizes().iter().map(|s| (s.major, s.pitch())).collect(), + ThreadForm::Bspp | ThreadForm::Rp | ThreadForm::Bspt | ThreadForm::Npt => { + self.pipe_sizes().iter().map(|s| (s.major, s.pitch())).collect() + } } } @@ -432,7 +441,7 @@ impl ThreadForm { let p = INCH / tpi; (d * INCH, p, p * n) } - ThreadForm::Square | ThreadForm::Bspp | ThreadForm::Bspt | ThreadForm::Npt => return Err(bad()), + ThreadForm::Square | ThreadForm::Bspp | ThreadForm::Rp | ThreadForm::Bspt | ThreadForm::Npt => return Err(bad()), }; if !(major.is_finite() && pitch.is_finite() && lead.is_finite() && major > 0.0 && pitch > 0.0 && pitch < major) { return Err(bad()); @@ -453,13 +462,14 @@ impl ThreadForm { ThreadForm::ButtressAsme => "like 2.5-8 BUTT", ThreadForm::Square => "no standard", ThreadForm::Bspp => "like G 1/2 (ISO 228-1, 1/16 to 6)", + ThreadForm::Rp => "like Rp 1/2, internal (ISO 7-1, 1/16 to 6)", ThreadForm::Bspt => "like R 1/2 external or Rc 1/2 internal (ISO 7-1, 1/16 to 6)", ThreadForm::Npt => "like 1/2-14 NPT (1/16 to 12)", } } /// The pipe size a pipe-thread designation names: `G 1/2` (a class A or B after it is a - /// tolerance, ignored), `R 1 1/4`, `Rc 1/2`, `1/2-14 NPT` or `1/2 NPT`. + /// tolerance, ignored), `Rp 1/2`, `R 1 1/4`, `Rc 1/2`, `1/2-14 NPT` or `1/2 NPT`. fn pipe_designation(self, s: &str) -> Option { let t = s.trim().to_ascii_uppercase().replace(' ', ""); let same = |n: &str, given: &str| n.replace(' ', "") == given; @@ -469,6 +479,7 @@ impl ThreadForm { let body = t.strip_prefix('G')?; find(body.strip_suffix(['A', 'B']).unwrap_or(body)) } + ThreadForm::Rp => find(t.strip_prefix("RP")?), ThreadForm::Bspt => find(t.strip_prefix("RC").or_else(|| t.strip_prefix('R'))?), ThreadForm::Npt => { let body = t.strip_suffix("NPT")?; @@ -518,9 +529,16 @@ impl ThreadForm { format!("{name}-{tpi} {}", if self == ThreadForm::Acme { "ACME" } else { "BUTT" }) } ThreadForm::Square => format!("{}x{}", show(d), show(p)), - ThreadForm::Bspp | ThreadForm::Bspt | ThreadForm::Npt => match self.pipe_size(d) { + ThreadForm::Bspp | ThreadForm::Rp | ThreadForm::Bspt | ThreadForm::Npt => match self.pipe_size(d) { Some(z) if self == ThreadForm::Npt => format!("{}-{} NPT", z.nominal, show(z.tpi)), - Some(z) => format!("{} {}", if self == ThreadForm::Bspp { "G" } else { "R" }, z.nominal), + Some(z) => { + let pre = match self { + ThreadForm::Bspp => "G", + ThreadForm::Rp => "Rp", + _ => "R", + }; + format!("{pre} {}", z.nominal) + } None => format!("{}x{}", show(d), show(p)), }, } @@ -600,14 +618,14 @@ impl ThreadForm { let flat = (p - 0.6 * p * (deg(7.0).tan() + deg(45.0).tan())) / 2.0; ((deg(7.0), deg(45.0)), flat, 0.6 * p, d / 2.0 - 0.6 * p, d / 2.0 - 0.6 * p, d / 2.0) } - ThreadForm::Bspp | ThreadForm::Bspt | ThreadForm::Npt => { + ThreadForm::Bspp | ThreadForm::Rp | ThreadForm::Bspt | ThreadForm::Npt => { // ISO 228-1 / ISO 7-1: 55°, h = 0.640327 P of the triangle H = 0.960491 P // (parallel) or 0.960237 P (taper), rounded equally at crest and root (r = // 0.137329 P / 0.137278 P), modelled as flats where the rounds would be. ASME // B1.20.1: 60°, h = 0.8 P of H = 0.866025 P, truncated equally at crest and root // (the minimum, 0.033 P). The flanks' bisector is square to the axis. let (half_angle, big_h, h) = match self { - ThreadForm::Bspp => (27.5, 0.960491 * p, 0.640327 * p), + ThreadForm::Bspp | ThreadForm::Rp => (27.5, 0.960491 * p, 0.640327 * p), ThreadForm::Bspt => (27.5, 0.960237 * p, 0.640327 * p), _ => (30.0, 0.866025 * p, crate::pipe_thread_sizes::NPT_HEIGHT * p), }; @@ -661,6 +679,8 @@ mod tests { for (s, form, major, tpi, written) in [ ("G 1/2", ThreadForm::Bspp, 20.955, 14.0, "G 1/2"), ("G1/2A", ThreadForm::Bspp, 20.955, 14.0, "G 1/2"), + ("Rp 1/2", ThreadForm::Rp, 20.955, 14.0, "Rp 1/2"), + ("RP3/4", ThreadForm::Rp, 26.441, 14.0, "Rp 3/4"), ("R 1 1/4", ThreadForm::Bspt, 41.910, 11.0, "R 1 1/4"), ("Rc1/2", ThreadForm::Bspt, 20.955, 14.0, "R 1/2"), ("1/2-14 NPT", ThreadForm::Npt, (0.77843 + 0.8 / 14.0) * INCH, 14.0, "1/2-14 NPT"), @@ -671,7 +691,7 @@ mod tests { assert!((z.major - major).abs() < 1e-9 && (z.pitch - INCH / tpi).abs() < 1e-12, "{s}"); assert_eq!(form.format(z.major, z.pitch, z.lead), written); } - for bad in ["G 7/8", "R 1/2x", "1/2-18 NPT", "Rp 1/2"] { + for bad in ["G 7/8", "R 1/2x", "1/2-18 NPT", "Rp 7/8"] { let parsed = ThreadForm::of_designation(bad).map(|f| f.parse(bad, 1)); assert!(!matches!(parsed, Some(Ok(_))), "{bad}"); } diff --git a/crates/engine/src/cmd/features.rs b/crates/engine/src/cmd/features.rs index b7aba7c39..dff24b342 100644 --- a/crates/engine/src/cmd/features.rs +++ b/crates/engine/src/cmd/features.rs @@ -93,7 +93,7 @@ pub static COMMANDS: &[CommandSpec] = &[ CommandSpec::new("solid.thread", "Thread", thread) .at("SOLID", "CREATE") .icon("thread") - .params("face: [x,y,z] on a cylindrical face; form?: metric|trapezoidal|acme|buttress|buttress_asme|bspp|bspt|npt (default: the one `designation` names, else metric; square is refused: no current standard defines it); designation?: the size, as its standard writes it: metric \"M8\", \"M8x1\", \"M16xPh3P1.5\" (ISO 68-1, ISO 261, ISO 965-1); trapezoidal \"Tr20x4\", \"Tr40x14(P7)\" (ISO 2904, ISO 2903); buttress \"S20x4\", \"S40x14(P7)\" (DIN 513, 3°/30°); acme \"1/2-10 ACME\" (ASME B1.5); buttress_asme \"2.5-8 BUTT\" (ASME B1.9, 7°/45°, basic profile; no size table); bspp \"G 1/2\" (ISO 228-1, 55° parallel); bspt \"R 1/2\" external, \"Rc 1/2\" internal (ISO 7-1, 55°, taper 1 in 16); npt \"1/2-14 NPT\" (ASME B1.20.1, 60°, taper 1 in 16) — a taper thread starts at a free end (the pipe end or the hole mouth) with its standard diameter there, and an external one runs its standard length unless `length` or `up_to` says otherwise (default: the standard size that fits the face, a shaft its major diameter, a hole its drill); hand?: right|left|both (default right; both: a right- and a left-handed groove crossing); steep_flank?: start|end (buttress only, default end: the steep flank of the screw's teeth faces the thread's end, the way its axis points); starts?: 1..8 (lead = starts x pitch: that many grooves, each a turn's starts-th further round; a designation that gives the lead gives the starts); ease_in?, ease_out?: expr|standard|short (modelled threads: the groove fades out over this length, its section moving out of the material as it turns; standard 2.5 P, short 1.25 P per ISO 3508; ease_in at the end the thread starts from (`from`, or the start of its extent), ease_out at the other; it lies past the full-form length, up to a shoulder's clearance; at a free end, inside the face); tip?: none|start|both (modelled external threads: start chamfers the end the thread starts from, which must be free, both each free end the thread reaches, after the groove is cut, ISO 4753's chamfered end, the last teeth tapering into the cone; chamfer_angle?: angle expr to the axis, default 45 deg; chamfer_depth?: expr, radial from the major diameter, default for a metric thread down to the external minor diameter d3 = d - 1.226869 P (ISO 724), the largest ISO 4753 allows; other forms give it); extent?: full|length|up_to (default: length when `length` is given, up_to when `up_to` is, else full: the whole face); length?: expr (from the end the thread starts at); up_to?: [x,y,z] (a point, such as on a shoulder face: the thread runs to its place along the axis) | plane name or {origin, normal} (to where the plane crosses the axis); from?: [x,y,z] near the end of the face the thread starts at (default: the face's only free end, the one with no material past it; else the end the `face` point lies within a third of the face of; a pick in the middle of a face whose ends are alike is refused); modeled?: bool (default false). Cosmetic: the model is unchanged, model.threads lists it. Modeled: cuts the thread profile into the body: past a free end the groove runs out a pitch into the air (or through a chamfer); at a shoulder, a head or a blind hole's bottom it stops with its section clear of it, never cutting into it; a shaft thicker than the thread is refused with the size to make it, never turned down"), + .params("face: [x,y,z] on a cylindrical face; form?: metric|trapezoidal|acme|buttress|buttress_asme|bspp|rp|bspt|npt (default: the one `designation` names, else metric; square is refused: no current standard defines it); designation?: the size, as its standard writes it: metric \"M8\", \"M8x1\", \"M16xPh3P1.5\" (ISO 68-1, ISO 261, ISO 965-1); trapezoidal \"Tr20x4\", \"Tr40x14(P7)\" (ISO 2904, ISO 2903); buttress \"S20x4\", \"S40x14(P7)\" (DIN 513, 3°/30°); acme \"1/2-10 ACME\" (ASME B1.5); buttress_asme \"2.5-8 BUTT\" (ASME B1.9, 7°/45°, basic profile; no size table); bspp \"G 1/2\" (ISO 228-1, 55° parallel); rp \"Rp 1/2\" (ISO 7-1's parallel internal thread, 55°, an R screws into it; internal only); bspt \"R 1/2\" external, \"Rc 1/2\" internal (ISO 7-1, 55°, taper 1 in 16); npt \"1/2-14 NPT\" (ASME B1.20.1, 60°, taper 1 in 16) — a taper thread starts at a free end (the pipe end or the hole mouth) with its standard diameter there, and an external one runs its standard length unless `length` or `up_to` says otherwise (default: the standard size that fits the face, a shaft its major diameter, a hole its drill); hand?: right|left|both (default right; both: a right- and a left-handed groove crossing); steep_flank?: start|end (buttress only, default end: the steep flank of the screw's teeth faces the thread's end, the way its axis points); starts?: 1..8 (lead = starts x pitch: that many grooves, each a turn's starts-th further round; a designation that gives the lead gives the starts); ease_out?: expr|standard|short (modelled threads: the inner end, away from where the thread starts, fades out over this length (shorter than a turn too), its section moving out of the material as it turns; standard 2.5 P, short 1.25 P per ISO 3508; it lies past the full-form length, up to a shoulder's clearance; at a free end, inside the face; without it the groove stops square there, ending in its own profile; the start never fades: it runs off its free end, plain or chamfered (`tip`)); tip?: none|start|both (modelled external threads: start chamfers the end the thread starts from, which must be free, both each free end the thread reaches, after the groove is cut, ISO 4753's chamfered end, the last teeth tapering into the cone; chamfer_angle?: angle expr to the axis, default 45 deg; chamfer_depth?: expr, radial from the major diameter, default for a metric thread down to the external minor diameter d3 = d - 1.226869 P (ISO 724), the largest ISO 4753 allows; other forms give it); extent?: full|length|up_to (default: length when `length` is given, up_to when `up_to` is, else full: the whole face); length?: expr (from the end the thread starts at); up_to?: [x,y,z] (a point, such as on a shoulder face: the thread runs to its place along the axis) | plane name or {origin, normal} (to where the plane crosses the axis); from?: [x,y,z] near the end of the face the thread starts at (default: the face's only free end, the one with no material past it; else the end the `face` point lies within a third of the face of; a pick in the middle of a face whose ends are alike is refused); modeled?: bool (default false). Cosmetic: the model is unchanged, model.threads lists it. Modeled: cuts the thread profile into the body: past a free end the groove runs out a pitch into the air (or through a chamfer); at a shoulder, a head or a blind hole's bottom it stops with its section clear of it, never cutting into it; a shaft thicker than the thread is refused with the size to make it, never turned down"), CommandSpec::new("solid.shell", "Shell", shell) .at("SOLID", "MODIFY") .icon("shell") @@ -2917,7 +2917,7 @@ fn thread(s: &mut Session, p: &Value) -> Result { let designation = str_(p, "designation").map(|t| t.trim().to_string()).filter(|t| !t.is_empty()); let form = match str_(p, "form") { Some(f) => ThreadForm::from_name(f).ok_or_else(|| { - bad(cmd, format!("unknown thread form `{f}` (metric, trapezoidal, acme, buttress, buttress_asme, bspp, bspt, npt or square)")) + bad(cmd, format!("unknown thread form `{f}` (metric, trapezoidal, acme, buttress, buttress_asme, bspp, rp, bspt, npt or square)")) })?, None => designation.as_deref().and_then(ThreadForm::of_designation).unwrap_or_default(), }; @@ -2977,7 +2977,13 @@ fn thread(s: &mut Session, p: &Value) -> Result { } }) }; - let (ease_in, ease_out) = (ease("ease_in")?, ease("ease_out")?); + if p.get("ease_in").is_some() { + return Err(bad( + cmd, + "`ease_in` is gone: a thread's start runs off its free end, plain or chamfered (`tip: start`); fade the inner end with `ease_out`", + )); + } + let ease_out = ease("ease_out")?; let length = expr(p, "length"); if let Some(l) = &length { check_expr(s, l, Kind::Length, cmd, "length")?; @@ -3019,7 +3025,6 @@ fn thread(s: &mut Session, p: &Value) -> Result { form, hand, starts, - ease_in, ease_out, tip, chamfer_angle, diff --git a/crates/engine/src/thread_tests.rs b/crates/engine/src/thread_tests.rs index 3b9d1f65c..93dc0eb37 100644 --- a/crates/engine/src/thread_tests.rs +++ b/crates/engine/src/thread_tests.rs @@ -521,43 +521,57 @@ fn a_thread_stops_clear_of_a_shoulder() { assert!((got - want).abs() < want * 2e-4, "{got} vs {want}"); } -/// A d10 boss (z 6..22) joined onto a 40x40x6 plate, threaded M10: the plate's top is the -/// shoulder. The groove, with or without its runout, stays on the boss: the plate keeps all of -/// its 40 40 6 (what lies below z = 6 after the boss is cut away), and without a runout the -/// boss loses (16 - w)/P turns, as at a collar. +/// A d10 boss (z t..t+16) on a plate t thick, threaded M10: the plate's top is the shoulder. +/// The groove, with or without its runout, stays on the boss: the plate keeps all of itself +/// (what lies below z = t after the boss is cut away), and without a runout the boss loses +/// (16 - w)/P turns, as at a collar. The owner's bug: built as the app builds it (a rounded +/// plate, a circle sketched on its top face and extruded with Join), a plate thinner than 1.5 P +/// had no material where the free-end test looked (1 to 1.5 pitches past the face), so its top +/// was taken for a free end and the overrun cut a pitch into it. #[test] fn a_thread_on_a_boss_never_cuts_into_the_plate_below() { - let boss = |extra: Value| { + let boss = |t: f64, extra: Value| { let mut s = Session::default(); - run(&mut s, "solid.box", json!({"corner": [-20, -20, 0], "length": 40, "width": 40, "height": 6, "body_name": "Part"})); - run(&mut s, "solid.cylinder", json!({"base": [0, 0, 6], "radius": 5, "height": 16, "operation": "join", "targets": ["Part"]})); - let mut p = json!({"face": [5, 0, 14], "designation": "M10", "modeled": true}); + run(&mut s, "sketch.create", json!({"plane": "XY"})); + run(&mut s, "sketch.rectangle.rounded", json!({"p0": [-20, -20], "p1": [20, 20], "radius": 5})); + run(&mut s, "sketch.finish", json!({})); + run(&mut s, "solid.extrude", json!({"distance": t})); + run(&mut s, "sketch.create", json!({"plane": {"face": [0, 0, t]}})); + run(&mut s, "sketch.circle.center", json!({"center": [0, 0], "radius": 5})); + run(&mut s, "sketch.finish", json!({})); + run(&mut s, "solid.extrude", json!({"distance": 16, "operation": "join"})); + assert_eq!(s.model.state().bodies.len(), 1); + let mut p = json!({"face": [5, 0, t + 8.0], "modeled": true}); if let (Some(p), Value::Object(e)) = (p.as_object_mut(), extra) { p.extend(e); } run(&mut s, "solid.thread", p); s }; - let plate_left = |mut s: Session| { + let plate_left = |mut s: Session, t: f64| { run( &mut s, "solid.box", - json!({"corner": [-30, -30, 6], "length": 60, "width": 60, "height": 30, "body_name": "Above", "operation": "new_body"}), + json!({"corner": [-30, -30, t], "length": 60, "width": 60, "height": 30, "body_name": "Above", "operation": "new_body"}), ); - run(&mut s, "solid.combine", json!({"target": "Part", "tools": ["Above"], "operation": "cut"})); - exact_volume(&s, "Part") + run(&mut s, "solid.combine", json!({"target": "Body1", "tools": ["Above"], "operation": "cut"})); + exact_volume(&s, "Body1") }; - let s = boss(json!({})); + let plate = |t: f64| (40.0 * 40.0 - (4.0 - PI) * 25.0) * t; let (p, w) = (1.5, ext_half_width(10.0, 1.5)); - let want = 40.0 * 40.0 * 6.0 + PI * 25.0 * 16.0 - (16.0 - w) / p * ext_turn(10.0, p, 5.0); - let got = exact_volume(&s, "Part"); - assert!((got - want).abs() < want * 2e-4, "{got} vs {want}"); - assert!((plate_left(s) - 9600.0).abs() < 1e-6); + for t in [6.0, 1.0] { + let s = boss(t, json!({})); + let want = plate(t) + PI * 25.0 * 16.0 - (16.0 - w) / p * ext_turn(10.0, p, 5.0); + let got = exact_volume(&s, "Body1"); + assert!((got - want).abs() < want * 2e-4, "plate {t}: {got} vs {want}"); + let left = plate_left(s, t); + assert!((left - plate(t)).abs() < 1e-6 * plate(t), "plate {t}: lost {} mm³", plate(t) - left); + } for extra in [json!({"ease_out": "standard"}), json!({"ease_out": "short", "tip": "both"})] { - let s = boss(extra.clone()); - assert!(s.model.state().body("Part").unwrap().body.validity().is_empty(), "{extra}"); - let left = plate_left(s); - assert!((left - 9600.0).abs() < 1e-6, "{extra}: the plate below the boss lost {} mm³", 9600.0 - left); + let s = boss(1.0, extra.clone()); + assert!(s.model.state().body("Body1").unwrap().body.validity().is_empty(), "{extra}"); + let left = plate_left(s, 1.0); + assert!((left - plate(1.0)).abs() < 1e-6 * plate(1.0), "{extra}: the plate below the boss lost {} mm³", plate(1.0) - left); } } @@ -971,39 +985,39 @@ fn m10_runout_mean(h: f64) -> f64 { simpson / h } -/// ISO 3508 runouts on a shaft between two collars: the groove fades out over 2.5 P (standard) at -/// the end it starts from and 1.25 P (short) at the other, its section moving out past the surface -/// as it turns, each reaching nothing where its section clears the collar. The cut is the -/// integral over the turn of the clipped section's 2π∫ r dA (Pappus with the section moving): -/// full turns at f(0), the runouts at the mean of f over the offsets they pass. +/// ISO 3508 runouts on a shaft between two collars: the thread starts at the lower collar and +/// its inner end fades out over 1.25 P (short) or 2.5 P (standard) before the upper one, its +/// section moving out past the surface as it turns, reaching nothing where its section clears the +/// collar. The cut is the integral over the turn of the clipped section's 2π∫ r dA (Pappus with +/// the section moving): full turns at f(0), the runout at the mean of f over the offsets it +/// passes. A fade shorter than a turn is cut too; the start never fades (`ease_in` is refused). #[test] -fn a_runout_fades_the_groove_out_before_each_shoulder() { - let mut s = shaft_on_collar(); - run(&mut s, "solid.cylinder", json!({"base": [0, 0, 35], "radius": 8, "height": 10, "operation": "join", "targets": ["Part"]})); - let before = exact_volume(&s, "Part"); - run( - &mut s, - "solid.thread", - json!({"face": [5, 0, 20], "designation": "M10", "ease_in": "standard", "ease_out": "short", "from": [0, 0, 10], "modeled": true}), - ); - let st = s.model.state(); - assert!(st.body("Part").unwrap().body.validity().is_empty()); +fn a_runout_fades_the_groove_out_before_the_shoulder() { let (p, w) = (1.5, ext_half_width(10.0, 1.5)); let root = 5.0 - 5.0 * p * 3f64.sqrt() / 16.0; let h = 5.0 - root + 0.05 * p; let turns = (35.0 - 10.0 - 2.0 * w) / p; - let (r_in, r_out) = (2.5, 1.25); - let want = 2.0 * PI * (m10_cut_per_radian(0.0) * (turns - r_in - r_out) + (r_in + r_out) * m10_runout_mean(h)); - let got = before - exact_volume(&s, "Part"); - // Where the section moves, the sweep's walls lie within its tolerance (1e-4 P) of the true - // surfaces, not on them: up to that times the runouts' walls (about 64 mm² a turn, 3.75 turns), - // 0.036 mm³. Full-depth turns are exact radially (6e-4 mm³ here). - let bound = 1e-4 * p * 64.0 * (r_in + r_out); - assert!((got - want).abs() < bound, "{got} vs {want}"); - // Longer runouts than the thread are refused. + for (ease, r_out) in [(json!("short"), 1.25), (json!("standard"), 2.5), (json!("1 mm"), 1.0 / 1.5)] { + let mut s = shaft_on_collar(); + run(&mut s, "solid.cylinder", json!({"base": [0, 0, 35], "radius": 8, "height": 10, "operation": "join", "targets": ["Part"]})); + let before = exact_volume(&s, "Part"); + run(&mut s, "solid.thread", json!({"face": [5, 0, 20], "designation": "M10", "ease_out": ease, "from": [0, 0, 10], "modeled": true})); + assert!(s.model.state().body("Part").unwrap().body.validity().is_empty(), "{ease}"); + let want = 2.0 * PI * (m10_cut_per_radian(0.0) * (turns - r_out) + r_out * m10_runout_mean(h)); + let got = before - exact_volume(&s, "Part"); + // Where the section moves, the sweep's walls lie within its tolerance (1e-4 P) of the + // true surfaces, not on them: up to that times the walls (about 64 mm² a turn) of the + // runout and of a turn more. Measured: 0.018 (short), 0.012 (standard), 0.011 mm³ (1 + // mm), not growing with the runout's length; full-depth turns are exact radially. + let bound = 1e-4 * p * 64.0 * (r_out + 1.0); + assert!((got - want).abs() < bound, "{ease}: {got} vs {want}"); + } + // Longer runouts than the thread are refused, and so is a runout at the start. let mut s = shaft_on_collar(); - let e = s.execute("solid.thread", &json!({"face": [5, 0, 20], "designation": "M10", "ease_in": 14, "ease_out": 14, "modeled": true})); + let e = s.execute("solid.thread", &json!({"face": [5, 0, 20], "designation": "M10", "ease_out": 30, "modeled": true})); assert!(e.err().map(|e| e.to_string()).unwrap_or_default().contains("longer than the thread")); + let e = s.execute("solid.thread", &json!({"face": [5, 0, 20], "designation": "M10", "ease_in": "standard", "modeled": true})); + assert!(e.err().map(|e| e.to_string()).unwrap_or_default().contains("`ease_in` is gone")); } /// A modelled M10 thread's flanks are several B-spline faces per turn (spans of one sweep); where @@ -1055,7 +1069,7 @@ fn a_modelled_threads_flank_joins_are_not_drawn() { /// 0.960237 P (taper), ASME B1.20.1 60° h 0.8 P of H 0.866025 P. fn pipe_profile(form: &str) -> (f64, f64, f64) { let (a, big_h, h) = match form { - "bspp" => (27.5f64, 0.960491, 0.640327), + "bspp" | "rp" => (27.5f64, 0.960491, 0.640327), "bspt" => (27.5, 0.960237, 0.640327), _ => (30.0, 0.866025, 0.8), }; @@ -1108,11 +1122,14 @@ fn pipe_threads_cut_their_standard_profiles_and_tapers() { // (designation, form, internal, stock radius, crest radius at z for a 12 mm stock threaded from z = 12) let r_half: f64 = 20.955 / 2.0 - 8.2 / 32.0; let npt_half: f64 = ((0.75843 + 0.32 / 16.0) + 0.8 / 14.0) * inch / 2.0 - 0.32 * inch / 32.0; - let cases: [(&str, &str, bool, f64, Box f64>); 4] = [ + // ISO 7-1's Rp, parallel and internal, in a hole drilled to its minor diameter. + let rp_minor = 20.955 / 2.0 - 0.640327 * inch / 14.0; + let cases: [(&str, &str, bool, f64, Box f64>); 5] = [ ("R 1/2", "bspt", false, 10.65, Box::new(move |z| r_half + (12.0 - z) / 32.0)), ("1/2-14 NPT", "npt", false, 0.42 * inch, Box::new(move |z| npt_half + (12.0 - z) / 32.0)), ("G 1/2", "bspp", false, 20.955 / 2.0, Box::new(|_| 20.955 / 2.0)), ("Rc 1/2", "bspt", true, 9.2, Box::new(|z| 20.955 / 2.0 - (12.0 - z) / 32.0)), + ("Rp 1/2", "rp", true, rp_minor + 1e-4, Box::new(|_| 20.955 / 2.0)), ]; for (designation, form, internal, rs, crest) in cases { let stock = || { @@ -1145,19 +1162,23 @@ fn pipe_threads_cut_their_standard_profiles_and_tapers() { // A parallel thread's meridians are alike exactly. A taper's section moves off the axis // as it turns, so the meridians differ; the averaged profile met the cut within 0.12 % of // the removed volume here (R 1/2 0.06 %, NPT 0.12 %). - let tol = if form == "bspp" { 1e-5 } else { 2e-3 }; + let tol = if matches!(form, "bspp" | "rp") { 1e-5 } else { 2e-3 }; assert!((got - want).abs() < (stock - want).abs() * tol, "{designation}: {got} vs {want} (stock {stock})"); } } /// A taper pipe thread's rules: it starts at a free end (not at a shoulder), ISO 7-1 names the -/// internal taper Rc and the external R, a pipe thread has one start and turns one way, and a -/// chamfered tip is not cut on it yet. +/// internal taper Rc and the external R (and Rp is internal only), a pipe thread has one start and +/// turns one way, and its chamfered tip is cut from the small end's major diameter. #[test] fn a_taper_pipe_thread_starts_at_a_free_end_and_is_named_for_its_side() { - let mut s = Session::default(); - run(&mut s, "solid.cylinder", json!({"radius": 16, "height": 10, "body_name": "Part"})); - run(&mut s, "solid.cylinder", json!({"base": [0, 0, 10], "radius": 10.65, "height": 25, "operation": "join", "targets": ["Part"]})); + let part = || { + let mut s = Session::default(); + run(&mut s, "solid.cylinder", json!({"radius": 16, "height": 10, "body_name": "Part"})); + run(&mut s, "solid.cylinder", json!({"base": [0, 0, 10], "radius": 10.65, "height": 25, "operation": "join", "targets": ["Part"]})); + s + }; + let mut s = part(); let err = |s: &mut Session, p: Value| s.execute("solid.thread", &p).err().map(|e| e.to_string()).unwrap_or_default(); let e = err(&mut s, json!({"face": [10.65, 0, 20], "designation": "R 1/2", "modeled": true, "from": [10.65, 0, 10]})); assert!(e.contains("starts at a free end"), "{e}"); @@ -1167,12 +1188,27 @@ fn a_taper_pipe_thread_starts_at_a_free_end_and_is_named_for_its_side() { assert!(e.contains("one start"), "{e}"); let e = err(&mut s, json!({"face": [10.65, 0, 20], "designation": "R 1/2", "hand": "both", "modeled": true, "from": [10.65, 0, 35]})); assert!(e.contains("turns one way"), "{e}"); - let e = err(&mut s, json!({"face": [10.65, 0, 20], "designation": "R 1/2", "tip": "both", "modeled": true, "from": [10.65, 0, 35]})); - assert!(e.contains("taper pipe thread"), "{e}"); + let e = err(&mut s, json!({"face": [10.65, 0, 20], "designation": "Rp 1/2", "modeled": true, "from": [10.65, 0, 35]})); + assert!(e.contains("Rp is an internal thread"), "{e}"); + // ISO 4753's chamfered end is metric: a pipe thread gives its depth. + let e = err(&mut s, json!({"face": [10.65, 0, 20], "designation": "R 1/2", "tip": "start", "modeled": true, "from": [10.65, 0, 35]})); + assert!(e.contains("chamfer depth"), "{e}"); // From the free end it runs ISO 7-1's useful thread, 13.2 mm for R 1/2. let out = run(&mut s, "solid.thread", json!({"face": [10.65, 0, 20], "designation": "R 1/2", "from": [10.65, 0, 35]})); let t = &out["thread"]; assert!((t["end"].as_f64().unwrap() - t["start"].as_f64().unwrap() - 13.2).abs() < 1e-9, "{t}"); - run(&mut s, "solid.thread", json!({"face": [10.65, 0, 20], "designation": "R 1/2", "modeled": true, "from": [10.65, 0, 35]})); + let mut plain = part(); + run(&mut plain, "solid.thread", json!({"face": [10.65, 0, 20], "designation": "R 1/2", "modeled": true, "from": [10.65, 0, 35]})); + assert!(plain.model.state().body("Part").unwrap().body.validity().is_empty()); + // The chamfered tip of a taper thread: the cone reaches the small end's major diameter less + // the depth, and cuts the first teeth. + let p = 25.4 / 14.0; + run( + &mut s, + "solid.thread", + json!({"face": [10.65, 0, 20], "designation": "R 1/2", "modeled": true, "from": [10.65, 0, 35], "tip": "start", "chamfer_depth": 0.640327 * p}), + ); assert!(s.model.state().body("Part").unwrap().body.validity().is_empty()); + let (chamfered, threaded) = (exact_volume(&s, "Part"), exact_volume(&plain, "Part")); + assert!(chamfered < threaded - 1e-3, "the tip cuts the first teeth: {chamfered} vs {threaded}"); } diff --git a/crates/ui-egui/src/dialogs_all_tests.rs b/crates/ui-egui/src/dialogs_all_tests.rs index 7f2716c1b..107dd2c98 100644 --- a/crates/ui-egui/src/dialogs_all_tests.rs +++ b/crates/ui-egui/src/dialogs_all_tests.rs @@ -234,7 +234,7 @@ fn control_role(command: &str, label: &str) -> Option { | "Bend Line Position" | "From Snap" | "To Snap" | "Joint" | "Joint 1" | "Joint 2" | "Gear 1" | "Gear 2" | "Pinion" | "Rack" | "Screw" | "Nut" | "Cam" | "Follower" | "Anchor" => Role::ComboBox, "Radius" if command == "joint.rack_pinion" => Role::Label, - "Pitch" | "Form" | "Hand" | "Starts" | "Extent" | "Ease In" | "Ease Out" | "Tip" if command == "solid.thread" => Role::ComboBox, + "Pitch" | "Form" | "Hand" | "Starts" | "Extent" | "Start" | "End" if command == "solid.thread" => Role::ComboBox, "Automatic size" | "Reverse" | "Other side" | "All Lines" | "Mirror" => Role::CheckBox, "Animate" => Role::Button, "Ratio" if command.starts_with("joint.") && command != "joint.motion_link" => return None, @@ -362,7 +362,7 @@ form_case!(path_pattern, "solid.pattern.path", ["Type", "Object Type", "Quantity form_case!(pipe, "solid.pipe", ["Diameter", "Wall", "Operation"]); form_case!(stock, "solid.bounding_solid", ["Margin"]); form_case!(frame_member, "frame.member", ["All Lines", "Anchor", "Angle", "Mirror", "Name"]); -form_case!(thread, "solid.thread", ["Form", "Size", "Pitch", "Designation", "Hand", "Starts", "Extent", "Ease In", "Ease Out", "Tip"]); +form_case!(thread, "solid.thread", ["Form", "Size", "Pitch", "Designation", "Hand", "Starts", "Extent", "Start", "End"]); form_case!(primitive_box, "solid.box", ["length", "width", "height", "Operation"]); form_case!(cylinder, "solid.cylinder", ["diameter", "height", "Operation"]); form_case!(sphere, "solid.sphere", ["diameter", "Operation"]); diff --git a/crates/ui-egui/src/dialogs_thread.rs b/crates/ui-egui/src/dialogs_thread.rs index 207f5e7a8..fb3239126 100644 --- a/crates/ui-egui/src/dialogs_thread.rs +++ b/crates/ui-egui/src/dialogs_thread.rs @@ -164,20 +164,24 @@ const FORMS: &[(&str, ThreadForm)] = &[ ("Acme (ASME B1.5)", ThreadForm::Acme), ("Buttress (DIN 513)", ThreadForm::Buttress), ("Buttress (ASME B1.9)", ThreadForm::ButtressAsme), + ("thread.form_bspp", ThreadForm::Bspp), + ("thread.form_rp", ThreadForm::Rp), + ("thread.form_bspt", ThreadForm::Bspt), + ("thread.form_npt", ThreadForm::Npt), ]; const HANDS: &[(&str, ThreadHand)] = &[("Right", ThreadHand::Right), ("Left", ThreadHand::Left), ("Both", ThreadHand::Both)]; -/// A tapped hole's hands: one groove, so never both. +/// A tapped hole's and a pipe thread's hands: one groove, so never both. const HOLE_HANDS: &[(&str, ThreadHand)] = &[("Right", ThreadHand::Right), ("Left", ThreadHand::Left)]; const STARTS: &[(&str, u32)] = &[("1", 1), ("2", 2), ("3", 3), ("4", 4), ("5", 5), ("6", 6), ("7", 7), ("8", 8)]; const FULL: usize = 0; const LENGTH: usize = 1; const UP_TO_EXTENT: usize = 2; const EXTENTS: &[(&str, &str)] = &[("Full", "full"), ("Length", "length"), ("Up to", "up_to")]; -/// Runout choices (ISO 3508); the last one is a typed length. -const EASES: &[(&str, &str)] = &[("None", ""), ("Standard (2.5 P)", "standard"), ("Short (1.25 P)", "short"), ("Length", "")]; -const EASE_LENGTH: usize = 3; -/// Which free ends are chamfered (ISO 4753). -const TIPS: &[(&str, ThreadTip)] = &[("None", ThreadTip::None), ("Start", ThreadTip::Start), ("Both", ThreadTip::Both)]; +/// The thread's start, its free end: run off it plain, or chamfered (ISO 4753). +const STARTS_AT: &[&str] = &["None", "Chamfer"]; +/// The thread's inner end: a square stop (the groove ends in its own profile) or a fade +/// (ISO 3508's runout). +const ENDS_AT: &[&str] = &["thread.end_square", "ui.fade"]; const FLANKS: &[(&str, SteepFlank)] = &[("End", SteepFlank::End), ("Start", SteepFlank::Start)]; /// The pick of the end the thread is measured from (`from`). @@ -191,22 +195,34 @@ pub(crate) fn inputs() -> Vec { vec![SelInput::new("Cylindrical face", FACES, false)] } -/// A runout at one end: a choice from the runout list and the typed length. +/// The inner end: square or a fade, the fade's typed length (empty: ISO 3508's runout, the +/// standard 2.5 P unless the thread was saved with the short 1.25 P). #[derive(Clone, Debug, Default, PartialEq)] pub struct Ease { - pub choice: usize, + pub fade: bool, pub length: String, + pub short: bool, } impl Ease { fn of(r: &Option) -> Ease { match r { None => Ease::default(), - Some(ThreadRunout::Standard) => Ease { choice: 1, length: String::new() }, - Some(ThreadRunout::Short) => Ease { choice: 2, length: String::new() }, - Some(ThreadRunout::Length { length }) => Ease { choice: EASE_LENGTH, length: expr(length) }, + Some(ThreadRunout::Standard) => Ease { fade: true, ..Ease::default() }, + Some(ThreadRunout::Short) => Ease { fade: true, short: true, ..Ease::default() }, + Some(ThreadRunout::Length { length }) => Ease { fade: true, length: expr(length), short: false }, } } + + /// The command's `ease_out`, none for a square end. + fn param(&self) -> Option { + let typed = self.length.trim(); + self.fade.then(|| match (typed.is_empty(), self.short) { + (false, _) => json!(typed), + (true, true) => json!("short"), + (true, false) => json!("standard"), + }) + } } fn expr(e: &Expr) -> String { @@ -221,7 +237,6 @@ pub struct Options { pub starts: u32, /// An index into the extents (full, length, up to). pub extent: usize, - pub ease_in: Ease, pub ease_out: Ease, pub tip: ThreadTip, pub chamfer_angle: String, @@ -236,7 +251,6 @@ impl Default for Options { hand: ThreadHand::default(), starts: 1, extent: FULL, - ease_in: Ease::default(), ease_out: Ease::default(), tip: ThreadTip::default(), chamfer_angle: String::new(), @@ -250,7 +264,7 @@ impl Options { /// Does the thread start at one end of the face (a length or an Up To extent, a runout or a /// tip)? Then the end to start from can be picked. pub fn starts_at_an_end(&self) -> bool { - self.extent != FULL || self.ease_in.choice != 0 || self.ease_out.choice != 0 || self.tip != ThreadTip::None + self.extent != FULL || self.ease_out.fade || self.tip != ThreadTip::None } } @@ -258,9 +272,15 @@ fn is_buttress(form: ThreadForm) -> bool { matches!(form, ThreadForm::Buttress | ThreadForm::ButtressAsme) } -/// Sizes in inches are listed by designation, and their pitch is part of it (threads per inch). +/// Sizes in inches are listed by designation, and their pitch is part of it (threads per inch): +/// the inch forms and the pipe threads, whose nominal sizes are pipe sizes. fn inch(form: ThreadForm) -> bool { - matches!(form, ThreadForm::Acme | ThreadForm::ButtressAsme) + matches!(form, ThreadForm::Acme | ThreadForm::ButtressAsme) || is_pipe(form) +} + +/// A pipe thread: one start, turning one way. +fn is_pipe(form: ThreadForm) -> bool { + !form.pipe_sizes().is_empty() } fn same(a: f64, b: f64) -> bool { @@ -385,8 +405,17 @@ pub(crate) fn rows( *suggested = None; } - pick(ui, "Hand", "thread_hand", &mut o.hand, HANDS); - pick(ui, "Starts", "thread_starts", &mut o.starts, STARTS); + if is_pipe(f) { + // A pipe thread has one start and turns one way. + o.starts = 1; + if o.hand == ThreadHand::Both { + o.hand = ThreadHand::Right; + } + pick(ui, "Hand", "thread_hand", &mut o.hand, HOLE_HANDS); + } else { + pick(ui, "Hand", "thread_hand", &mut o.hand, HANDS); + pick(ui, "Starts", "thread_starts", &mut o.starts, STARTS); + } if is_buttress(f) { pick(ui, "Steep Flank", "thread_flank", &mut o.steep_flank, FLANKS); } @@ -402,36 +431,45 @@ pub(crate) fn rows( } crate::ui_kit::section(ui, "thread_ends", "Ends", true, |ui| { - enter |= ease_rows(ui, "Ease In", "thread_ease_in", &mut o.ease_in); - enter |= ease_rows(ui, "Ease Out", "thread_ease_out", &mut o.ease_out); - pick(ui, "Tip", "thread_tip", &mut o.tip, TIPS); + // The start, a free end: plain or chamfered. A thread saved chamfered at both ends + // keeps that. + let mut chamfered = usize::from(o.tip != ThreadTip::None); + choice_row(ui, "Start", "thread_start", &mut chamfered, STARTS_AT); + o.tip = match (chamfered, o.tip) { + (0, _) => ThreadTip::None, + (_, ThreadTip::None) => ThreadTip::Start, + (_, kept) => kept, + }; if o.tip != ThreadTip::None { enter |= hint_row(ui, "Chamfer Angle", &mut o.chamfer_angle, tr("ui.iso_4753")); - enter |= hint_row(ui, "Chamfer Depth", &mut o.chamfer_depth, tr("ui.iso_4753")); + // ISO 4753's depth is for ISO metric threads; the other forms give theirs. + let depth = if f == ThreadForm::Metric { "ui.iso_4753" } else { "thread.chamfer_depth_needed" }; + enter |= hint_row(ui, "Chamfer Depth", &mut o.chamfer_depth, tr(depth)); + } + // The inner end: square, or a fade over its length. + let mut fade = usize::from(o.ease_out.fade); + choice_row(ui, "End", "thread_end", &mut fade, ENDS_AT); + o.ease_out.fade = fade == 1; + if o.ease_out.fade { + let hint = if o.ease_out.short { tr("thread.fade_short") } else { tr("thread.fade_standard") }; + enter |= hint_row(ui, "Fade Length", &mut o.ease_out.length, hint); } }); (enter, reset) } -/// A runout choice, with its length when typed. -fn ease_rows(ui: &mut egui::Ui, label: &'static str, id: &str, e: &mut Ease) -> bool { - let labels: Vec<&str> = EASES.iter().map(|x| x.0).collect(); - let before = e.choice; - choice_row(ui, label, id, &mut e.choice, &labels); - if e.choice != EASE_LENGTH { - return false; - } - if before != EASE_LENGTH && e.length.trim().is_empty() { - e.length = "1 mm".into(); - } - expr_row(ui, if label == "Ease In" { "Ease In Length" } else { "Ease Out Length" }, &mut e.length) -} - /// The Size choice of a form with a size table, and the Pitch choice of the metric ones (an /// inch designation names its threads per inch). fn size_rows(ui: &mut egui::Ui, f: ThreadForm, designation: &mut String, suggested: &mut Option) { let table = f.sizes(); let current = parse(f, designation); + // ISO 7-1 writes the internal taper thread Rc: a size picked for a hole the dialog sized Rc + // stays Rc. + let internal = f == ThreadForm::Bspt && ThreadForm::pipe_internal(designation); + let designation_of = |f: ThreadForm, d: f64, p: f64| { + let name = designation_of(f, d, p); + if internal { name.replacen("R ", "Rc ", 1) } else { name } + }; let mut diameters: Vec = table.iter().map(|(d, _)| *d).collect(); if let Some((d, _)) = current && !diameters.iter().any(|n| same(*n, d)) @@ -525,12 +563,8 @@ pub(crate) fn put_params(p: &mut Value, length: &str, o: &Options, inputs: &[Sel if let Some(from) = object_point(inputs, START_END) { p["from"] = from; } - for (key, e) in [("ease_in", &o.ease_in), ("ease_out", &o.ease_out)] { - match e.choice { - EASE_LENGTH => put(p, &[(key, e.length.as_str())]), - 0 => {} - c => p[key] = json!(EASES[c].1), - } + if let Some(e) = o.ease_out.param() { + p["ease_out"] = e; } if o.tip != ThreadTip::None { p["tip"] = json!(o.tip); @@ -569,7 +603,6 @@ pub(crate) fn reopen(d: &mut Dialog, s: &Session, kind: &FeatureKind) { form, hand, starts, - ease_in, ease_out, tip, chamfer_angle, @@ -593,7 +626,6 @@ pub(crate) fn reopen(d: &mut Dialog, s: &Session, kind: &FeatureKind) { } else { FULL }, - ease_in: Ease::of(ease_in), ease_out: Ease::of(ease_out), tip: *tip, chamfer_angle: chamfer_angle.as_ref().map(expr).unwrap_or_default(), diff --git a/crates/ui-egui/src/dialogs_thread_tests.rs b/crates/ui-egui/src/dialogs_thread_tests.rs index 24c4cf8e5..efda600c8 100644 --- a/crates/ui-egui/src/dialogs_thread_tests.rs +++ b/crates/ui-egui/src/dialogs_thread_tests.rs @@ -73,10 +73,9 @@ fn every_option_reaches_the_command() { choose(&mut h, "Starts", "2"); choose(&mut h, "Extent", "Length"); type_in(&mut h, "Length", "6 mm"); - choose(&mut h, "Ease In", "Standard (2.5 P)"); - choose(&mut h, "Ease Out", "Length"); - type_in(&mut h, "Ease Out Length", "1.5 mm"); - choose(&mut h, "Tip", "Both"); + choose(&mut h, "End", "ui.fade"); + type_in(&mut h, "Fade Length", "1.5 mm"); + choose(&mut h, "Start", "Chamfer"); type_in(&mut h, "Chamfer Angle", "30 deg"); type_in(&mut h, "Chamfer Depth", "0.5 mm"); click(&mut h, &["dialog:Modeled"]); @@ -86,14 +85,20 @@ fn every_option_reaches_the_command() { p, json!({ "designation": "Tr20x4", "form": "trapezoidal", "hand": "left", "starts": 2, "extent": "length", "length": "6 mm", - "ease_in": "standard", "ease_out": "1.5 mm", "tip": "both", "chamfer_angle": "30 deg", "chamfer_depth": "0.5 mm", + "ease_out": "1.5 mm", "tip": "start", "chamfer_angle": "30 deg", "chamfer_depth": "0.5 mm", "modeled": true, }) ); - choose(&mut h, "Ease In", "Short (1.25 P)"); + // An empty fade length is ISO 3508's standard runout; a square end has none. + click(&mut h, &["dialog:Fade Length"]); + h.step(&json!({"key":"A","cmd":true})).unwrap(); + h.step(&json!({"key":"Backspace"})).unwrap(); + h.frames(2); choose(&mut h, "Hand", "Both"); let p = params(&h); - assert_eq!((&p["ease_in"], &p["hand"]), (&json!("short"), &json!("both"))); + assert_eq!((&p["ease_out"], &p["hand"]), (&json!("standard"), &json!("both"))); + choose(&mut h, "End", "thread.end_square"); + assert!(params(&h).get("ease_out").is_none()); } /// Buttress rows only for the buttress forms, the length only with a Length extent, the Up To @@ -102,10 +107,10 @@ fn every_option_reaches_the_command() { #[test] fn only_the_fields_that_apply_are_shown() { let mut h = shaft(); - for row in ["Form", "Size", "Pitch", "Designation", "Hand", "Starts", "Extent", "Ease In", "Ease Out", "Tip"] { + for row in ["Form", "Size", "Pitch", "Designation", "Hand", "Starts", "Extent", "Start", "End"] { assert!(shown(row), "{row}"); } - for row in ["Steep Flank", "Length", "Ease In Length", "Ease Out Length", "Chamfer Angle", "Chamfer Depth"] { + for row in ["Steep Flank", "Length", "Fade Length", "Chamfer Angle", "Chamfer Depth"] { assert!(!shown(row), "{row}"); } let inputs = |h: &Harness| h.app.dialog.as_ref().unwrap().inputs.iter().map(|i| i.label).collect::>(); @@ -130,10 +135,10 @@ fn only_the_fields_that_apply_are_shown() { assert!(shown("Length")); choose(&mut h, "Extent", "Full"); assert_eq!(inputs(&h), ["Cylindrical face"]); - choose(&mut h, "Ease In", "Length"); + choose(&mut h, "End", "ui.fade"); assert_eq!(inputs(&h), ["Cylindrical face", START_END], "a runout starts at an end"); - assert!(shown("Ease In Length") && !shown("Ease Out Length")); - choose(&mut h, "Tip", "Start"); + assert!(shown("Fade Length")); + choose(&mut h, "Start", "Chamfer"); assert!(shown("Chamfer Angle") && shown("Chamfer Depth")); let p = params(&h); assert!(p.get("chamfer_angle").is_none() && p.get("chamfer_depth").is_none(), "empty values take ISO 4753's: {p}"); @@ -178,7 +183,7 @@ fn a_form_change_keeps_what_still_applies() { choose(&mut h, "Starts", "3"); choose(&mut h, "Extent", "Length"); type_in(&mut h, "Length", "4 mm"); - choose(&mut h, "Ease Out", "Short (1.25 P)"); + choose(&mut h, "End", "ui.fade"); let kept = options(&h); choose(&mut h, "Form", "Trapezoidal (ISO 2904)"); @@ -196,7 +201,7 @@ fn a_form_change_keeps_what_still_applies() { let now = options(&h); assert_eq!(Options { form: kept.form, ..now.clone() }, kept); let p = params(&h); - assert_eq!((&p["hand"], &p["starts"], &p["length"], &p["ease_out"]), (&json!("left"), &json!(3), &json!("4 mm"), &json!("short"))); + assert_eq!((&p["hand"], &p["starts"], &p["length"], &p["ease_out"]), (&json!("left"), &json!(3), &json!("4 mm"), &json!("standard"))); } /// The dialog shows the command's own error text for options it cannot build. @@ -225,6 +230,56 @@ fn the_forms_are_the_documents_and_square_is_not_offered() { assert_eq!(example(ThreadForm::Trapezoidal), "Tr20x4"); } +/// The pipe threads: a G 1/2 shaft and an Rc 1/2 hole size themselves by the form, list their +/// sizes by designation without a pitch, and offer one start turning one way. +#[test] +fn pipe_forms_size_the_face_with_one_start_turning_one_way() { + let size = |h: &Harness| match &h.app.dialog.as_ref().unwrap().kind { + Kind::Thread { designation, .. } => designation.clone(), + k => panic!("{k:?}"), + }; + let open = |hole: bool| { + let mut h = Harness::new(); + h.call("ui.resize", json!({"width":1600,"height":1400})); + h.app.home.open = false; + if hole { + h.app.run("solid.box", json!({"corner":[-20,-20,0],"length":40,"width":40,"height":12,"body_name":"Body1"})).unwrap(); + h.app.run("solid.cylinder", json!({"base":[0,0,-1],"radius":9.2,"height":14,"body_name":"Bore"})).unwrap(); + h.app.run("solid.combine", json!({"target":"Body1","tools":["Bore"],"operation":"cut"})).unwrap(); + } else { + h.app.run("solid.cylinder", json!({"radius":20.955 / 2.0,"height":15})).unwrap(); + } + h.app.session.selection = vec![thread_face(&h.app, "Body1")]; + h.step(&json!({"start":"solid.thread"})).unwrap(); + h.frames(2); + h + }; + let mut h = open(false); + choose(&mut h, "Form", "thread.form_bspp"); + assert_eq!(size(&h), "G 1/2"); + assert!(shown("Size") && shown("Hand") && !shown("Pitch") && !shown("Starts")); + choose(&mut h, "Hand", "Left"); + let p = params(&h); + assert_eq!((&p["form"], &p["hand"]), (&json!("bspp"), &json!("left"))); + choose(&mut h, "Form", "thread.form_bspt"); + assert_eq!(size(&h), "R 1/2"); + choose(&mut h, "Form", "thread.form_npt"); + assert_eq!(params(&h)["form"], json!("npt")); + // A hand of both, from a form that has it, turns right on a pipe thread. + choose(&mut h, "Form", "ISO metric"); + choose(&mut h, "Hand", "Both"); + choose(&mut h, "Form", "thread.form_bspp"); + assert!(params(&h).get("hand").is_none(), "right, the default"); + + let mut h = open(true); + choose(&mut h, "Form", "thread.form_bspt"); + assert_eq!(size(&h), "Rc 1/2", "ISO 7-1 writes the internal taper thread Rc"); + choose(&mut h, "Form", "thread.form_rp"); + assert_eq!(size(&h), "Rp 1/2"); + let (cmd, p) = apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap().remove(0); + h.app.session.execute(&cmd, &p).unwrap_or_else(|e| panic!("Rp 1/2 in its hole: {e}")); +} + /// The face's size follows the form. #[test] fn the_face_size_follows_the_form() { @@ -246,7 +301,7 @@ fn a_saved_thread_reopens_with_every_option() { for (made, picks) in [ ( json!({"designation":"S20x4","steep_flank":"start","hand":"left","starts":2,"length":"12 mm","from":[10,0,20],"modeled":true, - "ease_in":"standard","ease_out":"1 mm","tip":"start","chamfer_angle":"30 deg","chamfer_depth":"0.5 mm"}), + "ease_out":"1 mm","tip":"start","chamfer_angle":"30 deg","chamfer_depth":"0.5 mm"}), vec!["Cylindrical face", START_END], ), (json!({"designation":"M20","from":[10,0,20],"up_to":[10,0,5]}), vec!["Cylindrical face", START_END, UP_TO]), @@ -277,7 +332,7 @@ fn a_saved_thread_reopens_with_every_option() { assert_eq!(p["extent"], extent); if made["designation"] == "S20x4" { assert_eq!(p["form"], "buttress", "the form is saved resolved"); - assert!(shown("Steep Flank") && shown("Chamfer Angle") && shown("Ease Out Length")); + assert!(shown("Steep Flank") && shown("Chamfer Angle") && shown("Fade Length")); } let (cmd, params) = apply_commands(&h.app, h.app.dialog.as_ref().unwrap()).unwrap().remove(0); h.app.session.execute(&cmd, ¶ms).unwrap_or_else(|e| panic!("{made}: OK on the reopened dialog: {e}")); diff --git a/docs/threads.md b/docs/threads.md index 6234c6758..f50e7efe8 100644 --- a/docs/threads.md +++ b/docs/threads.md @@ -24,6 +24,7 @@ modelled: a modelled thread is the maximum-material design profile below. | Buttress inch | `buttress_asme` | `2.5-8 BUTT` | 7° (load) / 45° | h = 0.6 P | (P − 0.6 P (tan 7° + 1))/2 = 0.16316 P | d − 1.2 P (basic) | d − 1.2 P, d (basic) | | Parallel pipe | `bspp` | `G 1/2` | 27.5° / 27.5° | h = 0.640327 P of H = 0.960491 P | (H − h) tan 27.5° = 0.1667 P, both | d − 2h | d − 2h, d | +| Parallel internal (ISO 7-1) | `rp` | `Rp 1/2` | 27.5° / 27.5° | h = 0.640327 P of H = 0.960491 P | (H − h) tan 27.5° = 0.1667 P, both | (internal only) | d − 2h, d | | Taper pipe (ISO 7-1) | `bspt` | `R 1/2`, `Rc 1/2` | 27.5° / 27.5° | h = 0.640327 P of H = 0.960237 P | (H − h) tan 27.5°, both | d − 2h at the gauge plane | d − 2h, d at the gauge plane | | NPT | `npt` | `1/2-14 NPT` | 30° / 30° | h = 0.8 P of H = 0.866025 P | (H − h) tan 30° = 0.038 P, both | E − h at the plane of E | E − h, E + h | @@ -44,9 +45,11 @@ just past the crest, and the material beyond the major cone (external) or inside vanish into the pipe's surface (ISO 7-1's incomplete thread). An external taper thread runs its standard length unless `length` or `up_to` says otherwise (ISO 7-1's useful thread for the basic gauge length, NPT's effective thread L2); an internal one the face. A pipe thread has one start and -turns one way; a chamfered tip is not cut on a taper thread yet. ISO 228-1's G sizes are ISO 7-1's -gauge-plane diameters (1/16 to 6); ISO 228-1's extra sizes (5/8, 7/8, …) are not tabulated yet, nor -is ISO 7-1's parallel internal Rp. +turns one way. A taper thread's chamfered tip (`tip`, with its `chamfer_depth`) is measured from the +major diameter the taper has at that end. ISO 228-1's G sizes are ISO 7-1's gauge-plane diameters +(1/16 to 6); ISO 228-1's extra sizes (5/8, 7/8, …) are not tabulated yet. ISO 7-1's parallel +internal thread Rp (`rp`, `Rp 1/2`), the one an R screws into, has the parallel form (H = 0.960491 +P) at the gauge diameters; it is internal only. Trapezoidal clearance ac (ISO 2904): 0.15 mm for P = 1.5, 0.25 mm for P 2 to 5, 0.5 mm for P 6 to 12, 1 mm for P 14 to 44. @@ -95,16 +98,17 @@ whole face. ## Runout and tip -**Runout** (`ease_in`, `ease_out`: a length, `standard` = 2.5 P or `short` = 1.25 P, ISO 3508's -normal and short thread runouts x): the groove fades out over that length, its section moving -out of the material as it turns (an external thread's away from the axis, past the surface; a -nut's towards it, into the hole), linearly, by SMLib's radial screw sweep. `ease_in` is at the end -the thread starts from (`from`, or the start of its extent), `ease_out` at the other. The runout -lies past the full-form length: beyond a square stop, and before a shoulder up to its clearance -(the full form then ends a runout short of it); at a free end it lies inside the face, the groove -reaching nothing at the end. No end gets a runout unless asked. Where the section moves, the -sweep's walls are within its tolerance (1e-4 P) of the true surfaces; full-depth turns are exact -radially. +**Runout** (`ease_out`: a length, `standard` = 2.5 P or `short` = 1.25 P, ISO 3508's normal and +short thread runouts x): the thread's inner end, away from where it starts, fades out over that +length, shorter than a turn too: its section moves out of the material as it turns (an external +thread's away from the axis, past the surface; a nut's towards it, into the hole), linearly, by +SMLib's radial screw sweep, and no end face is left. Without it the groove stops square there, +ending in its own profile, a flat face in the axial plane. The runout lies past the full-form +length: beyond a square stop, and before a shoulder up to its clearance (the full form then ends a +runout short of it); at a free end it lies inside the face, the groove reaching nothing at the +end. The start never fades: it runs off its free end, cut by the end face, plain or chamfered +(`tip`); `ease_in` is refused. Where the section moves, the sweep's walls are within its tolerance +(1e-4 P) of the true surfaces; full-depth turns are exact radially. **Tip** (ISO 4753's chamfered end; `tip: start` the end the thread starts from, which must be free, `tip: both` each free end it reaches): at those ends of a modelled external thread, after the groove, the material outside a cone `chamfer_angle` to the axis (45°) reaching