3D sketch curves (wires): Include 3D Geometry keeps out-of-plane edges and curves 3D; Project To Surface (curves onto a face along the sketch normal), Intersection Curve (bodies/faces), Isoparametric Curve (u/v or a direction), Spun Profile (a body's outline about an axis) and Fit Curves to Mesh Section; all linked and re-resolved; wires drawn, inspected and deletable

Co-Authored-By: Claude Opus 5.5 <[email protected]>
Claude-Session: https://claude.ai/code/session_01AS5Tn3xieewUSg3uxrMVdL
This commit is contained in:
bherbruckandClaude Opus 5.5 committed 2026-10-07 23:59:59 +00:00
1 parent beab69cfb2
commit cb01314d35
14 files changed
+835 -13

No files matched your search

+2
View File
@@ -16,6 +16,7 @@ mod profiles;
mod shape;
mod solver;
mod text;
mod wire;
pub use curves::{MAX_SPLINE_POINTS, conic_point, ellipse_point, end_curvature, spline_end_tangent, spline_point, spline_polyline};
pub use link::{Link, LinkGeom, LinkKind, LinkSource, MAX_LINK_ENTITIES};
@@ -24,6 +25,7 @@ pub use profiles::{Profile, find_drawn_profiles, find_profiles, merge_regions};
pub use shape::{Shape, intersections};
pub use solver::{SolveReport, SolveStatus, solve};
pub use text::{MAX_TEXT_CHARS, text_geometry};
pub use wire::{MAX_WIRE_POINTS, Wire};
#[cfg(test)]
mod tests;
+22 -1
View File
@@ -55,6 +55,16 @@ pub enum LinkSource {
/// An origin plane (`XY`, `XZ`, `YZ`) or a construction plane (by name): its trace on the
/// sketch plane.
Plane { name: String },
/// A curve of a sketch projected onto a body face (through `at`) along the normal of the
/// sketch that holds the link: a 3D curve.
OnSurface { sketch: u64, curve: String, body: String, at: Vec3 },
/// Where two bodies or faces (`Body` / `Face` sources) meet: 3D curves.
Intersection { a: Box<LinkSource>, b: Box<LinkSource> },
/// An isoparametric curve of the face through `at`: `dir` is `u` (around a curved face),
/// `v` (along it) or an explicit direction `[x, y, z]` (as text).
Iso { body: String, at: Vec3, dir: String },
/// The outline of a body spun about an axis (world line), laid into the sketch plane.
Spun { body: String, origin: Vec3, dir: Vec3 },
/// Text: baseline start `at` (sketch coordinates), capital height and angle (radians).
Text {
text: String,
@@ -78,6 +88,10 @@ impl LinkSource {
LinkSource::Origin => "origin".into(),
LinkSource::Axis { name } => format!("{name} axis"),
LinkSource::Plane { name } => format!("{name} plane"),
LinkSource::OnSurface { curve, .. } => format!("{curve} on a face"),
LinkSource::Intersection { a, b } => format!("intersection of {} and {}", a.describe(), b.describe()),
LinkSource::Spun { body, .. } => format!("spun profile of {body}"),
LinkSource::Iso { body, .. } => format!("isoparametric curve of {body}"),
LinkSource::Text { text, .. } => format!("text \"{}\"", text.chars().take(20).collect::<String>()),
}
}
@@ -513,6 +527,11 @@ impl Sketch {
p.fixed = false;
}
}
for w in &mut self.wires {
if w.link.as_deref() == Some(id) {
w.link = None;
}
}
self.links.retain(|l| l.id != id);
Ok(())
}
@@ -523,7 +542,9 @@ impl Sketch {
return;
}
let used = |id: &str, sk: &Sketch| {
sk.curves.iter().any(|c| c.link.as_deref() == Some(id)) || sk.points.iter().any(|p| p.link.as_deref() == Some(id))
sk.curves.iter().any(|c| c.link.as_deref() == Some(id))
|| sk.points.iter().any(|p| p.link.as_deref() == Some(id))
|| sk.wires.iter().any(|w| w.link.as_deref() == Some(id))
};
let keep: Vec<bool> = self.links.iter().map(|l| used(&l.id, self)).collect();
let mut k = keep.iter();
+5
View File
@@ -432,6 +432,9 @@ pub struct Sketch {
/// Links to geometry outside the sketch (projections, intersections, includes).
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub links: Vec<crate::link::Link>,
/// 3D curves (world coordinates) carried by the sketch.
#[serde(default, skip_serializing_if = "Vec::is_empty")]
pub wires: Vec<crate::wire::Wire>,
/// Next number per id prefix (`l` → l1, l2…).
#[serde(default)]
counters: std::collections::BTreeMap<String, u64>,
@@ -450,6 +453,7 @@ impl Sketch {
curves: Vec::new(),
constraints: Vec::new(),
links: Vec::new(),
wires: Vec::new(),
counters: Default::default(),
}
}
@@ -471,6 +475,7 @@ impl Sketch {
|| self.curves.iter().any(|c| c.id == id)
|| self.constraints.iter().any(|c| c.id == id)
|| self.links.iter().any(|l| l.id == id)
|| self.wires.iter().any(|w| w.id == id)
}
pub fn point_index(&self, id: &str) -> Option<usize> {
+86
View File
@@ -0,0 +1,86 @@
//! 3D sketch curves (wires): polylines in world coordinates that a sketch carries besides its
//! planar geometry — included 3D edges, curves projected onto surfaces, intersection curves.
//! They are reference geometry: drawn and usable as paths, not part of profiles or the solver.
use serde::{Deserialize, Serialize};
use solvecraft_geom::Vec3;
use crate::link::{Link, LinkGeom, LinkKind, LinkSource};
use crate::model::{Result, Sketch, SketchError};
/// Most points one wire may have.
pub const MAX_WIRE_POINTS: usize = 100_000;
#[derive(Clone, Debug, PartialEq, Serialize, Deserialize)]
pub struct Wire {
pub id: String,
/// World-space polyline.
pub pts: Vec<Vec3>,
#[serde(default, skip_serializing_if = "Option::is_none")]
pub link: Option<String>,
}
fn clean(w: &[Vec3]) -> Option<Vec<Vec3>> {
let mut out: Vec<Vec3> = Vec::new();
for p in w.iter().take(MAX_WIRE_POINTS) {
if !(p.is_finite() && p.x.abs() < 1e9 && p.y.abs() < 1e9 && p.z.abs() < 1e9) {
return None;
}
if out.last().is_none_or(|l| l.dist(*p) > 1e-9) {
out.push(*p);
}
}
(out.len() >= 2).then_some(out)
}
impl Sketch {
pub fn wire_index(&self, id: &str) -> Option<usize> {
self.wires.iter().position(|w| w.id == id)
}
/// Wires owned by a link, in creation order.
pub fn link_wires(&self, id: &str) -> Vec<usize> {
self.wires.iter().enumerate().filter(|(_, w)| w.link.as_deref() == Some(id)).map(|(i, _)| i).collect()
}
/// Add a link with planar geometry and/or 3D wires.
pub fn add_link_with_wires(&mut self, kind: LinkKind, source: LinkSource, geom: &[LinkGeom], wires: &[Vec<Vec3>]) -> Result<String> {
let ws: Vec<Vec<Vec3>> = wires.iter().filter_map(|w| clean(w)).collect();
if ws.is_empty() {
return self.add_link(kind, source, geom);
}
let id = if geom.is_empty() {
let id = self.fresh("j");
self.links.push(Link { id: id.clone(), kind, source, lost: false });
id
} else {
self.add_link(kind, source, geom)?
};
self.set_link_wires(&id, &ws)?;
Ok(id)
}
/// Replace a link's wires (ids are kept in order; extra wires get new ids).
pub fn set_link_wires(&mut self, id: &str, wires: &[Vec<Vec3>]) -> Result<()> {
if self.link(id).is_none() {
return Err(SketchError::Unknown(id.into()));
}
let ws: Vec<Vec<Vec3>> = wires.iter().filter_map(|w| clean(w)).collect();
let old: Vec<String> = self.link_wires(id).iter().filter_map(|i| self.wires.get(*i).map(|w| w.id.clone())).collect();
self.wires.retain(|w| w.link.as_deref() != Some(id));
for (k, pts) in ws.into_iter().enumerate() {
let wid = match old.get(k) {
Some(o) => o.clone(),
None => self.fresh("w"),
};
self.wires.push(Wire { id: wid, pts, link: Some(id.to_string()) });
}
Ok(())
}
/// Remove wires by id.
pub fn remove_wires(&mut self, ids: &[String]) {
self.wires.retain(|w| !ids.contains(&w.id));
self.prune_links();
}
}