Insert SVG: say why a sketch is too large (#10874) (#10880)

* claim: #10874

Co-authored-by: Cursor <cursoragent@cursor.com>

* Insert drawing: name the sketch size cap when a file is too dense (#10874)

A large SVG/DXF failed with opaque \"sketch is too large\". Say the 20000 point/curve limit and that scale alone does not reduce entity count, and refuse dense drawings before adding them.

Co-authored-by: Cursor <cursoragent@cursor.com>

---------

Co-authored-by: Cursor <cursoragent@cursor.com>
This commit is contained in:
SilentWolf75andCursor authored and GitHub committed 2026-11-01 23:37:55 +00:00
1 parent cfc46448a8
commit afa4f72f7d
2 files changed
+29 -1

No files matched your search

+21
View File
@@ -245,6 +245,11 @@ fn insert(s: &mut Session, p: &Value, cmd: &str, svg: bool) -> Result<Value> {
let v = (q - pivot) * k;
Vec2::new(v.x * cos - v.y * sin, v.x * sin + v.y * cos) + off
};
// A dense SVG/DXF (a floorplan) can yield far more entities than a sketch takes; refuse
// before adding so the message names the cap (#10874). Scale alone does not shrink the count.
if geom.len() > solidcraft_sketch::MAX_POINTS {
return Err(solidcraft_sketch::SketchError::TooLarge.into());
}
let ((curves, texts), info) = edit(s, p, cmd, false, |sk, _| {
let (cs, texts) = add_geometry(sk, &geom, &f, k, tol)?;
Ok((ids_of(sk, &cs), texts))
@@ -371,6 +376,22 @@ mod tests {
}
}
/// #10874: a drawing with more entities than a sketch can hold is refused with the point
/// cap and that scale alone does not help (a floorplan SVG often hits this).
#[test]
fn a_drawing_with_too_many_entities_names_the_sketch_cap() {
let n = solidcraft_sketch::MAX_POINTS + 1;
let mut dxf = String::from("0\nSECTION\n2\nENTITIES\n");
for i in 0..n {
dxf.push_str(&format!("0\nLINE\n10\n{i}\n20\n0\n11\n{}\n21\n1\n", i + 1));
}
dxf.push_str("0\nENDSEC\n0\nEOF\n");
let mut s = Session::default();
let e = s.execute("sketch.insert_dxf", &json!({"text": dxf})).unwrap_err().to_string();
assert!(e.contains("20000") && e.contains("scale"), "{e}");
assert!(s.active_sketch.is_none(), "a refused insert leaves no empty sketch behind");
}
/// #9641: an SVG with nothing SolidCraft can draw (here only an embedded picture) is refused
/// with a message naming the file and saying why, not "invalid parameters … no geometry"; a
/// UTF-16 SVG file inserts.
+8 -1
View File
@@ -8,6 +8,8 @@ pub const MAX_POINTS: usize = 20_000;
pub const MAX_CONSTRAINTS: usize = 40_000;
/// Curves need points, so this follows the point cap.
pub const MAX_CURVES: usize = MAX_POINTS;
// [`SketchError::TooLarge`]'s message names this number; keep them matched (#10874).
const _: () = assert!(MAX_POINTS == 20_000);
/// Largest coordinate or dimension value (mm) a sketch accepts.
pub const MAX_COORD: f64 = 1e9;
@@ -37,7 +39,12 @@ pub enum SketchError {
Duplicate(String),
#[error("invalid value: {0}")]
Invalid(String),
#[error("sketch is too large")]
/// Cap hit on points, curves or constraints ([`MAX_POINTS`], [`MAX_CURVES`],
/// [`MAX_CONSTRAINTS`]). Insert SVG/DXF of a dense drawing (a floorplan) often hits this;
/// scale alone does not reduce how many curves the file has (#10874).
#[error(
"sketch is too large (at most 20000 points or curves); simplify the drawing or split it across sketches — changing scale does not reduce how many curves it has"
)]
TooLarge,
}