Merge solidcore 9b73dfe74 (ws/pin-5) into ws/default-solidcore
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01MNXLXkZLQ6T7TSi4wswcmk
This commit is contained in:
commit
ad6fd72bcf
9 files changed
+311
-175
No files matched your search
Generated
+1
-1
@@ -4054,7 +4054,7 @@ dependencies = [
|
||||
[[package]]
|
||||
name = "solidcore"
|
||||
version = "1.0.1"
|
||||
source = "git+https://github.com/tangency-labs/solidcore?rev=bdd614891fcfa5941558bff81a49d1bc7a8fbef2#bdd614891fcfa5941558bff81a49d1bc7a8fbef2"
|
||||
source = "git+https://github.com/tangency-labs/solidcore?rev=9dde25e97b05dd986b2ba49b8a03622b3ed572f9#9dde25e97b05dd986b2ba49b8a03622b3ed572f9"
|
||||
dependencies = [
|
||||
"thiserror 2.0.21",
|
||||
]
|
||||
|
||||
+1
-1
@@ -35,7 +35,7 @@ solidcraft-3dx-client = { path = "crates/threedx-client" }
|
||||
# they reach parity (crates/smlib/src/route.rs). Pinned; move the rev on its own commit. For a
|
||||
# local checkout, add `[patch."https://github.com/tangency-labs/solidcore"] solidcore = { path =
|
||||
# "../solidcore/crates/solidcore" }` to a `.cargo/config.toml` outside the repository.
|
||||
solidcore = { git = "https://github.com/tangency-labs/solidcore", rev = "bdd614891fcfa5941558bff81a49d1bc7a8fbef2" }
|
||||
solidcore = { git = "https://github.com/tangency-labs/solidcore", rev = "9dde25e97b05dd986b2ba49b8a03622b3ed572f9" }
|
||||
|
||||
# foundation
|
||||
thiserror = "2"
|
||||
|
||||
@@ -12,6 +12,14 @@ fn wedge() -> Body {
|
||||
fillet_variable_spline(&body, at, t.start, &t.spline).unwrap()
|
||||
}
|
||||
|
||||
/// The wedge's variable round: V 5223.0386, on whichever kernel the test runs (the fork's variable
|
||||
/// round follows the fillet between its traced points, 4438859, and solidcore's with it).
|
||||
#[test]
|
||||
fn the_wedge_round_keeps_its_volume() {
|
||||
let v = crate::measure(&wedge()).unwrap().volume;
|
||||
assert!((v - 5223.0386).abs() < 1e-3, "{v}");
|
||||
}
|
||||
|
||||
/// The display mesh of a fillet tapering to zero at a wedge's tip converges to the B-rep: each
|
||||
/// mesh lies within its chord tolerance of the faces, so its volume is within the body's area
|
||||
/// times that tolerance of the exact one (SMLib's, integrated on the surfaces, to 1e-8). Only
|
||||
|
||||
+50
-19
@@ -246,26 +246,44 @@ pub(crate) fn fixes() -> UpstreamFixes {
|
||||
f.good_drop_result_distances_in_order = true;
|
||||
f.face_tight_box_searches_trim = true;
|
||||
f.ssi_low_angle_start_on_probation = true;
|
||||
f.fillet_variable_span_follows_fillet = true;
|
||||
f.simple_coincidence_crossing_is_point = true;
|
||||
f.boolean_temporary_transform_statuses = true;
|
||||
f.primitive_path_curve_statuses = true;
|
||||
f.planar_path_sweep_statuses = true;
|
||||
f.planar_path_profile_placement_statuses = true;
|
||||
f.fillet_trim_status = true;
|
||||
f.perspective_sphere_offsets = true;
|
||||
f
|
||||
}
|
||||
|
||||
/// Opt-in fixes left off because the C++ fork (`SMLIB_REV`) does not carry them yet, so turning
|
||||
/// them on would part this backend from the C++ one. `precise_properties_trim_base_v`
|
||||
/// (solidcore#1664, WR-563), `bspline_trim_keeps_rational_end_spans` (solidcore#1711, WR-575) and
|
||||
/// `fillet_blend_curve_revolved_on_arc` (solidcore#1759, WR-581, an own design waiting for the
|
||||
/// fork's fix) have no fork commit. `fillet_trim_status` (solidcore#674, WR-604) has no fork
|
||||
/// commit. `temporary_radius_setup_errors` (solidcore#644, #458), `ellipse_step_interval_checks`
|
||||
/// (solidcore#686, #428) and `perspective_sphere_offsets` (solidcore#684, WR-608, #525) are the
|
||||
/// port's own fixes with no fork commit; the C++ build keeps upstream's behaviour there.
|
||||
/// `corner_patch_face_side_twist` (WR-613, fork 7fd9fb0) ports a fork commit that is not
|
||||
/// published.
|
||||
/// Opt-in fixes left off because the C++ fork (`SMLIB_REV`) does not behave as they do, so turning
|
||||
/// them on would part this backend from the C++ one. Each was read in the fork's source at 2fc375f.
|
||||
///
|
||||
/// `boolean_union_refuses_solid_leak` (solidcore#1794, WR-619) is solidcore's own design;
|
||||
/// `curve_loop_start_after_previous_end` (WR-96), `loop_use_reports_open_gaps` (WR-93),
|
||||
/// `planar_path_profile_placement_statuses` (WR-632, #483), `face_points_span_domain` (WR-86),
|
||||
/// `drop_curve_v_domain_degeneracy` (WR-100) and `mirror_curve_keeps_euclidean_control_points`
|
||||
/// (WR-98) are the port's fixes of upstream defects: none has a fork commit, and the C++ build
|
||||
/// keeps upstream's behaviour there.
|
||||
/// Upstream's defect is still there: `precise_properties_trim_base_v` (WR-563: `SmODEAreaIFEO` starts
|
||||
/// at the domain's lowest v), `fillet_blend_curve_revolved_on_arc` (WR-581: `CalcTorusFilletGeom` takes
|
||||
/// circular and linear sections only), `ellipse_step_interval_checks` (WR-211: `AdjustSTEPInterval`
|
||||
/// tests no inverted or collapsed interval), `boolean_union_refuses_solid_leak` (WR-619: STEP 6 deletes
|
||||
/// without testing regions), `curve_loop_start_after_previous_end` (WR-96), `loop_use_reports_open_gaps`
|
||||
/// (WR-93), `face_points_span_domain` (WR-86), `drop_curve_v_domain_degeneracy` (WR-100),
|
||||
/// `mirror_curve_keeps_euclidean_control_points` (WR-98), `geometric_g2_continuity` (WR-380: a normal
|
||||
/// compared with itself), `fillet_corner_variable_radius_rail_on_opposite_fillet` (WR-645: no test of
|
||||
/// the rail against the opposite fillet), `sphere_from_arcs_common_centre` (WR-103: `rOrigin` refers to
|
||||
/// the origin it is compared with), `dupin_bottom_hyperbola_axis` (WR-69: k2 for both axes),
|
||||
/// `extent3d_contains_both_segment_endpoints` (WR-3: `ContainsLineSeg3d` ors its two points),
|
||||
/// `gap_samples_use_trimmed_spans` (WR-89: `BuildSampleSet` spans from the first knot),
|
||||
/// `twist_simple_duw_sign` (WR-46: `EvaluateSimple`'s Duw y is -per cos) and
|
||||
/// `translation_sweep_regularize` (solidcore#1937: nothing regularizes after the sweep).
|
||||
///
|
||||
/// The fork deals with it another way: `bspline_trim_keeps_rational_end_spans` (WR-575: the fork keeps
|
||||
/// a short span of a UV curve, and still removes a 3D conic's) and `corner_patch_face_side_twist`
|
||||
/// (WR-613: the fork refines the patch, `corner_blend_coons_patch_tangent_to_sides`).
|
||||
///
|
||||
/// The fork carries on softly where these refuse: `temporary_radius_setup_errors` (#458: a scope guard
|
||||
/// cannot report), `fillet_corner_statuses` (`sm_TestG1Continuity`: no tangent is no tangency),
|
||||
/// `fillet_edge_curve_domain_statuses` (`sm_CheckEdgeCurveDomains`: a failed trim keeps the edge's
|
||||
/// curve), `offset_tangent_gap_statuses` (`HaveTangentGaps`: a failed sample shows no gap) and
|
||||
/// `ssi_alignment_statuses` (`ALIGN_DIR_WITH_PREVIOUS_POINT`: no angle, no alignment).
|
||||
///
|
||||
/// On since `SMLIB_REV` eaa998a: `fillet_trim_inside_by_best_dot` (fork de4dae6),
|
||||
/// `fillet_half_degree_crease` (2e8758b), `fillet_split_edge_keeps_near_half` (ceb3272) and
|
||||
@@ -281,20 +299,26 @@ pub(crate) fn fixes() -> UpstreamFixes {
|
||||
/// `sRefFrame`'s origin with `rOrigin`, a reference to it), `dupin_bottom_hyperbola_axis` (WR-69:
|
||||
/// `MakeDupin`'s bottom hyperbola takes k2 for both axes) and
|
||||
/// `extent3d_contains_both_segment_endpoints` (WR-3: `ContainsLineSeg3d` ors its two points).
|
||||
///
|
||||
/// The fork handles a failed status softly where these flags refuse (solidcore#1775, #483), so the
|
||||
/// flags would fail where the C++ kernel carries on: `fillet_corner_statuses` (`sm_TestG1Continuity`:
|
||||
/// no tangent is no tangency), `fillet_edge_curve_domain_statuses` (`sm_CheckEdgeCurveDomains`: a
|
||||
/// failed trim keeps the edge's curve), `offset_tangent_gap_statuses` (`HaveTangentGaps`: a failed
|
||||
/// sample shows no gap) and `ssi_alignment_statuses` (`ALIGN_DIR_WITH_PREVIOUS_POINT`: no angle, no
|
||||
/// alignment). `translation_sweep_regularize` (solidcore#1937) has no fork commit, and the fork keeps
|
||||
/// upstream's `gap_samples_use_trimmed_spans` (WR-89: `BuildSampleSet` spans from the first knot) and
|
||||
/// `twist_simple_duw_sign` (WR-46: `EvaluateSimple`'s Duw y is -per cos).
|
||||
#[cfg(test)]
|
||||
const HELD_BACK: &[&str] = &[
|
||||
"precise_properties_trim_base_v",
|
||||
"bspline_trim_keeps_rational_end_spans",
|
||||
"fillet_blend_curve_revolved_on_arc",
|
||||
"fillet_trim_status",
|
||||
"temporary_radius_setup_errors",
|
||||
"ellipse_step_interval_checks",
|
||||
"perspective_sphere_offsets",
|
||||
"corner_patch_face_side_twist",
|
||||
"boolean_union_refuses_solid_leak",
|
||||
"curve_loop_start_after_previous_end",
|
||||
"loop_use_reports_open_gaps",
|
||||
"planar_path_profile_placement_statuses",
|
||||
"face_points_span_domain",
|
||||
"drop_curve_v_domain_degeneracy",
|
||||
"mirror_curve_keeps_euclidean_control_points",
|
||||
@@ -303,6 +327,13 @@ const HELD_BACK: &[&str] = &[
|
||||
"sphere_from_arcs_common_centre",
|
||||
"dupin_bottom_hyperbola_axis",
|
||||
"extent3d_contains_both_segment_endpoints",
|
||||
"fillet_corner_statuses",
|
||||
"fillet_edge_curve_domain_statuses",
|
||||
"offset_tangent_gap_statuses",
|
||||
"ssi_alignment_statuses",
|
||||
"translation_sweep_regularize",
|
||||
"gap_samples_use_trimmed_spans",
|
||||
"twist_simple_duw_sign",
|
||||
];
|
||||
|
||||
fn fresh() -> Kernel {
|
||||
|
||||
@@ -519,7 +519,7 @@ fn rounds_at_a_concave_face_corner_are_mitred() {
|
||||
/// The back and left top edges are each trimmed 8 by those rounds: (0, 30)-(32, 30) and (0, 8)-(0, 30)
|
||||
/// at z = 10, and each piece keeps its edge's attribute (`Behavior::Copy`), as on the fork.
|
||||
#[test]
|
||||
#[ignore = "solidcore bug: SubtractRemovalRegion loses the attributes of target edges it replaces (next-pin/bugs/cliff-overflow-loses-edge-attributes.md)"]
|
||||
#[ignore = "solidcore#1980 (PR #1977): SubtractRemovalRegion loses the attributes of target edges it replaces"]
|
||||
fn an_edge_tag_crosses_a_cliff_overflow() {
|
||||
use solidcore::blend::fillet_executive::session::FilletSession;
|
||||
use solidcore::boolean::api_brep::boolean_difference;
|
||||
@@ -566,7 +566,7 @@ fn an_edge_tag_crosses_a_cliff_overflow() {
|
||||
/// 21000 - (50 d² + 4/3 d³) = 19265.666666667 (the fork, and the same body through the flat
|
||||
/// arrays). Refused: error 3, Corner Edge Computation Failure.
|
||||
#[test]
|
||||
#[ignore = "solidcore bug: next-pin/bugs/chamfer-boolean-body-keep-operand-uv-trims.md"]
|
||||
#[ignore = "solidcore#1981 (PR #1996)"]
|
||||
fn pocket_chamfer_on_a_boolean_body() {
|
||||
use solidcore::blend::fillet_executive::session::FilletSession;
|
||||
use solidcore::boolean::api_brep::boolean_difference;
|
||||
@@ -836,3 +836,138 @@ fn knife_edge_chamfers() {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// The part from SolidCraft #871: a plate with a narrower block on top and a window through both.
|
||||
fn part_871() -> Body {
|
||||
let (a, b) = (12.74437365538526, 22.69275963366936);
|
||||
let at = |lo: [f64; 3], hi: [f64; 3]| make_box(lo, [hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2]]).unwrap();
|
||||
let joined = boolean(&at([9.5, 8.0, 0.0], [23.5, 29.5, 10.0]), &at([9.5, a, 10.0], [23.5, b, 20.0]), BooleanOp::Union).unwrap().unwrap();
|
||||
boolean(&joined, &at([9.5, 14.0, 7.0], [23.5, 19.2, 14.1]), BooleanOp::Subtract).unwrap().unwrap()
|
||||
}
|
||||
|
||||
/// The 12 edges round each of the part's two end faces.
|
||||
fn edges_871() -> Vec<[f64; 3]> {
|
||||
let yz = [
|
||||
(12.74437365538526, 15.0),
|
||||
(10.37218682769263, 10.0),
|
||||
(8.0, 5.0),
|
||||
(18.75, 0.0),
|
||||
(29.5, 5.0),
|
||||
(26.09637981683468, 10.0),
|
||||
(22.69275963366936, 15.0),
|
||||
(17.71856664452731, 20.0),
|
||||
(16.6, 7.0),
|
||||
(14.0, 10.55),
|
||||
(16.6, 14.100000000000001),
|
||||
(19.200000000000003, 10.55),
|
||||
];
|
||||
[23.5, 9.5].iter().flat_map(|x| yz.iter().map(move |(y, z)| [*x, *y, *z])).collect()
|
||||
}
|
||||
|
||||
/// #871's rounds at r 0.5 fit (the wall between the window and the block's side is 1.26 thick):
|
||||
/// 38 faces, and the closed form `issue_871_tests::rounds_that_fit_are_closed` derives. At r 1 they
|
||||
/// overlap, which is refused. With SMLib built, the C++ kernel gives the same.
|
||||
#[test]
|
||||
fn rounds_on_the_871_part() {
|
||||
let p = part_871();
|
||||
let e = edges_871();
|
||||
let sizes = |r: f64| vec![r; e.len()];
|
||||
let part_volume = 14.0 * (21.5 * 10.0 + (22.69275963366936 - 12.74437365538526) * 10.0 - 5.2 * 7.1);
|
||||
let exact = part_volume - 2.0 * (2.0 * (21.5 + 20.0) + 2.0 * (5.2 + 7.1)) * spandrel(0.5);
|
||||
let fit = blend(&p, Blend::Round, &e, &sizes(0.5), TOL, &[], &[], Corners::Filled).unwrap();
|
||||
let (v, n) = (volume(&fit, 1e-8).unwrap(), counts(&fit).unwrap());
|
||||
let refused = blend(&p, Blend::Round, &e, &sizes(1.0), TOL, &[], &[], Corners::Filled).map(|_| ()).unwrap_err();
|
||||
assert_eq!(refused, Error::NoRoom);
|
||||
assert_eq!(n[0], 38);
|
||||
assert!((v - exact).abs() < 1e-3, "{v} vs {exact}");
|
||||
#[cfg(feature = "native")]
|
||||
{
|
||||
use crate::{Brep, ffi};
|
||||
crate::init().unwrap();
|
||||
let bx = |lo: [f64; 3], hi: [f64; 3]| ffi::make_box(&lo, &[hi[0] - lo[0], hi[1] - lo[1], hi[2] - lo[2]]).unwrap();
|
||||
let top = ffi::ops::boolean(
|
||||
&bx([9.5, 8.0, 0.0], [23.5, 29.5, 10.0]),
|
||||
&bx([9.5, 12.74437365538526, 10.0], [23.5, 22.69275963366936, 20.0]),
|
||||
ffi::ops::BOOLEAN_UNION,
|
||||
)
|
||||
.unwrap();
|
||||
let cut = ffi::ops::boolean(&top, &bx([9.5, 14.0, 7.0], [23.5, 19.2, 14.1]), ffi::ops::BOOLEAN_SUBTRACT).unwrap();
|
||||
let cpp = Brep::made(cut);
|
||||
let h = cpp.cpp().unwrap();
|
||||
let fit = ffi::ops::blend(ffi::ops::BLEND_ROUND, h, &e, &sizes(0.5), TOL).unwrap();
|
||||
let (cv, cn) = (ffi::volume(&fit, 1e-8).unwrap(), ffi::counts(&fit).unwrap().map(|x| usize::try_from(x).unwrap()));
|
||||
let crefused = ffi::ops::blend(ffi::ops::BLEND_ROUND, h, &e, &sizes(1.0), TOL).map(|_| ());
|
||||
assert!(rel(v, cv) < 1e-9, "solidcore {v} vs C++ {cv}");
|
||||
assert_eq!(n, cn);
|
||||
assert!(crefused.is_err());
|
||||
}
|
||||
}
|
||||
|
||||
/// The fork's `tabbed_plate_rounds_mitred_on_the_arcs_continuation`: a plate 2 thick, its outline an
|
||||
/// R25 arc to the sides x = +-4 of a tab whose top is 4 wide with R2 corners, every top edge of the
|
||||
/// outline rounded r 0.5. The arc's round and the tab side's are mitred on the arc wall's
|
||||
/// continuation. Removed: the outline's area less the area of the outline moved in by
|
||||
/// d = r (1 - cos phi), at the height r sin phi into the round (midpoint rule, 8192 steps; the area
|
||||
/// by Green's theorem). With SMLib built, the C++ kernel gives the same.
|
||||
#[test]
|
||||
fn tabbed_plate_rounds_mitred_on_the_arcs_continuation() {
|
||||
use super::sweep::extrude;
|
||||
use crate::sweeps::{Curve, DraftCorner};
|
||||
const Z: [f64; 3] = [0.0, 0.0, 1.0];
|
||||
let theta = (4.0_f64 / 25.0).acos();
|
||||
let y = 609.0_f64.sqrt();
|
||||
let cy = 280.0 / 9.0;
|
||||
let line = |a: [f64; 2], b: [f64; 2]| Curve::Line { start: [a[0], a[1], 0.0], end: [b[0], b[1], 0.0] };
|
||||
let arc = |c: [f64; 2], radius, start, end| Curve::Arc { center: [c[0], c[1], 0.0], axis: Z, reference: [1.0, 0.0, 0.0], radius, start, end };
|
||||
let outline = [
|
||||
arc([0.0, 0.0], 25.0, PI - theta, 2.0 * PI + theta),
|
||||
line([4.0, y], [4.0, cy]),
|
||||
arc([2.0, cy], 2.0, 0.0, PI / 2.0),
|
||||
line([2.0, cy + 2.0], [-2.0, cy + 2.0]),
|
||||
arc([-2.0, cy], 2.0, PI / 2.0, PI),
|
||||
line([-4.0, cy], [-4.0, y]),
|
||||
];
|
||||
let area = |da: f64, dt: f64| {
|
||||
let (big, rho) = (25.0 - da, 2.0 - dt);
|
||||
let tab = rho * rho * PI + 2.0 * rho * (2.0 + cy) + 4.0 * (cy + rho);
|
||||
let yc = (big * big - (4.0 - dt) * (4.0 - dt)).sqrt();
|
||||
let at = yc.atan2(4.0 - dt);
|
||||
0.5 * (big * big * (PI + 2.0 * at) + tab) + (4.0 - dt) * (cy - yc)
|
||||
};
|
||||
let (r, dphi) = (0.5, (PI / 2.0) / 8192.0);
|
||||
let want: f64 = (0..8192)
|
||||
.map(|i| {
|
||||
let phi = (f64::from(i) + 0.5) * dphi;
|
||||
let d = r * (1.0 - phi.cos());
|
||||
(area(0.0, 0.0) - area(d, d)) * r * phi.cos() * dphi
|
||||
})
|
||||
.sum();
|
||||
let top = [
|
||||
[0.0, -25.0, 2.0],
|
||||
[4.0, 27.8945, 2.0],
|
||||
[3.41421356, 32.5253247, 2.0],
|
||||
[0.0, cy + 2.0, 2.0],
|
||||
[-3.41421356, 32.5253247, 2.0],
|
||||
[-4.0, 27.8945, 2.0],
|
||||
];
|
||||
let plate = extrude(&outline, Z, 2.0, 0.0, DraftCorner::default(), true).unwrap();
|
||||
assert!(rel(volume(&plate, 1e-8).unwrap(), 2.0 * area(0.0, 0.0)) < 1e-10);
|
||||
let round = blend(&plate, Blend::Round, &top, &[r; 6], TOL, &[], &[], Corners::Filled).unwrap();
|
||||
let removed = volume(&plate, 1e-8).unwrap() - volume(&round, 1e-8).unwrap();
|
||||
assert!(rel(removed, want) < 1e-6, "removed {removed}, expected {want}");
|
||||
let (rec, _) = native(&to_arrays(&round).unwrap()).unwrap();
|
||||
rec.validate().unwrap();
|
||||
assert!(super::is_manifold_solid(&round).unwrap());
|
||||
assert!(super::check(&round, crate::check::CheckLevel::All).unwrap().is_valid());
|
||||
#[cfg(feature = "native")]
|
||||
{
|
||||
use crate::{Brep, ffi};
|
||||
crate::init().unwrap();
|
||||
let list = crate::sweeps::List::of(&outline).unwrap();
|
||||
let cpp = ffi::sweeps::extrude(&list.raw(), &Z, 2.0, 0.0, ffi::sweeps::DRAFT_CORNER_CURVATURE, true, &mut [f64::NAN; 3]).unwrap();
|
||||
let cround = ffi::ops::blend(ffi::ops::BLEND_ROUND, Brep::made(cpp).cpp().unwrap(), &top, &[r; 6], TOL).unwrap();
|
||||
let cv = ffi::volume(&cround, 1e-8).unwrap();
|
||||
assert!(rel(volume(&round, 1e-8).unwrap(), cv) < 1e-9);
|
||||
assert_eq!(counts(&round).unwrap(), ffi::counts(&cround).unwrap().map(|x| usize::try_from(x).unwrap()));
|
||||
}
|
||||
}
|
||||
@@ -665,7 +665,7 @@ mod history {
|
||||
|
||||
/// Two overlapping squares combined as regions of one plane.
|
||||
#[test]
|
||||
#[ignore = "solidcore's boolean_2d carries no attributes through its merge (#1462's scope; write-up review-1031/bugs/boolean2d-drops-history.md, not filed yet)"]
|
||||
#[ignore = "solidcore#1462 (PR #1977): boolean_2d carries no attributes through its merge"]
|
||||
fn a_boolean2d_has_the_cpp_history() {
|
||||
let _cpp = crate::route::on_cpp();
|
||||
use crate::sweeps::Curve;
|
||||
@@ -729,3 +729,40 @@ fn object_names_stay_distinct_past_a_million() {
|
||||
assert_eq!(keys.len(), total);
|
||||
assert_ne!(named(EntityRef::Face(FaceId::from_index(1_000_000)), 0).key, named(EntityRef::Loop(LoopId::from_index(0)), 0).key);
|
||||
}
|
||||
|
||||
/// Rig case booleans/2928, reduced (fork c2e3d9d): a ring, r 3..5 about (0, 10), z 0..2, unioned
|
||||
/// with a half annulus prism, r 4..5 about (e, 10), z 2..20, whose cap sits on the ring's top. Two
|
||||
/// equal circles a little apart cross; they do not coincide over a tiny edge. The stack's volume
|
||||
/// is 113 pi whatever e is.
|
||||
/// This path passes with `simple_coincidence_crossing_is_point` off too, so the test holds the
|
||||
/// result here and does not single out that flag (solidcore's own test does).
|
||||
#[test]
|
||||
fn a_ring_and_a_lip_with_walls_nearly_together() {
|
||||
use super::sweep::extrude;
|
||||
use crate::sweeps::Curve;
|
||||
use crate::sweeps::DraftCorner;
|
||||
const Z: [f64; 3] = [0.0, 0.0, 1.0];
|
||||
let up = |p: &[Curve], d| extrude(p, Z, d, 0.0, DraftCorner::default(), true).unwrap();
|
||||
let arc = |c: [f64; 3], radius, start, end| Curve::Arc { center: c, axis: Z, reference: [1.0, 0.0, 0.0], radius, start, end };
|
||||
let disc = |r| up(&[arc([0.0, 10.0, 0.0], r, 0.0, 2.0 * PI)], 2.0);
|
||||
let ring = boolean(&disc(5.0), &disc(3.0), BooleanOp::Subtract).unwrap().unwrap();
|
||||
for e in [0.0, 1e-4, 1e-3, 1e-2] {
|
||||
let c = [e, 10.0, 2.0];
|
||||
let lip = up(
|
||||
&[
|
||||
arc(c, 5.0, 0.0, PI),
|
||||
Curve::Line { start: [e - 5.0, 10.0, 2.0], end: [e - 4.0, 10.0, 2.0] },
|
||||
Curve::Arc { center: c, axis: [0.0, 0.0, -1.0], reference: [-1.0, 0.0, 0.0], radius: 4.0, start: 0.0, end: PI },
|
||||
Curve::Line { start: [e + 4.0, 10.0, 2.0], end: [e + 5.0, 10.0, 2.0] },
|
||||
],
|
||||
18.0,
|
||||
);
|
||||
let u = boolean(&ring, &lip, BooleanOp::Union).unwrap().unwrap();
|
||||
let v = volume(&u, 1e-8).unwrap();
|
||||
let report = super::check(&u, crate::check::CheckLevel::All).unwrap();
|
||||
assert!(report.is_valid(), "e {e}: {report}");
|
||||
assert_eq!(solid_count(&u).unwrap(), 1, "e {e}");
|
||||
assert!(super::is_manifold_solid(&u).unwrap(), "e {e}");
|
||||
assert!((v - 113.0 * PI).abs() < 1e-3, "e {e}: {v}");
|
||||
}
|
||||
}
|
||||
+11
-147
@@ -18,10 +18,9 @@
|
||||
|
||||
use solidcore::EntityRef;
|
||||
use solidcore::SolidError;
|
||||
use solidcore::curve::curve::Curve;
|
||||
use solidcore::geom::attribute::{Attribute, AttributeStore, Behavior, ObjectKey, ids};
|
||||
use solidcore::geom::attribute::{Attribute, Behavior, ids};
|
||||
use solidcore::geom::axis2_placement::Axis2Placement;
|
||||
use solidcore::geom::object::{ObjectRef, Shape};
|
||||
use solidcore::geom::object::Shape;
|
||||
use solidcore::geom::vector3d::{Point3, Vec3};
|
||||
use solidcore::intersect::point_class::PointClassType;
|
||||
use solidcore::kernel::Kernel;
|
||||
@@ -30,23 +29,17 @@ use solidcore::nurbs::b_spline_curve::ControlPointForm;
|
||||
use solidcore::nurbs::b_spline_surface::p1::SurfParamType;
|
||||
use solidcore::nurbs::b_spline_surface_n_lib::p2::OrientType;
|
||||
use solidcore::nurbs::knots::Side;
|
||||
use solidcore::offset::offset_executive::p2::{
|
||||
OffsetNotifications, OffsetOptions, ShellCopyIdentities, ShellOptions, api_offset_brep_full, api_shell_brep_full,
|
||||
};
|
||||
use solidcore::offset::offset_executive::p2::{OffsetOptions, ShellOptions, local_operation_simple, offset_brep_simple, shell_brep_simple};
|
||||
use solidcore::offset::offset_faces::{OffsetFacesExecutive, OffsetFacesRefusal};
|
||||
use solidcore::query::api_queries::{BrepRef, face_bounding_box, face_classify_uv, face_closest_point_in_shape, face_internal_point};
|
||||
use solidcore::query::api_queries::{face_bounding_box, face_classify_uv, face_closest_point_in_shape, face_internal_point};
|
||||
use solidcore::query::brep::{BrepIdentity, BrepQuery, LiveBrepObjects};
|
||||
use solidcore::surface::cone::Cone;
|
||||
use solidcore::surface::surface::{Surface, SurfaceKind};
|
||||
use solidcore::sweep::topology_sweep::store::SweepIdentities;
|
||||
use solidcore::topology::brep::local_operation::local_operation;
|
||||
use solidcore::topology::brep::{p1 as brep_p1, p2 as brep_p2};
|
||||
use solidcore::topology::face::p2 as face_p2;
|
||||
use solidcore::topology::topology::{NotifyRecords, Topology};
|
||||
use solidcore::topology::{Brep, BrepId, EdgeId, FaceId, FaceuseId, RegionId};
|
||||
use solidcore::topology::{Brep, BrepId, FaceId, FaceuseId};
|
||||
|
||||
use super::blend::{Miss, on_copy, p3, pick, points_ok, status as blend_status, tolerance_ok};
|
||||
use super::boolean::{domain, named};
|
||||
use super::{Body, answer};
|
||||
use crate::{Error, Result};
|
||||
|
||||
@@ -279,149 +272,21 @@ fn leaves_cavity(k: &mut Kernel, b: &mut Brep, open: &[FaceId], wall: f64) -> so
|
||||
Ok(false)
|
||||
}
|
||||
|
||||
// Each B-rep the offset executive touches (the source, its working copy, the result, the merge's
|
||||
// bodies) names its objects in its own key domain ([`named`]), as solidcore's offset fixture does,
|
||||
// so their notification records never collide. Curves and lists have domains of their own.
|
||||
const SOURCE: u64 = domain(1);
|
||||
const RESULT: u64 = domain(2);
|
||||
const WORKING: u64 = domain(3);
|
||||
/// The merge's B-rep `brep`: the domains of its objects, its curves and its lists.
|
||||
fn merge_domain(brep: BrepId, which: u64) -> u64 {
|
||||
domain(16 + u64::from(brep.index()) * 3 + which)
|
||||
}
|
||||
|
||||
fn source_key(e: EntityRef) -> ObjectRef {
|
||||
named(e, SOURCE)
|
||||
}
|
||||
|
||||
fn result_key(e: EntityRef) -> ObjectRef {
|
||||
named(e, RESULT)
|
||||
}
|
||||
|
||||
fn working_key(e: EntityRef) -> ObjectRef {
|
||||
named(e, WORKING)
|
||||
}
|
||||
|
||||
fn curve_in(domain: u64, edge: EdgeId, type_code: i64) -> ObjectRef {
|
||||
ObjectRef { key: ObjectKey(domain + u64::from(edge.index())), type_code }
|
||||
}
|
||||
|
||||
fn result_curve(edge: EdgeId, type_code: i64) -> ObjectRef {
|
||||
curve_in(domain(4), edge, type_code)
|
||||
}
|
||||
|
||||
fn source_curve(edge: EdgeId, type_code: i64) -> ObjectRef {
|
||||
curve_in(domain(5), edge, type_code)
|
||||
}
|
||||
|
||||
fn working_curve(edge: EdgeId, type_code: i64) -> ObjectRef {
|
||||
curve_in(domain(6), edge, type_code)
|
||||
}
|
||||
|
||||
fn lists_in(domain: u64, region: RegionId) -> [ObjectRef; 2] {
|
||||
[0, 1].map(|list| ObjectRef { key: ObjectKey(domain + u64::from(region.index()) * 2 + list), type_code: 0 })
|
||||
}
|
||||
|
||||
fn source_lists(result: bool, region: RegionId) -> [ObjectRef; 2] {
|
||||
lists_in(domain(if result { 8 } else { 7 }), region)
|
||||
}
|
||||
|
||||
fn working_lists(region: RegionId) -> [ObjectRef; 2] {
|
||||
lists_in(domain(9), region)
|
||||
}
|
||||
|
||||
fn merge_curve(brep: BrepId, edge: EdgeId, type_code: i64) -> ObjectRef {
|
||||
ObjectRef { key: ObjectKey(merge_domain(brep, 1) + u64::from(edge.index())), type_code }
|
||||
}
|
||||
|
||||
/// Identities of the B-reps the merge makes, disjoint from the keys above.
|
||||
struct MergeBodies;
|
||||
|
||||
impl SweepIdentities for MergeBodies {
|
||||
fn topology(&self, brep: BrepId, entity: EntityRef) -> ObjectRef {
|
||||
named(entity, merge_domain(brep, 0))
|
||||
}
|
||||
fn owned_auxiliary_objects(&self, brep: BrepId, model: &Brep) -> Vec<ObjectKey> {
|
||||
model.edges().iter().filter(|(_, e)| e.curve.is_some()).map(|(edge, _)| merge_curve(brep, edge, 0).key).collect()
|
||||
}
|
||||
fn curve(&self, brep: BrepId, edge: EdgeId, curve: &Curve) -> ObjectRef {
|
||||
merge_curve(brep, edge, curve.type_code())
|
||||
}
|
||||
fn new_curve(&self, brep: BrepId, edge: EdgeId, type_code: i64) -> solidcore::Result<ObjectRef> {
|
||||
Ok(merge_curve(brep, edge, type_code))
|
||||
}
|
||||
fn source_lists(&self, brep: BrepId, region: RegionId) -> solidcore::Result<[ObjectRef; 2]> {
|
||||
Ok(lists_in(merge_domain(brep, 2), region))
|
||||
}
|
||||
}
|
||||
|
||||
/// The notification stores of one offset call on `source` (SM_API's context keeps them for the
|
||||
/// process; each call here has its own).
|
||||
struct Notifications {
|
||||
records: NotifyRecords,
|
||||
attributes: AttributeStore,
|
||||
}
|
||||
|
||||
impl Notifications {
|
||||
/// Registers `source` (B-rep 0 of the source domain), its objects and the reserved result.
|
||||
fn new(source: &mut Brep) -> Notifications {
|
||||
source.set_key(source_key(EntityRef::Brep(ONE)).key);
|
||||
let mut records = NotifyRecords::new();
|
||||
records.insert(source.key(), Topology::new());
|
||||
records.insert(result_key(EntityRef::Brep(ONE)).key, Topology::new());
|
||||
let entities = source
|
||||
.shells()
|
||||
.iter()
|
||||
.map(|(id, _)| EntityRef::Shell(id))
|
||||
.chain(source.faces().iter().map(|(id, _)| EntityRef::Face(id)))
|
||||
.chain(source.faceuses().iter().map(|(id, _)| EntityRef::Faceuse(id)))
|
||||
.chain(source.edges().iter().map(|(id, _)| EntityRef::Edge(id)))
|
||||
.chain(source.edgeuses().iter().map(|(id, _)| EntityRef::Edgeuse(id)))
|
||||
.chain(source.vertices().iter().map(|(id, _)| EntityRef::Vertex(id)))
|
||||
.chain(source.vertexuses().iter().map(|(id, _)| EntityRef::Vertexuse(id)))
|
||||
.chain(source.loopuses().iter().map(|(id, _)| EntityRef::Loopuse(id)))
|
||||
.chain(source.regions().iter().map(|(id, _)| EntityRef::Region(id)));
|
||||
for e in entities {
|
||||
records.insert(source_key(e).key, Topology::new());
|
||||
}
|
||||
Notifications { records, attributes: AttributeStore::default() }
|
||||
}
|
||||
|
||||
fn context(&mut self) -> OffsetNotifications<'_> {
|
||||
OffsetNotifications {
|
||||
records: &mut self.records,
|
||||
attributes: &mut self.attributes,
|
||||
original_key_of: &source_key,
|
||||
result_key_of: &result_key,
|
||||
original_curve_ref: &source_curve,
|
||||
result_curve_ref: &result_curve,
|
||||
boolean_source_lists: &source_lists,
|
||||
result_brep: result_key(EntityRef::Brep(ONE)),
|
||||
merge_identities: Some(&MergeBodies),
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// `SmApiShellBrepFull(b, distance, TRUE, TRUE, TRUE, open, r)`: convex edges extended, results
|
||||
/// merged, side walls made at a sheet's edges, and (as the fork does, 5448b9a) a thickened
|
||||
/// sheet's coplanar side walls one face.
|
||||
fn shell_brep_full(k: &mut Kernel, mut b: Brep, distance: f64, open: &[FaceId]) -> solidcore::Result<Brep> {
|
||||
let mut n = Notifications::new(&mut b);
|
||||
fn shell_brep_full(k: &mut Kernel, b: &Brep, distance: f64, open: &[FaceId]) -> solidcore::Result<Brep> {
|
||||
let options = ShellOptions {
|
||||
offset: OffsetOptions { distance, extend_convex_edges: true, merge_results: true },
|
||||
create_offset_solid: true,
|
||||
merge_sheet_side_walls: true,
|
||||
};
|
||||
let faces: Vec<_> = open.iter().map(|&f| Some((ONE, f))).collect();
|
||||
let copy = ShellCopyIdentities { key_of: &working_key, curve_ref: &working_curve, boolean_source_lists: &working_lists };
|
||||
api_shell_brep_full(k, Some(BrepRef { brep: &b, handle: ONE }), options, &faces, ©, &mut n.context())
|
||||
shell_brep_simple(k, b, options, open)
|
||||
}
|
||||
|
||||
/// `SmApiOffsetBrepFull(b, distance, TRUE, TRUE, r)`.
|
||||
fn offset_brep_full(k: &mut Kernel, b: &mut Brep, distance: f64) -> solidcore::Result<Brep> {
|
||||
let mut n = Notifications::new(b);
|
||||
let options = OffsetOptions { distance, extend_convex_edges: true, merge_results: true };
|
||||
api_offset_brep_full(k, Some(b), options, &mut n.context())
|
||||
offset_brep_simple(k, b, OffsetOptions { distance, extend_convex_edges: true, merge_results: true })
|
||||
}
|
||||
|
||||
/// `finish`: the result must have faces, and a solid input must give a closed manifold solid.
|
||||
@@ -459,7 +324,7 @@ pub(crate) fn shell(body: &Body, points: &[[f64; 3]], tolerance: f64, thickness:
|
||||
if thickness < 0.0 && solid_in && !leaves_cavity(k, &mut w, &picked, -thickness)? {
|
||||
return Ok(Err(Error::NoRoom));
|
||||
}
|
||||
match called(shell_brep_full(k, w, thickness, &picked))? {
|
||||
match called(shell_brep_full(k, &w, thickness, &picked))? {
|
||||
Ok(r) => finish(r, solid_in),
|
||||
Err(e) => Ok(Err(e)),
|
||||
}
|
||||
@@ -528,7 +393,7 @@ pub(crate) fn thicken(body: &Body, thickness: f64, symmetric: bool) -> Result<Bo
|
||||
Err(e) => return Ok(Err(e)),
|
||||
};
|
||||
}
|
||||
match called(shell_brep_full(k, w, thickness, &[]))? {
|
||||
match called(shell_brep_full(k, &w, thickness, &[]))? {
|
||||
Ok(r) => finish(r, true),
|
||||
Err(e) => Ok(Err(e)),
|
||||
}
|
||||
@@ -787,8 +652,7 @@ pub(crate) fn draft(
|
||||
// `moved_faces(b, status(b->LocalOperation(faces, surfaces)))`, its marks on the picked
|
||||
// faces (`mark_moved`).
|
||||
mark_moved(&mut w, &picked)?;
|
||||
let mut notes = Notifications::new(&mut w);
|
||||
if let Err(e) = called(local_operation(k, &mut w, &picked, surfaces, &mut notes.context()))? {
|
||||
if let Err(e) = called(local_operation_simple(k, &mut w, &picked, surfaces))? {
|
||||
return Ok(Err(e));
|
||||
}
|
||||
if !moved_faces(&mut w)? {
|
||||
|
||||
@@ -783,7 +783,7 @@ mod history {
|
||||
}
|
||||
|
||||
#[test]
|
||||
#[ignore = "solidcore's stitch in the shell drops the flat sheet's edge tags (write-up review-1031/bugs/thicken-flat-sheet-edge-tags.md, not filed yet)"]
|
||||
#[ignore = "solidcore#1973 (PR #1977): the stitch in the shell drops the flat sheet's edge tags"]
|
||||
fn tags_cross_a_thicken_of_a_flat_sheet() {
|
||||
let _cpp = crate::route::on_cpp();
|
||||
thicken_parity(false);
|
||||
@@ -827,3 +827,64 @@ mod history {
|
||||
assert_eq!(core.canonical(), cpp.canonical());
|
||||
}
|
||||
}
|
||||
|
||||
/// A stepped block, 40 x 30 x 10 with its half x < 20 raised to 20 (rig case
|
||||
/// shell/cov-replace-face-step-onto-the-higher-face, the fork's `offset_faces_close_a_step_wall`):
|
||||
/// a top moved onto the other's plane closes the step wall between them to nothing, and the tops
|
||||
/// are one face of a 6-faced box.
|
||||
#[test]
|
||||
fn offset_faces_close_a_step_wall() {
|
||||
use super::boolean::boolean;
|
||||
let stepped = boolean(&make_box([0.0; 3], [40.0, 30.0, 10.0]).unwrap(), &make_box([0.0; 3], [20.0, 30.0, 20.0]).unwrap(), BooleanOp::Union)
|
||||
.unwrap()
|
||||
.unwrap();
|
||||
assert_eq!(counts(&stepped).unwrap()[0], 8);
|
||||
for (at, d, v, a) in [([30.0, 15.0, 10.0], 10.0, 24000.0, 5200.0), ([10.0, 15.0, 20.0], -10.0, 12000.0, 3800.0)] {
|
||||
let r = offset_faces(&stepped, &[at], 0.1, d).unwrap();
|
||||
let (got, n, area) = (volume(&r, 1e-8).unwrap(), counts(&r).unwrap(), super::area(&r, 1e-8).unwrap());
|
||||
assert_eq!(n[0], 6, "d {d}");
|
||||
assert!(rel(got, v) < 1e-9 && rel(area, a) < 1e-9, "d {d}: V {got} A {area}");
|
||||
}
|
||||
}
|
||||
|
||||
/// Rig case shell/4492's rounded box: four mitred rounds, r 3, come off a 40 x 30 x 10 box's top
|
||||
/// together and follow it. From height 0 the outline is the 34 x 24 top moved out by the round's
|
||||
/// w(z) = sqrt(9 - (z - axis)^2), or 3 below the axis. With the fork's values at +19, and a body
|
||||
/// whose rounds go all the way down at -7. With SMLib built, the C++ kernel gives the same.
|
||||
#[test]
|
||||
fn mitred_rounds_follow_a_moved_top() {
|
||||
use super::blend::{Corners, blend};
|
||||
use crate::Blend;
|
||||
let edges = [[20.0, 0.0, 10.0], [20.0, 30.0, 10.0], [0.0, 15.0, 10.0], [40.0, 15.0, 10.0]];
|
||||
let top = [20.0, 15.0, 10.0];
|
||||
let rounded = blend(&make_box([0.0; 3], [40.0, 30.0, 10.0]).unwrap(), Blend::Round, &edges, &[3.0; 4], TOL, &[], &[], Corners::Filled).unwrap();
|
||||
let analytic = |d: f64| {
|
||||
let (height, axis, n) = (10.0 + d, 7.0 + d, 20000);
|
||||
(0..n)
|
||||
.map(|i| {
|
||||
let z = height * (f64::from(i) + 0.5) / f64::from(n);
|
||||
let w = if z < axis { 3.0 } else { (9.0 - (z - axis) * (z - axis)).max(0.0).sqrt() };
|
||||
(34.0 + 2.0 * w) * (24.0 + 2.0 * w) * height / f64::from(n)
|
||||
})
|
||||
.sum::<f64>()
|
||||
};
|
||||
let moves = [(19.0, [10, 20, 12]), (1.0, [10, 20, 12]), (-1.0, [10, 20, 12]), (-6.9, [10, 20, 12]), (-7.0, [6, 12, 8])];
|
||||
for (d, n) in moves {
|
||||
let moved = offset_faces(&rounded, &[top], 0.1, d).unwrap();
|
||||
let v = volume(&moved, 1e-8).unwrap();
|
||||
assert_eq!(counts(&moved).unwrap(), n, "d {d}");
|
||||
assert!(rel(v, analytic(d)) < 1e-6, "d {d}: {v} vs {}", analytic(d));
|
||||
}
|
||||
#[cfg(feature = "native")]
|
||||
{
|
||||
use crate::ffi;
|
||||
crate::init().unwrap();
|
||||
let b = ffi::make_box(&[0.0; 3], &[40.0, 30.0, 10.0]).unwrap();
|
||||
let round = ffi::ops::blend(ffi::ops::BLEND_ROUND, &b, &edges, &[3.0; 4], TOL).unwrap();
|
||||
for (d, _) in moves {
|
||||
let cpp = ffi::ops::pick_op(ffi::ops::Pick::OffsetFaces, &round, &[top], 0.1, d).unwrap();
|
||||
let ours = offset_faces(&rounded, &[top], 0.1, d).unwrap();
|
||||
assert!(rel(volume(&ours, 1e-8).unwrap(), ffi::volume(&cpp, 1e-8).unwrap()) < 1e-9, "d {d}");
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -99,13 +99,13 @@ pub const MAX_CURVES: usize = ffi::sweeps::CURVE_MAX_CURVES;
|
||||
|
||||
/// The curves as the C API's curve list.
|
||||
#[derive(Default)]
|
||||
struct List {
|
||||
pub(crate) struct List {
|
||||
kinds: Vec<i64>,
|
||||
reals: Vec<f64>,
|
||||
}
|
||||
|
||||
impl List {
|
||||
fn of<'a>(curves: impl IntoIterator<Item = &'a Curve>) -> Result<List> {
|
||||
pub(crate) fn of<'a>(curves: impl IntoIterator<Item = &'a Curve>) -> Result<List> {
|
||||
let mut l = List::default();
|
||||
for c in curves {
|
||||
l.push(c)?;
|
||||
@@ -150,7 +150,7 @@ impl List {
|
||||
Ok(())
|
||||
}
|
||||
|
||||
fn raw(&self) -> ffi::sweeps::List<'_> {
|
||||
pub(crate) fn raw(&self) -> ffi::sweeps::List<'_> {
|
||||
ffi::sweeps::List::new(&self.kinds, &self.reals)
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user