While drawing, the pointer snaps to the crossing of two lines, circles or arcs and keeps the new point on both curves. Shift still prefers a midpoint.
This commit is contained in:
@@ -52,6 +52,8 @@ PCB / Package, Render, Animation, Simulation, Manufacture/CAM, Drawings.
|
||||
| M0 | Vertical slice | done | — |
|
||||
| M1 | Sketch depth: command coverage implemented — projection/intersect/include as linked geometry (auto-project on faces, lost-reference warnings, break link), full SKETCH create/modify set (slots, polygons, tangent arcs/circles, ellipse, fit/control splines, conic, text, trim/extend/break, fillet/chamfer, offset, mirror, patterns, move/scale, blend curve, centerline), constraints incl. curvature and polygon with over-constraint refusal, Shift-picked line midpoints in Horizontal/Vertical using persisted points and ordinary constraints (#2087), driven/arc-length/linear-diameter dimensions, AutoConstrain, DXF/SVG insert, 3D sketch curves (Project To Surface, Intersection Curve, Isoparametric Curve, Spun Profile), exact free-form profiles (B-spline/NURBS edges, any spline degree, curves cut by crossings), sweeps and pipes along 3D sketch curves, canvases and decals, curvature combs. Exact free-form Extend and certified associative offsets now preserve geometry and IDs through edits, deletion and reopen. Occurrence-frame 3D wires now store explicit coordinate spaces and retain points and analytic fits through moves, refresh, undo and reopen. Constructive sketch solving (Owen 1991, Fudos & Hoffmann 1997) ahead of the numerical solver: points and rigid clusters are placed on the branch the sketch had, so dimension edits and drags keep their solution; edits that would turn a sketch over are refused; drags re-solve only the sketch per frame. Remaining workflow repairs: mixed offset junctions, legacy natural-spline seams, and damaged legacy wire links lacking frame provenance | in progress | 4 |
|
||||
| M2 | Robust modelling: coplanar booleans in the kernel, holes (placed on faces, at distances from reference edges, and on sketch points), threads (cosmetic, then modelled), patterns, mirror, shell, draft, split, construction geometry | in progress | 16 |
|
||||
| M1 | Sketch depth: command coverage implemented — projection/intersect/include as linked geometry (auto-project on faces, lost-reference warnings, break link), full SKETCH create/modify set (slots, polygons, tangent arcs/circles, ellipse, fit/control splines, conic, text, trim/extend/break, fillet/chamfer, offset, mirror, patterns, move/scale, blend curve, centerline), constraints incl. curvature and polygon with over-constraint refusal, Shift-picked line midpoints in Horizontal/Vertical using persisted points and ordinary constraints (#2087), drawing snaps to where two lines, circles or arcs cross (#4967), driven/arc-length/linear-diameter dimensions, AutoConstrain, DXF/SVG insert, 3D sketch curves (Project To Surface, Intersection Curve, Isoparametric Curve, Spun Profile), exact free-form profiles (B-spline/NURBS edges, any spline degree, curves cut by crossings), sweeps and pipes along 3D sketch curves, canvases and decals, curvature combs. Exact free-form Extend and certified associative offsets now preserve geometry and IDs through edits, deletion and reopen. Occurrence-frame 3D wires now store explicit coordinate spaces and retain points and analytic fits through moves, refresh, undo and reopen. Constructive sketch solving (Owen 1991, Fudos & Hoffmann 1997) ahead of the numerical solver: points and rigid clusters are placed on the branch the sketch had, so dimension edits and drags keep their solution; edits that would turn a sketch over are refused; drags re-solve only the sketch per frame. Remaining workflow repairs: mixed offset junctions, legacy natural-spline seams, and damaged legacy wire links lacking frame provenance | in progress | 4 |
|
||||
| M2 | Robust modelling: coplanar booleans in the kernel, holes (placed on faces and on sketch points), threads (cosmetic, then modelled), patterns, mirror, shell, draft, split, construction geometry | in progress | 16 |
|
||||
| M3 | General fillets and chamfers (curved edges, chains, vertex blends); saddle rolling-ball surfaces now use continuous seam sections and arc-length fitting with shared contact boundaries and bounded accuracy checks; tiny rim edges remain selected instead of nearby wall seams when filleting (#2498) | in progress | 30 |
|
||||
| M4 | Files: STEP import (done — [docs/step-import.md](docs/step-import.md)), FreeCAD/Rhino solids through cadmpeg (done, desktop, browser and CLI), 3MF export and 3MF/STL import as mesh bodies (done), 3MF with B-rep face tags ([docs/formats/3mf-face-tags.md](docs/formats/3mf-face-tags.md), done), constant-section parametric mesh reconstruction, DXF sketches, OBJ import | in progress | 6 |
|
||||
| M5 | Persistent naming of faces and edges (docs/book/src/dev/naming.md): faces named from their exact kernel-reported history (sketch curve sides, caps, revolve sections, primitive sides, blends, shell inner walls, pattern/mirror copies; split pieces told apart by the faces around them, lumps of a cut body named after their faces), edges by their faces; fillets/chamfers, sketches on faces, shell/draft/offset/replace faces, hole placements, joint origins and face appearances resolve by name first and warn when the entity split or vanished: done. sheet metal edges by base sketch line and flange side, shell inner faces, sweep and loft roles: done. kernel-reported face history: done (merged faces answer to every name; operations without history yet fall back to geometric names, flagged unverified; format 14 keeps older designs' geometric names). Left: history through sheet metal, plastic, surface and emboss features; FaceSource certificates through history | in progress | 20 |
|
||||
|
||||
@@ -341,6 +341,51 @@ fn drawing_onto_a_curve_keeps_the_point_on_it() {
|
||||
assert!((st.dist(cc) - 8.0).abs() < 1e-7, "{st:?} {cc:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drawing_at_a_curve_crossing_keeps_the_point_on_both() {
|
||||
let mut s = new_sketch();
|
||||
let a = ids(&run(&mut s, "sketch.circle.center", json!({"center": [0, 0], "radius": 10}))["curves"])[0].clone();
|
||||
let b = ids(&run(&mut s, "sketch.circle.center", json!({"center": [10, 0], "radius": 10}))["curves"])[0].clone();
|
||||
let hi = [5.0, 5.0 * 3.0f64.sqrt()];
|
||||
let r = run(&mut s, "sketch.line", json!({"points": [format!("x:{a}+{b}:{},{}", hi[0], hi[1]), [40, 10]], "infer": false, "connect": false}));
|
||||
let n = ids(&r["curves"])[0].clone();
|
||||
let sk = sketch(&s);
|
||||
let st = sk.resolve_point(&format!("{n}.start")).and_then(|i| sk.point(i)).unwrap();
|
||||
assert!(st.dist(Vec2::new(hi[0], hi[1])) < 1e-6, "{st:?}");
|
||||
let start = sk.resolve_point(&format!("{n}.start")).unwrap();
|
||||
let ia = sk.curve_index(&a).unwrap();
|
||||
let ib = sk.curve_index(&b).unwrap();
|
||||
let on = |c: usize| {
|
||||
sk.constraints.iter().any(|k| matches!(k.kind, crate::sketch::ConstraintKind::PointOnCurve { p, c: curve } if p == start && curve == c))
|
||||
};
|
||||
assert!(on(ia) && on(ib), "{:?}", sk.constraints);
|
||||
run(&mut s, "sketch.dimension", json!({"entities": [a], "value": 12}));
|
||||
let sk = sketch(&s);
|
||||
let st = sk.resolve_point(&format!("{n}.start")).and_then(|i| sk.point(i)).unwrap();
|
||||
assert!(sk.shape(ia).expect("circle a").dist(st) < 1e-5, "on the resized circle: {st:?}");
|
||||
assert!(sk.shape(ib).expect("circle b").dist(st) < 1e-5, "still on the other circle: {st:?}");
|
||||
assert!(st.y > 0.0, "the upper crossing: {st:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn drawing_at_a_curve_crossing_refuses_hostile_arguments() {
|
||||
let mut s = new_sketch();
|
||||
let a = ids(&run(&mut s, "sketch.line", json!({"points": [[0, 0], [10, 0]], "infer": false}))["curves"])[0].clone();
|
||||
let b = ids(&run(&mut s, "sketch.line", json!({"points": [[0, 10], [10, 10]], "infer": false}))["curves"])[0].clone();
|
||||
for p in [
|
||||
json!({"points": ["x:", [1, 1]]}),
|
||||
json!({"points": [format!("x:{a}:1,1"), [1, 1]]}),
|
||||
json!({"points": [format!("x:{a}+{a}:5,0"), [1, 1]]}),
|
||||
json!({"points": [format!("x:{a}+{b}:nan,0"), [1, 1]]}),
|
||||
json!({"points": [format!("x:{a}+{b}:1,2,3"), [1, 1]]}),
|
||||
json!({"points": ["x:missing+also:0,0", [1, 1]]}),
|
||||
json!({"points": [format!("x:{a}+{b}:5,5"), [1, 1]]}),
|
||||
json!({"points": [format!("x:{}+{b}:0,0", "z".repeat(200)), [1, 1]]}),
|
||||
] {
|
||||
assert!(s.execute("sketch.line", &p).is_err(), "{p}");
|
||||
}
|
||||
}
|
||||
|
||||
/// A faucet spout path: a vertical riser, a horizontal top and an outlet sloping down, joined
|
||||
/// by fillets. The riser points up and the outlet down-left, so their directions are 150° apart
|
||||
/// while the lines meet at 30°.
|
||||
|
||||
@@ -6,8 +6,8 @@
|
||||
use serde_json::{Value, json};
|
||||
use solidcraft_doc::project::resolve;
|
||||
use solidcraft_doc::{Document, FeatureKind};
|
||||
use solidcraft_geom::{Plane, Vec3};
|
||||
use solidcraft_sketch::{ConstraintKind, LinkKind, LinkSource, Sketch};
|
||||
use solidcraft_geom::{Plane, Vec2, Vec3};
|
||||
use solidcraft_sketch::{ConstraintKind, LinkKind, LinkSource, Sketch, nearest_crossing};
|
||||
|
||||
use super::{CommandSpec, in_sketch};
|
||||
use crate::params::{bad, bool_, str_, vec3};
|
||||
@@ -442,11 +442,38 @@ fn auto_project(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
Ok(json!({"auto_project": s.auto_project}))
|
||||
}
|
||||
|
||||
/// `"x:<a>+<b>:x,y"` from interactive snapping: two distinct curve ids and a hint point.
|
||||
fn curve_intersection_arg(v: &Value, cmd: &str) -> Result<Option<(String, String, Vec2)>> {
|
||||
let Some(raw) = v.as_str() else { return Ok(None) };
|
||||
let Some(t) = raw.strip_prefix("x:") else { return Ok(None) };
|
||||
if t.len() > 256 {
|
||||
return Err(bad(cmd, "`x:` snap is too long"));
|
||||
}
|
||||
let Some((ids, xy)) = t.rsplit_once(':') else {
|
||||
return Err(bad(cmd, "`x:` needs two curve ids and a point"));
|
||||
};
|
||||
if ids.bytes().filter(|b| *b == b'+').count() != 1 {
|
||||
return Err(bad(cmd, "`x:` needs two distinct curve ids"));
|
||||
}
|
||||
let Some((a, b)) = ids.split_once('+') else {
|
||||
return Err(bad(cmd, "`x:` needs two distinct curve ids"));
|
||||
};
|
||||
if a.is_empty() || b.is_empty() || a == b || a.len() > 128 || b.len() > 128 {
|
||||
return Err(bad(cmd, "`x:` needs two distinct curve ids"));
|
||||
}
|
||||
let n: Vec<f64> = xy.split(',').map(str::trim).filter(|s| !s.is_empty()).filter_map(|x| x.parse().ok()).collect();
|
||||
match n.as_slice() {
|
||||
[x, y] if x.is_finite() && y.is_finite() => Ok(Some((a.to_string(), b.to_string(), Vec2::new(*x, *y)))),
|
||||
_ => Err(bad(cmd, "`x:` point must be two finite numbers")),
|
||||
}
|
||||
}
|
||||
|
||||
/// Point arguments that snap to model geometry while drawing, rewritten to sketch point ids:
|
||||
/// `{"vertex": [x,y,z]}` projects the vertex (a linked point); `{"on_edge": [x,y,z]}` projects
|
||||
/// the edge and makes a free point on it (coincident with the projection); `"mid:<line>"`
|
||||
/// makes a point held at the line's midpoint (and `"vertex:x,y,z"` is the vertex form). Everything
|
||||
/// else is left as it is. The links are added to the active sketch in the session's document.
|
||||
/// makes a point held at the line's midpoint; `"x:<a>+<b>:x,y"` makes a point at the crossing of
|
||||
/// two lines, circles or arcs (and `"vertex:x,y,z"` is the vertex form). Everything else is left
|
||||
/// as it is. The links are added to the active sketch in the session's document.
|
||||
pub(super) fn snap_points(s: &mut Session, p: &Value, cmd: &str) -> Result<Value> {
|
||||
let Some(id) = s.active_sketch else { return Ok(p.clone()) };
|
||||
let mut out = p.clone();
|
||||
@@ -468,11 +495,12 @@ pub(super) fn snap_points(s: &mut Session, p: &Value, cmd: &str) -> Result<Value
|
||||
let (c, xy) = t.rsplit_once(':')?;
|
||||
let n: Vec<f64> = xy.split(',').filter_map(|x| x.trim().parse().ok()).collect();
|
||||
match n[..] {
|
||||
[x, y] if x.is_finite() && y.is_finite() => Some((c.to_string(), solidcraft_geom::Vec2::new(x, y))),
|
||||
[x, y] if x.is_finite() && y.is_finite() => Some((c.to_string(), Vec2::new(x, y))),
|
||||
_ => None,
|
||||
}
|
||||
});
|
||||
if vertex.is_none() && edge.is_none() && mid.is_none() && on.is_none() {
|
||||
let crossing = curve_intersection_arg(v, cmd)?;
|
||||
if vertex.is_none() && edge.is_none() && mid.is_none() && on.is_none() && crossing.is_none() {
|
||||
return Ok(());
|
||||
}
|
||||
if doc.is_none() {
|
||||
@@ -492,6 +520,19 @@ pub(super) fn snap_points(s: &mut Session, p: &Value, cmd: &str) -> Result<Value
|
||||
let pi = sk.add_point(at, None)?;
|
||||
sk.add_constraint(ConstraintKind::PointOnCurve { p: pi, c }, None)?;
|
||||
sk.points.get(pi).map(|q| q.id.clone()).unwrap_or_default()
|
||||
} else if let Some((a, b, near)) = crossing {
|
||||
let ci = sk.curve_index(&a).ok_or_else(|| bad(cmd, format!("unknown curve `{a}`")))?;
|
||||
let cj = sk.curve_index(&b).ok_or_else(|| bad(cmd, format!("unknown curve `{b}`")))?;
|
||||
if ci == cj {
|
||||
return Err(bad(cmd, "`x:` needs two distinct curves"));
|
||||
}
|
||||
let sha = sk.shape(ci).ok_or_else(|| bad(cmd, format!("`{a}` is not a line, circle or arc")))?;
|
||||
let shb = sk.shape(cj).ok_or_else(|| bad(cmd, format!("`{b}` is not a line, circle or arc")))?;
|
||||
let at = nearest_crossing(&sha, &shb, near).ok_or_else(|| bad(cmd, "those curves do not meet"))?;
|
||||
let pi = sk.add_point(at, None)?;
|
||||
sk.add_constraint(ConstraintKind::PointOnCurve { p: pi, c: ci }, None)?;
|
||||
sk.add_constraint(ConstraintKind::PointOnCurve { p: pi, c: cj }, None)?;
|
||||
sk.points.get(pi).map(|q| q.id.clone()).unwrap_or_default()
|
||||
} else if let Some(line) = mid {
|
||||
// "mid:<line>": a new point at the line's midpoint, kept there.
|
||||
let l = sk.curve_index(&line).ok_or_else(|| bad(cmd, format!("unknown curve `{line}`")))?;
|
||||
|
||||
@@ -63,7 +63,7 @@ pub use profiles::{
|
||||
CurvePick, Profile, distinct_curves, find_drawn_profiles, find_profiles, merge_regions, profile_at_point, profile_by_curves,
|
||||
without_text_counters,
|
||||
};
|
||||
pub use shape::{Shape, intersections, intersections_within};
|
||||
pub use shape::{Shape, intersections, intersections_within, nearest_crossing, nearest_curve_intersection};
|
||||
pub use solver::solve_after_edit_with_analysis;
|
||||
pub use solver::{
|
||||
Analysis, CONSISTENT, DrivingValues, Hold, MAX_COMPONENT_VARS, SolveReport, SolveStatus, constraint_residual, determined_by, flips_from_stored,
|
||||
|
||||
@@ -136,6 +136,68 @@ pub fn intersections_within(x: &Shape, y: &Shape, tol: f64) -> Vec<Vec2> {
|
||||
}
|
||||
}
|
||||
|
||||
/// How close a computed crossing must lie to both bounded curves to count as on them.
|
||||
const ON_CURVE: f64 = 1e-4;
|
||||
/// Curves considered for a snap, so a hostile sketch cannot stall the pointer.
|
||||
const MAX_INTERSECTION_CANDIDATES: usize = 256;
|
||||
|
||||
/// The crossing of `x` and `y` nearest `near` that lies on both bounded curves.
|
||||
pub fn nearest_crossing(x: &Shape, y: &Shape, near: Vec2) -> Option<Vec2> {
|
||||
if !near.is_finite() {
|
||||
return None;
|
||||
}
|
||||
let mut best: Option<(f64, Vec2)> = None;
|
||||
for q in intersections_within(x, y, 1e-6) {
|
||||
if !q.is_finite() || x.dist(q) > ON_CURVE || y.dist(q) > ON_CURVE {
|
||||
continue;
|
||||
}
|
||||
let d = q.dist(near);
|
||||
if best.is_none_or(|prev| d < prev.0) {
|
||||
best = Some((d, q));
|
||||
}
|
||||
}
|
||||
best.map(|(_, q)| q)
|
||||
}
|
||||
|
||||
/// The nearest crossing of two lines, circles or arcs of `sk` to `p` within `tol`.
|
||||
///
|
||||
/// Skips a crossing that already has a sketch point. Curves whose bounded distance from `p`
|
||||
/// is greater than `tol` cannot meet near the cursor and are ignored.
|
||||
pub fn nearest_curve_intersection(sk: &Sketch, p: Vec2, tol: f64) -> Option<(Vec2, usize, usize)> {
|
||||
if !p.is_finite() || !tol.is_finite() || tol <= 0.0 {
|
||||
return None;
|
||||
}
|
||||
let mut candidates: Vec<(usize, Shape)> = Vec::new();
|
||||
for i in 0..sk.curves.len() {
|
||||
if candidates.len() >= MAX_INTERSECTION_CANDIDATES {
|
||||
break;
|
||||
}
|
||||
let Some(sh) = sk.shape(i) else { continue };
|
||||
if sh.dist(p) <= tol {
|
||||
candidates.push((i, sh));
|
||||
}
|
||||
}
|
||||
let mut best: Option<(f64, Vec2, usize, usize)> = None;
|
||||
for a in 0..candidates.len() {
|
||||
for b in a + 1..candidates.len() {
|
||||
let Some((ia, sa)) = candidates.get(a) else { continue };
|
||||
let Some((ib, sb)) = candidates.get(b) else { continue };
|
||||
let Some(q) = nearest_crossing(sa, sb, p) else { continue };
|
||||
let d = q.dist(p);
|
||||
if d > tol {
|
||||
continue;
|
||||
}
|
||||
if sk.points.iter().any(|pt| pt.pos.dist(q) <= ON_CURVE) {
|
||||
continue;
|
||||
}
|
||||
if best.is_none_or(|prev| d < prev.0) {
|
||||
best = Some((d, q, *ia, *ib));
|
||||
}
|
||||
}
|
||||
}
|
||||
best.map(|(_, q, i, j)| (q, i, j))
|
||||
}
|
||||
|
||||
impl Shape {
|
||||
/// Unbounded curve parameter of `p` (line: t along a→b; round: angle offset from start in
|
||||
/// [0, 2π)).
|
||||
@@ -204,3 +266,77 @@ impl Sketch {
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod intersection_snap_tests {
|
||||
use super::*;
|
||||
use crate::model::Sketch;
|
||||
|
||||
fn v(x: f64, y: f64) -> Vec2 {
|
||||
Vec2::new(x, y)
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nearest_curve_intersection_finds_crossing_lines() {
|
||||
let mut sk = Sketch::new();
|
||||
let a = sk.add_line(v(0.0, 0.0), v(20.0, 20.0), None, None, None).unwrap();
|
||||
let b = sk.add_line(v(0.0, 20.0), v(20.0, 0.0), None, None, None).unwrap();
|
||||
let (p, i, j) = nearest_curve_intersection(&sk, v(10.2, 9.8), 1.0).expect("crossing");
|
||||
assert!(p.dist(v(10.0, 10.0)) < 1e-9, "{p:?}");
|
||||
assert_eq!([i.min(j), i.max(j)], [a.min(b), a.max(b)]);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nearest_curve_intersection_skips_a_crossing_that_already_has_a_point() {
|
||||
let mut sk = Sketch::new();
|
||||
sk.add_line(v(0.0, 0.0), v(20.0, 20.0), None, None, None).unwrap();
|
||||
sk.add_line(v(0.0, 20.0), v(20.0, 0.0), None, None, None).unwrap();
|
||||
sk.add_point(v(10.0, 10.0), None).unwrap();
|
||||
assert!(nearest_curve_intersection(&sk, v(10.1, 10.0), 1.0).is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nearest_curve_intersection_ignores_parallel_lines_and_extensions() {
|
||||
let mut sk = Sketch::new();
|
||||
sk.add_line(v(0.0, 0.0), v(10.0, 0.0), None, None, None).unwrap();
|
||||
sk.add_line(v(0.0, 5.0), v(10.0, 5.0), None, None, None).unwrap();
|
||||
assert!(nearest_curve_intersection(&sk, v(5.0, 2.5), 3.0).is_none());
|
||||
let mut far = Sketch::new();
|
||||
far.add_line(v(0.0, 0.0), v(10.0, 0.0), None, None, None).unwrap();
|
||||
far.add_line(v(0.0, 10.0), v(0.0, 20.0), None, None, None).unwrap();
|
||||
assert!(nearest_curve_intersection(&far, v(0.0, 0.0), 1.0).is_none(), "the unbounded lines meet at an endpoint off the second segment");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nearest_curve_intersection_picks_the_nearer_circle_crossing() {
|
||||
let mut sk = Sketch::new();
|
||||
sk.add_circle(v(0.0, 0.0), 10.0, None, None).unwrap();
|
||||
sk.add_circle(v(10.0, 0.0), 10.0, None, None).unwrap();
|
||||
let hi = v(5.0, 5.0 * 3.0f64.sqrt());
|
||||
let (p, _, _) = nearest_curve_intersection(&sk, v(5.0, 8.0), 2.0).expect("upper crossing");
|
||||
assert!(p.dist(hi) < 1e-6, "{p:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nearest_curve_intersection_uses_an_arc_s_bounded_sweep() {
|
||||
let mut sk = Sketch::new();
|
||||
sk.add_arc(v(0.0, 0.0), v(10.0, 0.0), v(0.0, 10.0), [None; 3], None).unwrap();
|
||||
sk.add_line(v(-15.0, 0.0), v(-5.0, 0.0), None, None, None).unwrap();
|
||||
assert!(nearest_curve_intersection(&sk, v(-10.0, 0.0), 1.0).is_none(), "the missing half of the circle is not a snap");
|
||||
let mut on = Sketch::new();
|
||||
on.add_arc(v(0.0, 0.0), v(10.0, 0.0), v(0.0, 10.0), [None; 3], None).unwrap();
|
||||
on.add_line(v(0.0, 0.0), v(20.0, 20.0), None, None, None).unwrap();
|
||||
let (p, _, _) = nearest_curve_intersection(&on, v(7.0, 7.0), 2.0).expect("on the quarter");
|
||||
assert!((p.len() - 10.0).abs() < 1e-6 && p.x > 0.0 && p.y > 0.0, "{p:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn nearest_curve_intersection_refuses_hostile_cursor_and_tolerance() {
|
||||
let mut sk = Sketch::new();
|
||||
sk.add_line(v(0.0, 0.0), v(10.0, 0.0), None, None, None).unwrap();
|
||||
sk.add_line(v(0.0, 0.0), v(0.0, 10.0), None, None, None).unwrap();
|
||||
assert!(nearest_curve_intersection(&sk, Vec2::new(f64::NAN, 0.0), 1.0).is_none());
|
||||
assert!(nearest_curve_intersection(&sk, v(0.0, 0.0), 0.0).is_none());
|
||||
assert!(nearest_curve_intersection(&sk, v(0.0, 0.0), f64::INFINITY).is_none());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -362,9 +362,9 @@ fn combs(app: &SolveApp, painter: &egui::Painter, proj: &Proj) {
|
||||
});
|
||||
}
|
||||
|
||||
/// Snap a cursor point on the sketch plane to what is inferred while drawing: a line's
|
||||
/// midpoint, or alignment (horizontal/vertical) with the previous point of the tool. None:
|
||||
/// nothing near, use the grid.
|
||||
/// Snap a cursor point on the sketch plane to what is inferred while drawing: a crossing of
|
||||
/// two curves, a line's midpoint, or alignment (horizontal/vertical) with the previous point
|
||||
/// of the tool. None: nothing near, use the grid.
|
||||
pub fn refine_snap(
|
||||
app: &SolveApp,
|
||||
proj: &Proj,
|
||||
@@ -389,15 +389,25 @@ pub fn refine_snap(
|
||||
let mid_tol = if mid_only { tol * 1.5 } else { tol };
|
||||
let mut best: Option<(f64, &'static str, Vec2)> = None;
|
||||
let mut mid_of: Option<String> = None;
|
||||
for (i, c) in sk.curves.iter().enumerate() {
|
||||
if let solidcraft_engine::sketch::CurveKind::Line { .. } = c.kind
|
||||
&& let Some(solidcraft_engine::sketch::Shape::Line { a, b }) = sk.shape(i)
|
||||
{
|
||||
let m = (a + b) * 0.5;
|
||||
let d = m.dist(lp);
|
||||
if d < mid_tol && best.is_none_or(|x| d < x.0) {
|
||||
best = Some((d, "Mid", m));
|
||||
mid_of = Some(c.id.clone());
|
||||
// A crossing of two curves, before a midpoint or a point on one curve.
|
||||
if !mid_only
|
||||
&& let Some((q, i, j)) = solidcraft_engine::sketch::nearest_curve_intersection(sk, lp, tol)
|
||||
&& let (Some(a), Some(b)) = (sk.curves.get(i), sk.curves.get(j))
|
||||
{
|
||||
best = Some((q.dist(lp), "X", q));
|
||||
mid_of = Some(format!("{}+{}:{},{}", a.id, b.id, q.x, q.y));
|
||||
}
|
||||
if best.is_none() {
|
||||
for (i, c) in sk.curves.iter().enumerate() {
|
||||
if let solidcraft_engine::sketch::CurveKind::Line { .. } = c.kind
|
||||
&& let Some(solidcraft_engine::sketch::Shape::Line { a, b }) = sk.shape(i)
|
||||
{
|
||||
let m = (a + b) * 0.5;
|
||||
let d = m.dist(lp);
|
||||
if d < mid_tol && best.is_none_or(|x| d < x.0) {
|
||||
best = Some((d, "Mid", m));
|
||||
mid_of = Some(c.id.clone());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -468,8 +478,10 @@ pub fn refine_snap(
|
||||
}
|
||||
SNAP.with(|s| *s.borrow_mut() = best.map(|(_, l, p)| (l, p)));
|
||||
// A midpoint snap is a point argument the commands understand ("mid:<line>").
|
||||
// "x:a+b:x,y" is a crossing of two curves; "on:<curve>:x,y" is a point on one curve.
|
||||
best.map(|(_, l, p)| {
|
||||
let arg = match l {
|
||||
"X" => mid_of.map(|m| format!("x:{m}")),
|
||||
"Mid" => mid_of.map(|m| format!("mid:{m}")),
|
||||
"On" => mid_of.map(|m| format!("on:{m}")),
|
||||
// Already a point argument (`<id>.center` or `on:<id>:x,y`), or none for a free point.
|
||||
|
||||
@@ -88,7 +88,7 @@ While drawing or dragging a sketch point:
|
||||
| Keys | Action |
|
||||
|---|---|
|
||||
| Ctrl/Cmd or Alt/Option (default) | suppress auto-snap for that gesture |
|
||||
| Shift | prefer a line midpoint when targeting |
|
||||
| Shift | prefer a line midpoint when targeting (skips a curve-curve crossing) |
|
||||
|
||||
Change the snap-suppress chord in Preferences › Sketch. Selection still uses Shift and
|
||||
Ctrl/Cmd to add or toggle (Preferences › Selection can make Shift add-only).
|
||||
|
||||
@@ -156,6 +156,13 @@ ending the tool or losing picked points and inline values. The preview and hover
|
||||
keep construction dashes and centerline dash-dot patterns visible. With curves selected,
|
||||
Construction changes those curves as before.
|
||||
|
||||
The pointer snaps to existing sketch points, to a line's midpoint, and to **where two
|
||||
curves cross** (two lines, a line and a circle or arc, or two circles or arcs). The snap
|
||||
hint shows **X**. The new point stays on both curves when either one moves. Hold **Shift**
|
||||
to prefer a line midpoint instead; hold Ctrl/Cmd or Alt/Option (the default suppress chord)
|
||||
to stop snapping for that gesture. Scripts pass `"x:<curve>+<curve>:x,y"` as a point
|
||||
argument, the same way `"mid:<line>"` and `"on:<curve>:x,y"` work.
|
||||
|
||||
Enable **3D Sketch** in the Sketch Palette to draw lines, fit splines and points off the plane.
|
||||
While placing these points, you can snap to points on other visible sketches. For a bridge
|
||||
line, start Line and click an endpoint on each source sketch; each endpoint uses its source
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
row gives that item's menu. Right-click the design or a component and choose **Expand All** or
|
||||
**Collapse All** to open or close every folder under that row (the design row stays visible
|
||||
when the whole tree is collapsed). Rows drag into groups and other components.
|
||||
- **Viewport.** Click to select, Shift or Ctrl to add (Preferences › Selection), drag for a window or crossing box. While sketching, Ctrl/Cmd or Alt/Option suppress auto-snap by default; Shift prefers a midpoint. To
|
||||
- **Viewport.** Click to select, Shift or Ctrl to add (Preferences › Selection), drag for a window or crossing box. While sketching, Ctrl/Cmd or Alt/Option suppress auto-snap by default; Shift prefers a midpoint; the pointer also snaps to where two curves cross. To
|
||||
reach something under something else (two lines drawn on top of each other, coincident points,
|
||||
an edge in front of a face, overlapping bodies), hold the left button still for half a second
|
||||
(long-press on a touch screen) or right-click › **Select Other…**: a list of everything under
|
||||
|
||||
Reference in New Issue
Block a user