Skip to content

SolidCraft: an open-source parametric 3D CAD application built in pure Rust. Desktop, web, and automation through MCP.

Sketch: a group too large to solve says so, not "conflicts with" nothing (#5280) (#5347)

dudedagger427e24f0e35a5c
diff --git a/crates/engine/src/cmd/sketch_pattern_tests.rs b/crates/engine/src/cmd/sketch_pattern_tests.rs
index ef4e66f66d..a4017c372f 100644
--- a/crates/engine/src/cmd/sketch_pattern_tests.rs
+++ b/crates/engine/src/cmd/sketch_pattern_tests.rs
@@ -656,3 +656,25 @@ fn circular_quantity_changes_keep_partial_full_centered_and_reversed_placements(
}
}
}
+
+/// #5280: a pattern joins its copies into one group of unknowns, and a group larger than the
+/// solver takes is refused saying so, not as an over-constraint with no constraint named.
+#[test]
+fn a_pattern_too_large_to_solve_says_why() {
+ let hexagon = |s: &mut Session| {
+ let r = run(s, "sketch.polygon.inscribed", json!({"center": [0, 0], "radius": 2.5, "sides": 6}));
+ ids(&r["curves"])
+ };
+ // 15 × 22 hexagons: inside the limit.
+ let mut s = new_sketch();
+ let lines = hexagon(&mut s);
+ run(&mut s, "sketch.pattern.rectangular", json!({"entities": lines, "count": 15, "spacing": 6.5, "count2": 22, "spacing2": 6.5}));
+ // 17 × 20: past it.
+ let mut s = new_sketch();
+ let lines = hexagon(&mut s);
+ let e = s
+ .execute("sketch.pattern.rectangular", &json!({"entities": lines, "count": 17, "spacing": 6.5, "count2": 20, "spacing2": 6.5}))
+ .unwrap_err()
+ .to_string();
+ assert!(e.contains("unknowns") && e.contains(&solidcraft_sketch::MAX_COMPONENT_VARS.to_string()) && !e.contains("conflicts with"), "{e}");
+}
diff --git a/crates/sketch/src/lib.rs b/crates/sketch/src/lib.rs
index 08c7748378..92599f0978 100644
--- a/crates/sketch/src/lib.rs
+++ b/crates/sketch/src/lib.rs
@@ -66,8 +66,8 @@ pub use profiles::{
pub use shape::{Shape, intersections, intersections_within};
pub use solver::solve_after_edit_with_analysis;
pub use solver::{
- Analysis, CONSISTENT, DrivingValues, Hold, SolveReport, SolveStatus, constraint_residual, determined_by, measure_dimension, move_line_towards,
- move_point_towards, solve, solve_after_edit, solve_after_value_edit, solve_holding, solve_with,
+ Analysis, CONSISTENT, DrivingValues, Hold, MAX_COMPONENT_VARS, SolveReport, SolveStatus, constraint_residual, determined_by, measure_dimension,
+ move_line_towards, move_point_towards, solve, solve_after_edit, solve_after_value_edit, solve_holding, solve_with,
};
pub use text::{MAX_TEXT_CHARS, TextAlign, TextStyle, text_geometry, text_geometry_in, text_geometry_styled};
pub use thin::{MAX_THIN_SEGMENTS, thin_wall_regions};
diff --git a/crates/sketch/src/solver.rs b/crates/sketch/src/solver.rs
index de296c1b3d..51954460c0 100644
--- a/crates/sketch/src/solver.rs
+++ b/crates/sketch/src/solver.rs
@@ -37,7 +37,7 @@ const MAX_ITERS: usize = 500;
/// 128 MB matrix; past that the request grows to gigabytes and an allocation failure aborts the
/// process, which no panic guard can intercept. A component this size is reported as failed and
/// its geometry left alone.
-const MAX_COMPONENT_VARS: usize = 4_000;
+pub const MAX_COMPONENT_VARS: usize = 4_000;
/// Converged when every residual is below this (mm).
const TOL: f64 = 1e-9;
/// A solution is accepted when every residual is below this (mm).
@@ -84,6 +84,10 @@ pub struct SolveReport {
/// analysis, and only for components of at most a few hundred variables.
#[serde(default)]
pub redundant: Vec<String>,
+ /// The unknowns of the largest connected group too large to solve ([`MAX_COMPONENT_VARS`]):
+ /// the solve fails without a conflicting constraint to name (#5280).
+ #[serde(default)]
+ pub oversized: Option<usize>,
}
impl SolveReport {
@@ -100,6 +104,11 @@ impl SolveReport {
/// Why a solve failed or turned over: the constraints whose orientation the edit flips,
/// or else `conflict` of the constraints still violated (listed, comma-separated).
pub fn failure(&self, conflict: impl FnOnce(&str) -> String) -> String {
+ if let Some(n) = self.oversized {
+ return format!(
+ "the sketch joins {n} unknowns (point coordinates and radii) in one connected group, more than the {MAX_COMPONENT_VARS} the solver takes at once; a pattern joins all its copies: make fewer copies, or split them over several patterns or sketches"
+ );
+ }
if self.folded.is_empty() {
conflict(&self.failing.join(", "))
} else {
@@ -2198,7 +2207,8 @@ fn solve_inner(
let mut rank = 0;
let mut redundant: Vec<String> = Vec::new();
// A component too large to solve is a failure, not an allocation.
- if comps.iter().any(|(_, vars, bis)| !bis.is_empty() && oversized(vars)) {
+ let too_large = comps.iter().filter(|(_, vars, bis)| !bis.is_empty() && oversized(vars)).map(|(_, vars, _)| vars.len()).max();
+ if too_large.is_some() {
max_residual = f64::MAX;
}
let mut check = |r: &[f64], owner: &[usize], blocks: &[(Block, Vec<usize>)], failing: &mut Vec<String>| {
@@ -2389,6 +2399,7 @@ fn solve_inner(
point_determined,
curve_determined,
redundant,
+ oversized: too_large,
}
}