Rebase the complete PR change onto current main, preserving changes previously stored in merge commits.
This commit is contained in:
@@ -27,7 +27,7 @@ pub static COMMANDS: &[CommandSpec] = &[
|
||||
.at("SOLID", "CREATE")
|
||||
.icon("sweep")
|
||||
.params("sketch: profile sketch; profiles?; path_sketch: sketch; path: [curve ids in order]; orientation?: perpendicular (default: square to the path, turning with it) | parallel (as drawn: the profile moves without turning; the path must keep crossing its plane) | [x,y,z] (square to the path, its turn about the path fixed by this direction); twist?: angle expr (the profile turns this much about the path over its length; within 4 turns); scale?: expr (the profile's scale at the end, linear along the path; 0.01…100); rails?: [{sketch?: sketch (default path_sketch), curves: [curve ids in order]}] (guide rails, one or two, each meeting every plane square to the path once along it, from the end nearest the path's start: one rail turns the profile so its point where the rail starts stays on the rail and scales it with the rail's distance from the path; two rails carry it between them, its points where they start staying on both; rails take the default orientation, no twist and no scale, and a path without sharp corners); rail_fit?: scale (default: the profile grows and shrinks evenly) | stretch (only across to the rail, between the rails); operation?, targets?, name?, body_name?"),
|
||||
CommandSpec::new("solid.loft", "Loft", loft).at("SOLID", "CREATE").icon("loft").params("sections: [{sketch, profiles?} | {sketch, point: id} (an apex)] (2 or more, in order); operation?, targets?, name?, body_name?"),
|
||||
CommandSpec::new("solid.loft", "Loft", loft).at("SOLID", "CREATE").icon("loft").params("sections: [{sketch, profiles?} | {sketch, point: id} (an apex)] (2…50, in order; matching hole counts, no holes at an apex); operation?, targets?, name?, body_name?"),
|
||||
CommandSpec::new("solid.box", "Box", prim_box).at("SOLID", "CREATE").icon("box").params("length, width, height: expr; corner?: [x,y,z] | center?: [x,y,z] (numbers in mm or length expressions; default: the origin); operation?, targets?: [body], name?, body_name?"),
|
||||
CommandSpec::new("solid.cylinder", "Cylinder", prim_cylinder).at("SOLID", "CREATE").icon("cylinder").params("radius | diameter, height: expr; base?: [x,y,z] (centre of the bottom: numbers in mm or length expressions; default: the origin); axis?: X|Y|Z|[x,y,z] (default Z); operation?, targets?: [body], name?, body_name?"),
|
||||
CommandSpec::new("solid.sphere", "Sphere", prim_sphere).at("SOLID", "CREATE").icon("sphere").params("radius | diameter: expr; center?: [x,y,z] (numbers in mm or length expressions; default: the origin); operation?, targets?: [body], name?, body_name?"),
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
//! A loft section that is a ring (a profile with a hole) is refused (#1184): the loft builds each
|
||||
//! section from its outline, so it used to fill the hole and report success.
|
||||
//! A loft section that is a ring keeps its passage (#2435); incompatible sections
|
||||
//! are refused atomically rather than silently filling the hole (#1184).
|
||||
|
||||
use super::*;
|
||||
|
||||
@@ -11,24 +11,42 @@ fn ring(s: &mut Session, name: &str, z: f64) {
|
||||
run(s, "sketch.finish", json!({}));
|
||||
}
|
||||
|
||||
fn refused(s: &mut Session, sections: Value) {
|
||||
fn refused(s: &mut Session, sections: Value, message: &str) {
|
||||
let saved = s.doc.to_json();
|
||||
let err = s.execute("solid.loft", &json!({"sections": sections, "operation": "new"})).err().map(|e| e.to_string());
|
||||
assert!(err.as_deref().is_some_and(|e| e.contains("not supported yet: a loft section with a hole")), "{err:?}");
|
||||
assert!(err.as_deref().is_some_and(|e| e.contains(message)), "{err:?}");
|
||||
assert_eq!(s.doc.to_json(), saved);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_ring_section_is_refused_not_filled() {
|
||||
fn a_ring_section_keeps_its_hole_and_rejects_a_disc() {
|
||||
let mut s = Session::default();
|
||||
ring(&mut s, "A", 0.0);
|
||||
ring(&mut s, "B", 20.0);
|
||||
let ring_at = |n: &str| json!({"sketch": n, "profiles": [{"point": [16, 0]}]});
|
||||
refused(&mut s, json!([ring_at("A"), ring_at("B")]));
|
||||
let sections = json!([ring_at("A"), ring_at("B")]);
|
||||
run(&mut s, "solid.loft", json!({"sections": sections, "operation": "new"}));
|
||||
let want = PI * (400.0 - 144.0) * 20.0;
|
||||
assert!(rel(volume(&mut s), want) < 1e-3);
|
||||
let reopened = Session::new(solidcraft_doc::Document::from_json(&s.doc.to_json()).unwrap());
|
||||
assert!(reopened.model.results.iter().all(|r| r.error.is_none()));
|
||||
let st = reopened.model.state();
|
||||
let body = &st.bodies[0];
|
||||
assert!(body.body.validity().is_empty());
|
||||
assert_eq!(body.body.shell_count(), 1);
|
||||
for face in 0..body.body.face_count() {
|
||||
assert!(solidcraft_doc::naming::face_name_exact(body, face), "face {face} lost its sketch-curve provenance");
|
||||
}
|
||||
assert!(!body.body.tessellate(0.001).unwrap().contains(solidcraft_geom::Vec3::new(0.0, 0.0, 10.0)));
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
assert!(s.model.state().bodies.is_empty());
|
||||
run(&mut s, "edit.redo", json!({}));
|
||||
assert!(rel(volume(&mut s), want) < 1e-3);
|
||||
run(&mut s, "edit.undo", json!({}));
|
||||
// A ring and a plain disc, in either order.
|
||||
let disc_b = json!({"sketch": "B", "profiles": [{"point": [0, 0]}]});
|
||||
refused(&mut s, json!([ring_at("A"), disc_b]));
|
||||
refused(&mut s, json!([disc_b, ring_at("A")]));
|
||||
refused(&mut s, json!([ring_at("A"), disc_b]), "same number of holes");
|
||||
refused(&mut s, json!([disc_b, ring_at("A")]), "same number of holes");
|
||||
// The discs inside the holes still loft into a cylinder of radius 12.
|
||||
run(&mut s, "solid.loft", json!({"sections": [{"sketch": "A", "profiles": [{"point": [0, 0]}]}, disc_b], "operation": "new"}));
|
||||
let want = std::f64::consts::PI * 12.0 * 12.0 * 20.0;
|
||||
@@ -47,5 +65,39 @@ fn a_ring_lofted_to_a_point_is_refused() {
|
||||
run(&mut s, "sketch.create", json!({"plane": "XY", "offset": 20, "name": "Top"}));
|
||||
run(&mut s, "sketch.point", json!({"point": [0, 0], "id": "apex"}));
|
||||
run(&mut s, "sketch.finish", json!({}));
|
||||
refused(&mut s, json!([{"sketch": "A", "profiles": [{"point": [16, 0]}]}, {"sketch": "Top", "point": "apex"}]));
|
||||
refused(
|
||||
&mut s,
|
||||
json!([{"sketch": "A", "profiles": [{"point": [16, 0]}]}, {"sketch": "Top", "point": "apex"}]),
|
||||
"lofting a section with holes to a point",
|
||||
);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_ring_loft_joins_cuts_and_intersects_without_filling_the_hole() {
|
||||
for operation in ["join", "cut", "intersect"] {
|
||||
let mut s = Session::default();
|
||||
run(&mut s, "solid.box", json!({"length": 50, "width": 50, "height": 10, "corner": [-25, -25, -5]}));
|
||||
ring(&mut s, "A", 0.0);
|
||||
ring(&mut s, "B", 20.0);
|
||||
let sections = json!([{"sketch": "A", "profiles": [{"point": [16, 0]}]}, {"sketch": "B", "profiles": [{"point": [16, 0]}]}]);
|
||||
run(&mut s, "solid.loft", json!({"sections": sections, "operation": operation}));
|
||||
let area = PI * (400.0 - 144.0);
|
||||
let want = match operation {
|
||||
"join" => 25000.0 + area * 15.0,
|
||||
"cut" => 25000.0 - area * 5.0,
|
||||
_ => area * 5.0,
|
||||
};
|
||||
assert!(rel(volume(&mut s), want) < 1e-3, "{operation}");
|
||||
for b in &s.model.state().bodies {
|
||||
assert!(b.body.validity().is_empty(), "{operation}: {:?}", b.body.validity());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn tapered_ring_loft_reproduction() {
|
||||
let mut s = Session::default();
|
||||
s.run_script(&serde_json::from_str(include_str!("../../../../examples/regressions/loft_rings.json")).unwrap()).unwrap();
|
||||
let want = PI * 30.0 / 3.0 * ((400.0 + 280.0 + 196.0) - (144.0 + 96.0 + 64.0));
|
||||
assert!(rel(volume(&mut s), want) < 1e-3);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user