use crate::{join_curve_chain, loft_profile_brep_guided, loft_profile_brep_guided_frame, BrepSolid, JointContinuity, KernelRefusal, KernelStage, NurbsCurve, SweepPath};
pub fn loft_profile_brep_guided_chain(sections: &[Vec<NurbsCurve>], guide: &[NurbsCurve], name: Option<&str>, rotate_to_frame: bool) -> Result<BrepSolid, KernelRefusal> {
let loft = |spine: &NurbsCurve| if rotate_to_frame { loft_profile_brep_guided_frame(sections, spine, name) } else { loft_profile_brep_guided(sections, spine, name) };
if let [spine] = guide {
return loft(spine);
}
let path = SweepPath::new(guide.to_vec(), Vec::new()).map_err(|error| error.with_message(|message| format!("guidedLoft: guide chain: {message}")))?;
if path.closed {
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"));
}
for joint in &path.joints {
if joint.continuity == JointContinuity::G0 {
return Err(KernelRefusal::input(
KernelStage::Classify,
"guide_corner",
format!(
"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)",
joint.tangent_break.to_degrees(),
joint.after,
joint.before
),
));
}
}
let spine = join_curve_chain(&path.curves).map_err(|message| KernelRefusal::input(KernelStage::Collect, "guide_chain", format!("guidedLoft: guide chain: {message}")))?;
loft(&spine)
}