Sketch offset keeps its source lines free to turn (#4464) (#4466)

* claim: #4464

* Sketch offset keeps its source lines free to turn (#4464)

An offset adds a Parallel between each source line and its offset line.
Since offsets became associative, the offset's points are held during a
solve, so each Parallel pinned its source line to the offset line's
current direction: a closed chain lost its turning freedom (8 degrees of
freedom became 6), and Horizontal or an angle edit on a source line was
refused as conflicting.

The solver and the constructive reading now leave out a Parallel that
ties an offset line to the source it follows while the association lives;
the association already keeps them parallel. After Break the stored
Parallel drives again.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
Frank
2026-10-23 14:30:21 +00:00
committed by GitHub
parent 4e7bf2b63a
commit 3acb81964a
4 changed files with 68 additions and 2 deletions
@@ -1562,6 +1562,50 @@ fn offset_driver_edits_reopens_and_undoes_without_moving_sources() {
check(&reopened, 3.0);
}
#[test]
fn an_offset_leaves_its_source_lines_free_to_turn() {
// #4464: the Parallel between each source line and its offset line pinned the source to the
// offset's held direction: 8 degrees of freedom became 6, Horizontal and angle edits conflicted.
let mut s = new_sketch();
let points = json!([[-2, 38.9], [36.7, 17.1], [-5, 0], [57.7, -17.7], [-7.6, -25.7], [-22, 21.3]]);
run(&mut s, "sketch.line", json!({"points": points, "closed": true, "ids": ["l1", "l2", "l3", "l4", "l5", "l6"]}));
let mut angle = String::new();
for pair in [["l6", "l1"], ["l1", "l2"], ["l2", "l3"], ["l4", "l5"]] {
let d = run(&mut s, "sketch.dimension", json!({"entities": pair, "type": "angle"}));
angle = d["param"].as_str().unwrap().to_string();
}
let o = run(&mut s, "sketch.offset", json!({"curves": ["l1"], "distance": 2, "side": [5, 5]}));
assert_eq!(o["sketch"]["dof"], 8, "the offset follows its source and takes no freedom away: {o}");
let outputs = ids(&o["curves"]);
let line = |sk: &solidcraft_sketch::Sketch, id: &str| match sk.curves[sk.curve_index(id).unwrap()].kind {
CurveKind::Line { a, b } => (sk.points[a].pos, sk.points[b].pos),
ref other => panic!("{id} is {other:?}"),
};
let follows = |s: &Session| {
let sk = sketch(s);
for (source, output) in ["l1", "l2", "l3", "l4", "l5", "l6"].iter().zip(&outputs) {
let ((a, b), (c, d)) = (line(&sk, source), line(&sk, output));
let u = (b - a).normalized().unwrap();
assert!(u.cross((d - c).normalized().unwrap()).abs() < 1e-7, "{output} is parallel to {source}");
assert!(close(u.cross(c - a).abs(), 2.0) && close(u.cross(d - a).abs(), 2.0), "{output} is 2 mm from {source}");
}
};
follows(&s);
let h = run(&mut s, "sketch.constraint.horizontal_vertical", json!({"line": "l4", "mode": "horizontal"}));
assert_eq!(h["sketch"]["dof"], 7, "{h}");
follows(&s);
let (a, b) = line(&sketch(&s), "l4");
assert!((a.y - b.y).abs() < 1e-7, "l4 is horizontal");
run(&mut s, "parameters.change", json!({"name": angle, "expression": "90 deg"}));
follows(&s);
// A rounded boundary takes the convex path, whose lines pair with the association's roles.
let polygon = run(&mut s, "sketch.line", json!({"points": [[100, 0], [130, 5], [125, 30], [105, 25]], "closed": true}));
let corners = run(&mut s, "sketch.fillet", json!({"points": polygon["created"]["points"], "radius": "1 mm"}));
let o = run(&mut s, "sketch.offset", json!({"curves": [ids(&polygon["curves"])[0]], "distance": 1, "side": [115, 15]}));
assert!(o["association"].is_string(), "{o}");
assert_eq!(o["sketch"]["dof"], corners["sketch"]["dof"], "{o}");
}
#[test]
fn offset_driver_covers_disconnected_selections_and_refuses_bad_values_atomically() {
let mut s = new_sketch();
+1 -1
View File
@@ -829,7 +829,7 @@ pub(crate) fn read(sk: &Sketch, before: &dyn Fn(usize) -> Option<Vec2>, on_curve
let rounds: Vec<Option<Round>> = (0..m).map(|k| round_of(sk, k)).collect();
let line = |l: usize| lines.get(l).copied().flatten();
let round = |k: usize| rounds.get(k).copied().flatten();
let cons: Vec<&ConstraintKind> = sk.constraints.iter().filter(|c| !c.driven).map(|c| &c.kind).collect();
let cons: Vec<&ConstraintKind> = sk.constraints.iter().filter(|c| !c.driven && !sk.follows_its_source(&c.kind)).map(|c| &c.kind).collect();
let dim = |v: f64| (v.is_finite() && (0.0..=MAX_COORD).contains(&v)).then_some(v);
// Radii and lengths the dimensions set, also through equal curves.
+22
View File
@@ -30,6 +30,28 @@ impl Sketch {
.or_else(|| self.freeform_offsets.iter().find(|o| o.output == output).map(|o| o.distance))
}
/// A Parallel between an offset line and the source it follows (#4464). The association
/// keeps them parallel already, and the output's points are held during a solve, so solving
/// it would only pin the source to the output's current direction. It drives again once
/// Break releases the output.
pub(crate) fn follows_its_source(&self, kind: &ConstraintKind) -> bool {
let ConstraintKind::Parallel { a, b } = *kind else {
return false;
};
let (Some(a), Some(b)) = (self.curves.get(a).map(|c| c.id.as_str()), self.curves.get(b).map(|c| c.id.as_str())) else {
return false;
};
self.offsets.iter().any(|o| {
o.sources.iter().enumerate().any(|(i, (source, _))| {
let output = match &o.topology {
Some(t) => t.roles.get(i).map(|r| r.output.as_str()),
None => o.outputs.get(i).map(String::as_str),
};
output.is_some_and(|output| (source == a && output == b) || (source == b && output == a))
})
})
}
/// Endpoints of a normal-distance annotation, evaluated from its source curve.
pub fn offset_dimension_points(&self, output: &str) -> Option<(Vec2, Vec2)> {
let (source, forward, distance) = self
+1 -1
View File
@@ -1504,7 +1504,7 @@ fn build_blocks<'a>(sk: &'a Sketch, lay: &Layout, on_curve: &[(usize, usize)]) -
}
}
for (i, c) in sk.constraints.iter().enumerate() {
if c.driven || matches!(c.kind, ConstraintKind::OffsetDistance { .. }) {
if c.driven || matches!(c.kind, ConstraintKind::OffsetDistance { .. }) || sk.follows_its_source(&c.kind) {
continue;
}
raw.push(match touch_point(sk, &c.kind, on_curve) {