Skip to content
Merged
1 change: 0 additions & 1 deletion crates/smlib/src/core.rs
Original file line number Diff line number Diff line change
Expand Up @@ -135,7 +135,6 @@ pub(crate) fn fixes() -> UpstreamFixes {
f.analytic_inversion_answers_apart = true;
f.fillet_statuses_pass_on = true;
f.fillet_rail_trim_at_near_knot = true;
f.offset_keep_cavity_regions = true;
f.corner_patch_face_side_twist = true;
f.boolean_union_refuses_solid_leak = true;
f.validation_does_not_make_uv_trims = true;
Expand Down
2 changes: 0 additions & 2 deletions solidcore/crates/solidcore/src/kernel.rs
Original file line number Diff line number Diff line change
Expand Up @@ -617,8 +617,6 @@ pub struct UpstreamFixes {
pub edgeuse_convexity_propagates_step_off_failure: bool,
/// `SmBrep::LocalOperation` sizes the offset executive's distance (by which it extends the neighbouring surfaces to meet the moved ones) from a box that also holds the replacement surfaces, not from the original body alone, so a face moved further than about the body's size away is still reached (WR-534; the fork's tangency-labs/smlib@a1ee273).
pub local_operation_box_holds_new_surfaces: bool,
/// An inset's `do_extended_offset` makes manifold only the finite regions of the merged offset that are cavity, not every finite region (upstream's own TODO there: "we will need to select regions to keep"): a region is cavity where one of its faces has the body's face the wall's thickness behind it and none has the body's face that far ahead. Where a floor is no thicker than the wall its two faces' offsets cross and the merge closes the region between them; kept, the cavity was no manifold solid and the shell failed with `SM_ERR` (1001) (WR-667; the fork's tangency-labs/smlib@37af643).
pub offset_keep_cavity_regions: bool,
/// In a local operation (`SmBrep::LocalOperation`), `SmOffsetGeometryCreation::ExtendTrimEdges` fails a tangent or lamina edge whose lift onto one face's new surface drops onto the other's farther than ten times `max(the offset edge's tolerance, the approximation tolerance)`, and `EdgeuseOffset` passes that failure on, so the operation is refused; upstream ignores it ("will be fixed later", which no later step of a local operation does) and returns a body with an edge as loose as the gap between a moved face and its unmoved tangent neighbour (WR-530, #402; the fork's tangency-labs/smlib@23c5b0a). Offsets and shells are unchanged.
pub local_operation_refuses_loose_tangent_edges: bool,
/// A local operation that moves one of two tangent faces along its normal builds the step: `EdgeuseOffset` finds the two faces parallel but apart across the edge (`IsStepAcrossEdge`) and builds the ruled wall between their edges (`CreateStepWall`, rails of uniform weight made non-rational), kept out of the face extensions; `CloseLoopGaps` closes the gaps the wall leaves at its ends and the edges running past its corners are split; a vertex moved past an edge's other end is `SM_ERR_OFFSET_EDGE_VANISHES` (1043) (WR-530 addendum; tangency-labs/smlib 5d428ae, 90aabff, 34318f4).
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,10 @@
//! |-----------------------------|-----------------------|
//! | `is_cavity_region` (crate) | `sm_IsCavityRegion` |
//!
//! Deviations: opt-in (`Kernel::fixes.offset_keep_cavity_regions`, read by
//! `do_extended_offset`). The body's `BrepPointSolve` runs on one point-solve cache of the
//! body made by the caller (`p1`'s original-body solve, as `RemoveExcessFaces` uses it);
//! Deviations: `do_extended_offset` asks only when the merge left two or more finite
//! regions (with one there is nothing to select). The body's `BrepPointSolve` runs on
//! one point-solve cache of the body made by the caller (`p1`'s original-body solve, as
//! `RemoveExcessFaces` uses it);
//! a failed internal point, point solve or normal skips the face as the fork does, but an
//! unported dependency still propagates. No recursion.
Expand Down
40 changes: 24 additions & 16 deletions solidcore/crates/solidcore/src/offset/offset_executive/p2.rs
Original file line number Diff line number Diff line change
Expand Up @@ -1158,25 +1158,33 @@ impl OffsetExecutive {
// WR-455 (#855; tangency-labs/smlib@601d804): [`stitch_merged_offset`].
let to_be_solid = self.create_offset_solid() || brep_is_manifold_solid(original)?;
stitch_merged_offset(kernel, &mut result, to_be_solid)?;
// Opt-in (WR-667; tangency-labs/smlib@37af643): an inset keeps the regions
// that are cavity, not every finite region (upstream's TODO here: "we will
// need to select regions to keep"). Where the body is no thicker than the
// wall, the offsets of a floor's two faces cross and the merge closes the
// region between them, touching the cavity's pieces along edges; kept, the
// cavity was no manifold solid and the shell failed (1001). (SER.)
// WR-667 (tangency-labs/smlib@37af643): an inset keeps the regions that are
// cavity, not every finite region (upstream's TODO here: "we will need to
// select regions to keep"). Where the body is no thicker than the wall, the
// offsets of a floor's two faces cross and the merge closes the region
// between them, touching the cavity's pieces along edges; kept, the cavity
// was no manifold solid and the shell failed (1001). (SER.)
//
// Only a choice between two or more finite regions can select anything: with
// one, `make_manifold` keeps it whether it is cavity or not (a lone cavity
// region is every region; a lone other region leaves no cavity to keep), so
// the body's point solves are not run for it, nor the live classification
// whose trims, caches and tolerance growth they would leave on `result`.
let mut cavities = Vec::new();
let mut select = false;
if kernel.fixes.offset_keep_cavity_regions
&& self.inset()
&& self.operation() == OffsetOperation::SolidOffset
{
let infinite = result.infinite_region();
let regions = bp1::regions(&result, None)?;
let finite: Vec<RegionId> =
if self.inset() && self.operation() == OffsetOperation::SolidOffset {
let infinite = result.infinite_region();
bp1::regions(&result, None)?
.into_iter()
.filter(|&region| Some(region) != infinite)
.collect()
} else {
Vec::new()
};
if finite.len() > 1 {
let mut body_cache = None;
for region in regions {
if Some(region) == infinite {
continue;
}
for region in finite {
if body_cache.is_none() {
body_cache = Some(super::p1::make_original_brep_cache(kernel, original)?);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
//! Fork tangency-labs/smlib@37af643 under `Kernel::fixes.offset_keep_cavity_regions`
//! (WR-667): an inset keeps the regions that are cavity, not every finite region.
//! Fork tangency-labs/smlib@37af643 (WR-667), the kernel's default: an inset keeps the
//! regions that are cavity, not every finite region.
//!
//! SolidCraft rig case shell/545's frame, rebuilt from the commit message: a 20 x 20 x 5
//! block with a recess from the top ((5, 5)..(15, 15), z 3..5) and a square ring cut from
Expand All @@ -8,7 +8,7 @@
//! edges, merged) open at the ring cut's outer wall x = 18: the floor is no thicker than
//! the wall, its two faces' offsets cross, and the merge closes the region between them.
//! Upstream's `MakeManifold` keeps every finite region ("we will need to select regions
//! to keep"), so the result is no manifold solid. With the flag only the cavity is kept.
//! to keep"), so the result is no manifold solid. The kernel keeps only the cavity.
//!
//! Closed form (sharp offsets, the open face's neighbours' walls ending at its plane):
//! the cavity is z 0.5..2.5 over the core (7.5..12.5)^2 and the outer band
Expand All @@ -27,16 +27,14 @@ mod offset_fixture;

use offset_fixture::{planar_faces_at, volume, Notifications};
use solidcore::boolean::api_brep::boolean_difference;
use solidcore::error::offset::{OffsetFailure, Unsoundness};
use solidcore::error::Reason;
use solidcore::kernel::UpstreamFixes;
use solidcore::math::Point3;
use solidcore::offset::offset_executive::p1::OffsetExecutive;
use solidcore::offset::offset_executive::p2::{OffsetOptions, ShellOptions};
use solidcore::primitive::api_primitives::create_box;
use solidcore::query::api_queries::brep_is_manifold_solid;
use solidcore::topology::brep::validation::{check_brep, CheckLevel};
use solidcore::{Brep, Kernel, SolidError};
use solidcore::{Brep, Kernel};

/// The frame, the ring cut's top at `ring_top` (2.5: a 0.5 floor under the recess).
fn frame(k: &mut Kernel, ring_top: f64) -> Brep {
Expand Down Expand Up @@ -94,108 +92,28 @@ fn shell(fixes: &UpstreamFixes, ring_top: f64) -> (bool, f64) {
(manifold, volume(&k, &mut wall).unwrap())
}

fn keep_cavity() -> UpstreamFixes {
let mut f = UpstreamFixes::default();
f.offset_keep_cavity_regions = true;
f
}

/// With cavity selection off, the sliver between the crossing offsets leaves no
/// manifold cavity. The shell refuses it with `OffsetFailure::Unsound` and retains
/// the original frame.
/// Only the cavity is made manifold; the shell is the closed form and passes `check_brep`
/// at every level.
#[test]
fn flag_off_refuses_the_sliver_and_retains_the_input() {
let mut k = Kernel::default();
let mut part = frame(&mut k, 2.5);
part.refresh_cached_topology();
let open = planar_faces_at(&k, &part, 0, 18.0);
assert_eq!(open.len(), 1);
let mut notifications = Notifications::new(&mut part);
let key = part.key();
let tolerance = part.tolerance();
let ids = (
part.face_list().to_vec(),
part.edge_list().to_vec(),
part.vertex_list().to_vec(),
);
let points: Vec<_> = part
.vertices()
.iter()
.map(|(id, v)| (id, v.point, v.tolerance))
.collect();
let outcome = OffsetExecutive::shell_brep(
&mut k,
part,
shell_options(),
&open,
&mut notifications.context(),
);
let error = outcome.result.as_ref().unwrap_err();
let SolidError::Failed(failure) = error else {
panic!("not a refusal: {error}");
};
assert_eq!(
failure.reason,
Reason::Offset(OffsetFailure::Unsound {
what: Unsoundness::NotManifoldSolid
})
);
assert!(!outcome.input_ownership_transferred());
let mut retained = outcome.retained_input.unwrap();
assert_eq!(retained.key(), key);
assert_eq!(retained.tolerance(), tolerance);
assert_eq!(
(
retained.face_list().to_vec(),
retained.edge_list().to_vec(),
retained.vertex_list().to_vec()
),
ids
);
assert_eq!(
retained
.vertices()
.iter()
.map(|(id, v)| (id, v.point, v.tolerance))
.collect::<Vec<_>>(),
points
);
// Check the returned caches as-is, without refreshing away an inconsistency.
assert!(solidcore::topology::integrity::check(&retained).is_ok());
assert!(brep_is_manifold_solid(&retained).unwrap());
fn keeps_only_the_cavity() {
let (mut k, wall) = shell_result(&UpstreamFixes::default(), 2.5);
let mut wall = wall.unwrap();
for level in [CheckLevel::Level0, CheckLevel::Level1, CheckLevel::Level2] {
let checked = check_brep(&mut k, &mut retained, level).unwrap();
let checked = check_brep(&mut k, &mut wall, level).unwrap();
assert!(checked.is_valid(), "{level:?}: {:?}", checked.lines());
}
let v = volume(&k, &mut retained).unwrap();
// Block 2000, less the recess 200 and square ring (256 - 36) * 2.5 = 550.
assert!((v - 1250.0).abs() <= 1e-9 * 1250.0, "{v}");
}

/// The flag: only the cavity is made manifold; the shell is the closed form.
#[test]
fn flag_on_keeps_only_the_cavity() {
let (manifold, v) = shell(&keep_cavity(), 2.5);
let (manifold, v) = shell(&UpstreamFixes::default(), 2.5);
assert!(manifold);
assert!((v - 638.75).abs() <= 1e-9 * 638.75, "{v}");
}

/// The offset fixes SolidCraft ran with on this path (WR-345's crossing loops, WR-455's
/// stitch) are the default now: with the flag the shell is the same.
/// Control: a 1.0 floor (ring top at 2) has no crossing offsets and one finite region, so
/// there is nothing to select. Closed form as above: the body is 2000 - 200 - 220 x 2 =
/// 1360; the cavity is z 0.5..2.5 over the core and the band ((25 + 80.5) x 2: 211) and
/// z 2.5..4.5 over (0.5..19.5)^2 less the recess walls (240 x 2: 480), 691; a shell of 669.
#[test]
fn flag_on_with_offset_fixes() {
let fixes = keep_cavity();
let (manifold, v) = shell(&fixes, 2.5);
fn thicker_floor_is_the_closed_form() {
let (manifold, v) = shell(&UpstreamFixes::default(), 2.0);
assert!(manifold);
assert!((v - 638.75).abs() <= 1e-9 * 638.75, "{v}");
}

/// Control: a 1.0 floor (ring top at 2) has no crossing offsets, one finite region, and
/// shells the same with the flag off and on.
#[test]
fn thicker_floor_is_unchanged() {
let off = shell(&UpstreamFixes::default(), 2.0);
let on = shell(&keep_cavity(), 2.0);
assert!(off.0 && on.0);
assert_eq!(off.1.to_bits(), on.1.to_bits());
assert!((v - 669.0).abs() <= 1e-9 * 669.0, "{v}");
}
28 changes: 27 additions & 1 deletion solidcore/crates/solidcore/tests/issue_1476_swept_bar_shell.rs
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,7 @@ use solidcore::offset::offset_executive::p2::{OffsetOptions, ShellOptions};
use solidcore::query::api_queries::brep_is_manifold_solid;
use solidcore::topology::brep::p10::TopologyEnv;
use solidcore::topology::brep::p7::read_from_file;
use solidcore::topology::brep::validation::{check_brep, CheckLevel};
use solidcore::topology::database_io::FileType;
use solidcore::topology::topology::NotifyRecords;
use solidcore::{Brep, Kernel};
Expand Down Expand Up @@ -104,10 +105,22 @@ fn shell(fixes: &UpstreamFixes) -> (Kernel, solidcore::Result<Brep>) {

/// Checks the shell and returns its number of line edges.
fn check(fixes: &UpstreamFixes, want: Option<f64>) -> usize {
let (k, result) = shell(fixes);
check_validated(fixes, want, false)
}

/// [`check`]; with `validate`, the shell also passes `check_brep` at every level
/// (`Level2` runs every test, SolidCraft's `CheckLevel::All`).
fn check_validated(fixes: &UpstreamFixes, want: Option<f64>, validate: bool) -> usize {
let (mut k, result) = shell(fixes);
let mut b = result.unwrap();
b.refresh_cached_topology();
assert!(brep_is_manifold_solid(&b).unwrap());
if validate {
for level in [CheckLevel::Level0, CheckLevel::Level1, CheckLevel::Level2] {
let checked = check_brep(&mut k, &mut b, level).unwrap();
assert!(checked.is_valid(), "{level:?}: {:?}", checked.lines());
}
}
let v = volume(&k, &mut b).unwrap();
let kinds: Vec<&str> = b
.edge_list()
Expand Down Expand Up @@ -137,11 +150,24 @@ fn check(fixes: &UpstreamFixes, want: Option<f64>) -> usize {
kinds.iter().filter(|&&k| k == "line").count()
}

/// The default kernel, which keeps an inset's cavity regions (WR-667). The merge leaves one
/// finite region (deduced: before #17064 the one-name fixture shelled with this selection, which
/// the verdicts' point-solve cache would have refused), which `make_manifold` keeps whatever its cavity
/// verdict, so the verdict's point solves over the operand are not run (#17393).
#[test]
fn issue_1476_swept_bar_shells() {
assert_eq!(check(&UpstreamFixes::default(), None), 16);
}

/// SolidCraft's configuration (which also keeps an inset's cavity regions, now the
/// default): the shell is the closed form and passes `check_brep` at every level. Slow in
/// debug builds, as below.
#[test]
#[ignore = "slow in debug builds (two 38 000-sample curve offsets)"]
fn issue_1476_swept_bar_shells_with_solidcraft_fixes_validates() {
assert_eq!(check_validated(&solidcraft_fixes(), None, true), 16);
}

/// About 6 s at opt-level 3 but over 4 min in a debug build (the two 38 000-sample
/// offsets' knot removal): run with `--ignored` (`--profile difftest`). The default
/// test above keeps the extrusion fix live; `nurbs::crv_offset`'s unit tests keep the
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -94,7 +94,6 @@ const SOLIDCRAFT_C494A18: &[&str] = &[
"offset_edges_keep_source_tolerance",
"offset_extension_as_itself",
"offset_extension_from_base",
"offset_keep_cavity_regions",
"offset_open_edge_second_trim_point",
"point_class_gap_3d_propagates_no_drop_error",
"point_on_start_point_squared_tolerance",
Expand Down
1 change: 0 additions & 1 deletion solidcore/crates/solidcore/tests/kernel_cases/fixes.json
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
"validation_does_not_make_uv_trims",
"edgeuse_convexity_propagates_step_off_failure",
"local_operation_box_holds_new_surfaces",
"offset_keep_cavity_regions",
"local_operation_refuses_loose_tangent_edges",
"local_operation_step_walls",
"revolution_round_offset_collapses",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,10 @@
//! fillet's surface of revolution of an arc; moved in past its radius it has no offset,
//! as a torus's, and the floor's and side's offsets meet across it in a circle. Upstream's
//! `SmSurfOfRevolution` never collapses, and its offset builds the arc turned inside out
//! (r 0.1 or 0.5 round its centre): the shell fails with 1001 open at the rounded end's
//! other side, and is 0.85% and 4.2% low open at the rounded end.
//! (r 0.1 or 0.5 round its centre): upstream's shell fails with 1001 open at the rounded
//! end's other side, and is 0.85% and 4.2% low open at the rounded end. Without the
//! collapse test the kernel's cavity selection (WR-667) still gives the closed form open
//! at the other end.
//!
//! Expected: the cavity is the cylinder r 15 - t, 5 - t deep; the round takes
//! r^2 (1 - pi/4) from the disc's section, its centroid r (10 - 3 pi) / (3 (4 - pi)) in
Expand All @@ -27,6 +29,7 @@ use solidcore::blend::fillet_executive::api::fillet_edges;
use solidcore::kernel::UpstreamFixes;
use solidcore::math::Point3;
use solidcore::primitive::api_primitives::create_cylinder;
use solidcore::topology::brep::validation::{check_brep, CheckLevel};
use solidcore::{Brep, Kernel};

const RD: f64 = 15.0;
Expand Down Expand Up @@ -87,11 +90,24 @@ fn shelled(k: &mut Kernel, edge_z: f64, open_z: f64, t: f64) -> bool {
)
}

/// Without the revolution's collapse test the round's offset is the arc turned inside out
/// (upstream), and the shell failed with 1001 open at the other end while the inset kept
/// every finite region. Keeping only the cavity regions (WR-667) gives the closed form, a
/// shell valid at every `check_brep` level. (Deduced, not checked: with fewer than two
/// finite regions the selection is skipped, so the result would not have changed; this
/// merge leaves at least two.)
#[test]
fn wr567_default_fails_open_at_the_other_end() {
// upstream: the round's offset is the arc turned inside out
fn wr567_without_collapse_open_at_the_other_end_keeps_the_cavity() {
let mut k = kernel(false);
assert!(!shelled(&mut k, -H, 0.0, 1.6));
assert!(shelled(&mut k, -H, 0.0, 1.6));
let b = rounded_disc(&mut k, -H);
let open = planar_faces_at(&k, &b, 2, 0.0);
let mut result = shell(&mut k, b, -1.6, &open).unwrap();
result.refresh_cached_topology();
for level in [CheckLevel::Level0, CheckLevel::Level1, CheckLevel::Level2] {
let checked = check_brep(&mut k, &mut result, level).unwrap();
assert!(checked.is_valid(), "{level:?}: {:?}", checked.lines());
}
}

#[test]
Expand Down
Loading
Loading