#1949 joined the straight runs of a profile into one side face for straight extrudes; tapered extrudes (extrude_tapered, extrude_tapered_between) still sloped each piece as its own face, so a drafted mirrored profile kept the edge. They now join the runs the same way (NumberedLoop::merged_lines), the sloped side generated by every piece under it. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com> Co-authored-by: bherbruck <brennen.herbruck@gmail.com>
This commit is contained in:
@@ -3778,3 +3778,15 @@ fn a_sketch_on_one_piece_stays_attached_when_the_side_joins() {
|
||||
let sketch = run(&mut s, "timeline.inspect", json!({"feature": "Sketch2"}));
|
||||
assert!(sketch["error"].is_null() && sketch["warning"].is_null(), "{sketch}");
|
||||
}
|
||||
|
||||
/// With a taper too, a side drawn in two collinear pieces extrudes into one face (#1788).
|
||||
#[test]
|
||||
fn a_tapered_side_drawn_in_two_collinear_pieces_is_one_face() {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "sketch.create", json!({"plane": "XY"}));
|
||||
run(&mut s, "sketch.line", json!({"points": [[0, 0], [10, 0], [20, 0], [20, 10], [0, 10], [0, 0]]}));
|
||||
run(&mut s, "sketch.finish", json!({}));
|
||||
run(&mut s, "solid.extrude", json!({"distance": 5, "taper": "5 deg"}));
|
||||
let m = run(&mut s, "inspect.measure", json!({}));
|
||||
assert_eq!(m["bodies"][0]["kernel"]["faces"], 6, "{m}");
|
||||
}
|
||||
|
||||
@@ -1328,7 +1328,9 @@ pub fn extrude_tapered_between(plane: &Plane, region: &Region2, from: f64, to: f
|
||||
region_ok(region)?;
|
||||
let (t, sign) = (taper.tan(), dir_sign.signum());
|
||||
let (bottom_plane, top_plane) = (plane.offset(from * sign), plane.offset(to * sign));
|
||||
let loops0 = oriented(region)?;
|
||||
// A side drawn in collinear pieces slopes as one face over all of them, as a straight
|
||||
// extrude's does (#1788).
|
||||
let loops0 = oriented(region)?.map_loops(|l| l.merged_lines(continues_straight));
|
||||
let split: Vec<(Loop2, Vec<usize>)> = loops0.loops().map(|l| offset_splits(&l.lp, from.abs().max(to.abs()) * t)).collect();
|
||||
let ends = |h: f64| split.iter().map(|(lp, _)| offset_loop(lp, h * t)).collect::<Result<Vec<_>>>();
|
||||
let (bottoms, tops) = (ends(from)?, ends(to)?);
|
||||
|
||||
@@ -277,3 +277,28 @@ fn collinear_profile_lines_extrude_into_one_side_face() {
|
||||
let body = crate::extrude_whole_sides(&Plane::XY, &[Region2 { outer: Loop2::polygon(&step), holes: vec![] }], 0.0, 5.0).unwrap().pop().unwrap();
|
||||
assert_eq!(body.face_count(), 8);
|
||||
}
|
||||
|
||||
/// A tapered extrude joins a side drawn in collinear pieces as the straight extrude does
|
||||
/// (#1788): one sloped face generated by both pieces, and the same solid as a side in one piece.
|
||||
#[test]
|
||||
fn collinear_profile_lines_taper_into_one_side_face() {
|
||||
use solidcraft_geom::{Loop2, Plane, Region2, Vec2};
|
||||
let polygon =
|
||||
|pts: &[(f64, f64)]| Region2 { outer: Loop2::polygon(&pts.iter().map(|&(x, y)| Vec2::new(x, y)).collect::<Vec<_>>()), holes: vec![] };
|
||||
let split = polygon(&[(0.0, 0.0), (10.0, 0.0), (20.0, 0.0), (20.0, 10.0), (0.0, 10.0)]);
|
||||
let whole = polygon(&[(0.0, 0.0), (20.0, 0.0), (20.0, 10.0), (0.0, 10.0)]);
|
||||
let taper = 5f64.to_radians();
|
||||
for (from, to, foot) in [(0.0, 5.0, 0.0), (-1.0, 5.0, 1.0)] {
|
||||
let body = crate::extrude_tapered_between(&Plane::XY, &split, from, to, foot, 1.0, taper).unwrap();
|
||||
let reference = crate::extrude_tapered_between(&Plane::XY, &whole, from, to, foot, 1.0, taper).unwrap();
|
||||
assert_eq!(body.face_count(), reference.face_count(), "{from}..{to} foot {foot}: as many faces as one piece");
|
||||
let (v, w) = (crate::measure(&body).unwrap().volume, crate::measure(&reference).unwrap().volume);
|
||||
assert!((v - w).abs() < 1e-9 * w, "{v} vs {w}");
|
||||
let h = body.history().unwrap();
|
||||
h.check(&body, &[]).unwrap();
|
||||
assert!(
|
||||
h.faces.iter().any(|f| f.origins == vec![FaceOrigin::Profile { segment: 0 }, FaceOrigin::Profile { segment: 1 }]),
|
||||
"the bottom side is generated by both its pieces"
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user