forked from 1b-agent/opencadstudio-upstream
Preserve periodic control-vertex spline seams
This commit is contained in:
1 parent
b84d387f43
commit
7a9ffef5cf
1 file changed
+19
-10
@@ -52,20 +52,29 @@ impl SplineCommand {
|
|||||||
if self.pts.len() < 2 {
|
if self.pts.len() < 2 {
|
||||||
return None;
|
return None;
|
||||||
}
|
}
|
||||||
let mut spline = make_spline(&self.pts, closed, self.control_vertices);
|
let spline = if self.control_vertices {
|
||||||
if self.control_vertices {
|
let points: Vec<_> = self.pts.iter().map(|point| point.to_array()).collect();
|
||||||
let count = spline.control_points.len();
|
control_spline(&points, self.degree.min(points.len() - 1), closed)?
|
||||||
let degree = self.degree.min(count - 1);
|
} else { make_spline(&self.pts, closed, false) };
|
||||||
spline.degree = degree as i32;
|
|
||||||
spline.knots = (0..count + degree + 1).map(|index| {
|
|
||||||
if index <= degree { 0.0 } else if index >= count { 1.0 }
|
|
||||||
else { (index - degree) as f64 / (count - degree) as f64 }
|
|
||||||
}).collect();
|
|
||||||
}
|
|
||||||
Some(EntityType::Spline(spline))
|
Some(EntityType::Spline(spline))
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
fn control_spline(points: &[[f64; 3]], degree: usize, closed: bool) -> Option<Spline> {
|
||||||
|
let curve = cadkernel::space::NurbsCurve3::from_control_polygon(degree, points, closed)?;
|
||||||
|
let mut spline = Spline {
|
||||||
|
degree: curve.degree() as i32,
|
||||||
|
control_points: curve.control_points().iter().map(|p| Vector3::new(p[0], p[1], p[2])).collect(),
|
||||||
|
knots: curve.knots().to_vec(),
|
||||||
|
weights: curve.weights().to_vec(),
|
||||||
|
..Default::default()
|
||||||
|
};
|
||||||
|
spline.flags.closed = closed;
|
||||||
|
spline.flags.periodic = closed;
|
||||||
|
spline.flags.planar = crate::entities::curve::spline_is_planar(&spline);
|
||||||
|
Some(spline)
|
||||||
|
}
|
||||||
|
|
||||||
/// Store the chosen construction method directly in the persistent spline.
|
/// Store the chosen construction method directly in the persistent spline.
|
||||||
fn make_spline(pts: &[DVec3], closed: bool, control_vertices: bool) -> Spline {
|
fn make_spline(pts: &[DVec3], closed: bool, control_vertices: bool) -> Spline {
|
||||||
let mut points: Vec<Vector3> = pts.iter().map(|p| Vector3::new(p.x, p.y, p.z)).collect();
|
let mut points: Vec<Vector3> = pts.iter().map(|p| Vector3::new(p.x, p.y, p.z)).collect();
|
||||||
|
|||||||
Reference in new issue
Block a user