Skip to main content

brep_construction/construction/
loft_guide_chain.rs

1//! The guided loft along a guide that is a chain of curves.
2//!
3//! The guided loft ([`crate::loft_profile_brep_guided`] and
4//! [`crate::loft_profile_brep_guided_frame`]) bends its sections along ONE
5//! spine curve. A guide drawn as several curves that meet smoothly (a line
6//! into a fillet arc into a line) is such a spine: the chain is joined into
7//! one curve ([`crate::join_curve_chain`], exactly, each piece on a stretch of
8//! the parameter as long as the piece) and lofted along. A chain with a corner
9//! is not a spine: the loft's skin passes smoothly through its stations and
10//! would round the corner off, so it is refused by name with the angle
11//! measured there.
12use crate::{join_curve_chain, loft_profile_brep_guided, loft_profile_brep_guided_frame, BrepSolid, JointContinuity, KernelRefusal, KernelStage, NurbsCurve, SweepPath};
13
14/// The loft of `sections` along the guide `guide`, a chain of curves that
15/// follow one another head to tail and meet smoothly; `rotate_to_frame` turns
16/// the sections with the guide's moving frame
17/// ([`crate::loft_profile_brep_guided_frame`]) instead of keeping their own
18/// orientation ([`crate::loft_profile_brep_guided`]). A chain of one curve is
19/// that curve.
20///
21/// Refuses, by name: an empty chain (the path's own refusal), curves that do
22/// not meet (`guide_chain`), a chain that closes on itself (`guide_closed`), and a joint where
23/// the tangent turns (`guide_corner`, with the angle).
24pub fn loft_profile_brep_guided_chain(sections: &[Vec<NurbsCurve>], guide: &[NurbsCurve], name: Option<&str>, rotate_to_frame: bool) -> Result<BrepSolid, KernelRefusal> {
25    let loft = |spine: &NurbsCurve| if rotate_to_frame { loft_profile_brep_guided_frame(sections, spine, name) } else { loft_profile_brep_guided(sections, spine, name) };
26    if let [spine] = guide {
27        return loft(spine);
28    }
29    let path = SweepPath::new(guide.to_vec(), Vec::new()).map_err(|error| error.with_message(|message| format!("guidedLoft: guide chain: {message}")))?;
30    if path.closed {
31        return Err(KernelRefusal::input(KernelStage::Classify, "guide_closed", "guidedLoft: the guide chain closes on itself; a guide runs from the first section to the last"));
32    }
33    for joint in &path.joints {
34        if joint.continuity == JointContinuity::G0 {
35            return Err(KernelRefusal::input(
36                KernelStage::Classify,
37                "guide_corner",
38                format!(
39                    "guidedLoft: the guide turns {:.3}° where its curve {} follows curve {}; the curves of a guide chain must meet smoothly (a loft along a corner would round it off)",
40                    joint.tangent_break.to_degrees(),
41                    joint.after,
42                    joint.before
43                ),
44            ));
45        }
46    }
47    let spine = join_curve_chain(&path.curves).map_err(|message| KernelRefusal::input(KernelStage::Collect, "guide_chain", format!("guidedLoft: guide chain: {message}")))?;
48    loft(&spine)
49}
50