test: failing regression test for #261: Rectangular pattern of a hole cut scales super-linearly (#276)
* test: reproduce #261 (Rectangular pattern of a hole cut scales super-linearly) * Patterns of many hole cuts scale near-linearly (#261) Two quadratic costs: - Meshing a face tested every point against every segment of every boundary loop, so a plate face with hundreds of holes meshed in quadratic time. The vendored truck-meshalgo inside test now skips loops whose parameter box is clear of the point (they wind zero times around it). - A pattern cut each copy in turn, rebuilding and re-checking an ever more complex target per copy. Copies whose boxes are clear of each other are now one tool of many pieces (kernel::union_apart, no intersection work), cut once. 512 holes now take ~7 s instead of not finishing. The test's volume tolerance is widened from 1e-6 relative to 0.1 % of each hole: the measure meshes the bores and reads each hole ~0.06 % small, on main too. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Hole-pattern test: a budget CI can meet; coarser apart-box meshes (#261) CI runs every test binary at once and is about ten times slower than a machine running this test alone (15 tests passed 60 s in the last run), so the 512-hole pattern (about 6 s alone) hit the 60 s timeout there. The budget now only has to tell linear from the quadratic hang: 300 s timeout, 120 s budget. union_apart meshes each copy coarsely (2 % of its size, box grown by twice that). Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> * Hole-pattern test checks the scaling, not a wall-clock time (#261) CI runs every test binary at once: the 512-hole pattern (about 6 s alone, 10 s CPU single-threaded) took 177 s there, so no fixed time is reliable. The test now patterns 128 and then 512 holes and requires the second to take under 8x the first (linear is 4x, measured 3.5-4.2x here; the old quadratic cost was 16x or more), each with the volume check and a 900 s hang guard. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com> --------- Co-authored-by: bherbruck <brennen.herbruck@gmail.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
6 files changed
+109
-4
No files matched your search
@@ -75,7 +75,7 @@ pub use measure::{BodyMeasure, measure};
|
||||
pub use mesh_convert::convert_prismatic_mesh;
|
||||
pub use meshbody::{MAX_TRIANGLES, mesh_body};
|
||||
pub use offset::with_same_surface;
|
||||
pub use ops::{BoolOp, boolean, can_join_touching_faces, split_by_plane, transform, transform_matrix};
|
||||
pub use ops::{BoolOp, boolean, can_join_touching_faces, split_by_plane, transform, transform_matrix, union_apart};
|
||||
pub use polybool::{faceted_boolean, planar_boolean};
|
||||
pub use polyhedron::{HalfSpace, convex_polyhedron, draft, offset_faces, shell};
|
||||
pub use prism::{extrude_planar_regions, planar_regions_boolean};
|
||||
|
||||
@@ -588,6 +588,43 @@ fn by_lumps(la: Vec<Body>, lb: Vec<Body>, op: BoolOp) -> Result<Option<Body>> {
|
||||
join_pieces(out)
|
||||
}
|
||||
|
||||
/// Bodies whose bounding boxes are clearly apart, as one body of several pieces, without any
|
||||
/// intersection work (many identical pattern tools, #261). `None` when any two may meet, or a
|
||||
/// body is a mesh: the caller unions those the usual way.
|
||||
pub fn union_apart(bodies: &[Body]) -> Result<Option<Body>> {
|
||||
if bodies.len() < 2 || bodies.len() > 10_000 || bodies.iter().any(Body::is_mesh) {
|
||||
return Ok(None);
|
||||
}
|
||||
let mut boxes = Vec::with_capacity(bodies.len());
|
||||
for b in bodies {
|
||||
// A coarse mesh is enough: the chord tolerance bounds how far the true surface lies
|
||||
// outside it, and the box grows by twice that.
|
||||
let tol = (b.size() * 0.02).max(1e-3);
|
||||
let bb = b.tessellate(tol)?.bounds();
|
||||
if bb.is_empty() {
|
||||
return Ok(None);
|
||||
}
|
||||
let pad = Vec3::new(1.0, 1.0, 1.0) * (2.0 * tol);
|
||||
boxes.push(solvecraft_geom::Aabb3 { min: bb.min - pad, max: bb.max + pad });
|
||||
}
|
||||
// Sweep along x: only boxes whose x ranges overlap are compared.
|
||||
let mut order: Vec<usize> = (0..boxes.len()).collect();
|
||||
order.sort_by(|&i, &j| boxes.get(i).map(|b| b.min.x).unwrap_or(0.0).total_cmp(&boxes.get(j).map(|b| b.min.x).unwrap_or(0.0)));
|
||||
for (k, &i) in order.iter().enumerate() {
|
||||
let Some(a) = boxes.get(i) else { continue };
|
||||
for &j in order.iter().skip(k + 1) {
|
||||
let Some(b) = boxes.get(j) else { continue };
|
||||
if b.min.x > a.max.x {
|
||||
break;
|
||||
}
|
||||
if a.min.y <= b.max.y && b.min.y <= a.max.y && a.min.z <= b.max.z && b.min.z <= a.max.z {
|
||||
return Ok(None);
|
||||
}
|
||||
}
|
||||
}
|
||||
join_pieces(bodies.to_vec())
|
||||
}
|
||||
|
||||
/// Bodies (apart from each other) as one body of several pieces.
|
||||
pub(crate) fn join_pieces(pieces: Vec<Body>) -> Result<Option<Body>> {
|
||||
match pieces.len() {
|
||||
|
||||
Reference in new issue
Block a user