Sketch projection: Project (edges, face loops, body silhouettes, vertices, other sketches' curves and points, origin, axes, planes), Intersect (body/face/edge section with the sketch plane) and Include 3D Geometry as linked reference geometry: fixed, purple, re-resolved on every recompute (follows upstream edits, keeps ids when the shape is unchanged, flagged when the reference is lost), usable in profiles, constraints and dimensions; Break Link; sketching on a face auto-projects its edges (sketch.auto_project); drawing on a model vertex or edge projects it

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01AS5Tn3xieewUSg3uxrMVdL
This commit is contained in:
bherbruckandClaude Opus 5.5 committed 2026-10-07 21:58:18 +00:00
1 parent eb22a149b1
commit 9301bc4210
17 files changed
+1842 -30

No files matched your search

+28 -13
View File
@@ -19,7 +19,7 @@ pub enum SketchError {
TooLarge,
}
type Result<T> = std::result::Result<T, SketchError>;
pub(crate) type Result<T> = std::result::Result<T, SketchError>;
/// A sketch point. `fixed` points are constants for the solver.
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@@ -28,6 +28,9 @@ pub struct SPoint {
pub pos: Vec2,
#[serde(default)]
pub fixed: bool,
/// Projected (linked) reference geometry: the id of the link that owns this point.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub link: Option<String>,
}
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
@@ -53,6 +56,10 @@ pub struct Curve {
/// as-drawn meaning.
#[serde(default, skip_serializing_if = "std::ops::Not::not")]
pub reversed: bool,
/// Projected (linked) reference geometry: the id of the link that owns this curve. Its
/// points are fixed and a linked circle keeps its radius.
#[serde(default, skip_serializing_if = "Option::is_none")]
pub link: Option<String>,
}
/// Geometric constraints and dimensions. Indices refer to `Sketch::points` (`p`, `q`) or
@@ -303,6 +310,9 @@ pub struct Sketch {
pub points: Vec<SPoint>,
pub curves: Vec<Curve>,
pub constraints: Vec<Constraint>,
/// Links to geometry outside the sketch (projections, intersections, includes).
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub links: Vec<crate::link::Link>,
/// Next number per id prefix (`l` → l1, l2…).
#[serde(default)]
counters: std::collections::BTreeMap<String, u64>,
@@ -317,28 +327,31 @@ impl Default for Sketch {
impl Sketch {
pub fn new() -> Self {
Sketch {
points: vec![SPoint { id: "origin".into(), pos: Vec2::ZERO, fixed: true }],
points: vec![SPoint { id: "origin".into(), pos: Vec2::ZERO, fixed: true, link: None }],
curves: Vec::new(),
constraints: Vec::new(),
links: Vec::new(),
counters: Default::default(),
}
}
/// A new unused id with the given prefix (`l` → `l3`).
pub fn fresh(&mut self, prefix: &str) -> String {
let n = self.counters.entry(prefix.to_string()).or_insert(0);
let mut n = self.counters.get(prefix).copied().unwrap_or(0);
loop {
*n += 1;
n += 1;
let id = format!("{prefix}{n}");
let taken =
self.points.iter().any(|p| p.id == id) || self.curves.iter().any(|c| c.id == id) || self.constraints.iter().any(|c| c.id == id);
if !taken {
if !self.id_taken(&id) {
self.counters.insert(prefix.to_string(), n);
return id;
}
}
}
fn id_taken(&self, id: &str) -> bool {
self.points.iter().any(|p| p.id == id) || self.curves.iter().any(|c| c.id == id) || self.constraints.iter().any(|c| c.id == id)
pub(crate) fn id_taken(&self, id: &str) -> bool {
self.points.iter().any(|p| p.id == id)
|| self.curves.iter().any(|c| c.id == id)
|| self.constraints.iter().any(|c| c.id == id)
|| self.links.iter().any(|l| l.id == id)
}
pub fn point_index(&self, id: &str) -> Option<usize> {
@@ -367,7 +380,7 @@ impl Sketch {
Some(i) => i.to_string(),
None => self.fresh("p"),
};
self.points.push(SPoint { id, pos: p, fixed: false });
self.points.push(SPoint { id, pos: p, fixed: false, link: None });
Ok(self.points.len() - 1)
}
@@ -395,7 +408,7 @@ impl Sketch {
return Err(SketchError::Invalid("line needs two distinct points".into()));
}
let id = self.curve_id(id, "l")?;
self.curves.push(Curve { id, kind: CurveKind::Line { a, b }, construction: false, reversed: false });
self.curves.push(Curve { id, kind: CurveKind::Line { a, b }, construction: false, reversed: false, link: None });
Ok(self.curves.len() - 1)
}
@@ -424,7 +437,7 @@ impl Sketch {
Some(i) if i < self.points.len() => i,
_ => self.own_point(&id, "center", center)?,
};
self.curves.push(Curve { id, kind: CurveKind::Circle { c, r }, construction: false, reversed: false });
self.curves.push(Curve { id, kind: CurveKind::Circle { c, r }, construction: false, reversed: false, link: None });
Ok(self.curves.len() - 1)
}
@@ -450,7 +463,7 @@ impl Sketch {
Some(i) if i < n && i != a => i,
_ => self.own_point(&id, "end", p1)?,
};
self.curves.push(Curve { id, kind: CurveKind::Arc { c, a, b }, construction: false, reversed: false });
self.curves.push(Curve { id, kind: CurveKind::Arc { c, a, b }, construction: false, reversed: false, link: None });
Ok(self.curves.len() - 1)
}
@@ -576,6 +589,7 @@ impl Sketch {
orphans.sort_unstable();
orphans.dedup();
self.remove_points(&orphans);
self.prune_links();
}
fn point_used_by_curve(&self, p: usize) -> bool {
@@ -656,6 +670,7 @@ impl Sketch {
idx += 1;
k
});
self.prune_links();
}
/// Resolve a point reference: a point id (`origin`, `l1.end`, `p3`) or `<curve>.start|end|center`.