EPS/.ai editing data: a live outline's check samples inside each segment

Two outlines can share their vertices and join them differently: ends
alone matched a bowtie to the square of its look. Each segment is now
checked at points at most the tolerance apart, within the same budget of
points compared.
This commit is contained in:
Don Omondi
2026-11-07 15:02:04 -05:00
parent bafa1868da
commit 5520a254b9
2 changed files with 23 additions and 4 deletions
+16 -4
View File
@@ -1164,12 +1164,24 @@ fn draws_look_outline(object: &Node, appearance: &Appearance, look: &Node) -> bo
}
(!over && !out.is_empty()).then_some(out)
}
/// Does every end of segments `a` lie within the tolerance of segments `b`? Both ends: the last
/// point of an open outline starts no segment.
/// Does every point of segments `a` lie within the tolerance of segments `b`? Each segment is
/// checked at both ends (the last point of an open outline starts no segment) and at points
/// at most the tolerance apart between them (two outlines can share their vertices and join
/// them differently). `false` past [`MAX_OUTLINE_PAIRS`] points compared.
fn near(a: &[kurbo::Line], b: &[kurbo::Line]) -> bool {
use kurbo::ParamCurveNearest;
use kurbo::{ParamCurve, ParamCurveArclen, ParamCurveNearest};
let close = |p: kurbo::Point| b.iter().any(|t| t.nearest(p, 1e-6).distance_sq <= OUTLINE_TOLERANCE * OUTLINE_TOLERANCE);
a.iter().all(|s| close(s.p0) && close(s.p1))
let mut budget = MAX_OUTLINE_PAIRS;
for s in a {
let steps = (s.arclen(1e-6) / OUTLINE_TOLERANCE).ceil();
let steps = if steps.is_finite() && steps >= 1.0 { steps as usize } else { 1 };
let Some(left) = budget.checked_sub(steps.saturating_add(1).saturating_mul(b.len())) else { return false };
budget = left;
if !(0..=steps).all(|k| close(s.eval(k as f64 / steps as f64))) {
return false;
}
}
true
}
let (mut ours, mut theirs) = (vec![], vec![]);
if !matches!(object.kind, NodeKind::Path { .. } | NodeKind::Compound { .. }) || !leaves(object, &mut ours, 0) || !leaves(look, &mut theirs, 0) {
+7
View File
@@ -5863,6 +5863,13 @@ fn a_path_with_zig_zag_comes_in_as_itself_where_its_look_has_that_outline() {
assert!(!r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings);
let r = read_ok(&format!("{}{}", distort_styles("Adobe Zigzag", keys, BLUE_FILL), layer(&object(&ops(3.0)))));
assert!(r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings);
// A Zig Zag of no size on an open path through the corners of its look's square, joined
// across it: the vertices match, the segments between them don't, so the drawn look stays.
let flat = "0 /Real (amount) ,\n1 /Real (absoluteness) ,\n0 /Real (ridges) ,\n0 /Real (roundness) ,\n";
let bowtie = "%_20 20 m\n%_60 50 L\n%_60 20 L\n%_20 50 L\n%_F\n";
let crossed = format!("0 Ae\nu\n0 0 0 0 0 0 1 Xa\n{}f\nU\n{bowtie}1 (Bent) XW\n", rect_path(20.0, 20.0, 60.0, 50.0));
let r = read_ok(&format!("{}{}", distort_styles("Adobe Zigzag", flat, BLUE_FILL), layer(&crossed)));
assert!(r.warnings.iter().any(|w| w.contains("drawn look")), "{:?}", r.warnings);
}
/// The gradient `G`, white to black, defined for a document.