Sketch: Line and Construction Line refuse a second point next to the first (#11595)
A through-point 0.0000001 mm from the start made an infinite line whose direction nothing held, and a Line that short had both ends connected to the origin, a line of length zero. Both now refuse points closer than the distance at which a new point is connected to an existing one. Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -481,7 +481,7 @@ pub(super) mod solve_counts {
|
||||
}
|
||||
|
||||
/// How close (mm) a new point must land to an existing one to be connected to it.
|
||||
const CONNECT_TOL: f64 = 1e-6;
|
||||
pub(super) const CONNECT_TOL: f64 = 1e-6;
|
||||
|
||||
/// New points (index `first` on) that land on an existing point, the origin included, get a
|
||||
/// coincident constraint to it, as when a click snaps there; `connect: false` leaves them free.
|
||||
@@ -1171,7 +1171,8 @@ fn draw_line(s: &mut Session, p: &Value) -> Result<Value> {
|
||||
for i in 0..segs {
|
||||
let j = (i + 1) % n;
|
||||
let (Some(a), Some(b)) = (args.get(i), args.get(j)) else { continue };
|
||||
if a.pos().dist(b.pos()) < 1e-9 {
|
||||
// Ends closer than this would both be connected to one point (#11001).
|
||||
if a.pos().dist(b.pos()) < CONNECT_TOL {
|
||||
return Err(bad(cmd, "zero-length line"));
|
||||
}
|
||||
let id = ids.get(i).map(String::as_str);
|
||||
|
||||
@@ -6,7 +6,7 @@ use solidcore_record::{Seg2, Vec2};
|
||||
use solidcraft_geom::prelude::*;
|
||||
use solidcraft_sketch::{ConstraintKind, CurveKind, Sketch};
|
||||
|
||||
use super::sketch::{add_c, curve_ref, edit, ids_of, line_or_axis_ref, line_pts, req_parg, result};
|
||||
use super::sketch::{CONNECT_TOL, add_c, curve_ref, edit, ids_of, line_or_axis_ref, line_pts, req_parg, result};
|
||||
use super::{CommandSpec, in_sketch};
|
||||
use crate::params::{bad, expr, num, str_, vec2};
|
||||
use crate::schema::sketch_create::{ConstructionLineParams, ConstructionLineResult};
|
||||
@@ -261,6 +261,10 @@ fn run(s: &mut Session, p: &Value, default_mode: &str) -> Result<Value> {
|
||||
let first_new = sk.points.len();
|
||||
let at = req_parg(sk, doc, &p, "at", CMD)?;
|
||||
let through = if mode == "free" { Some(req_parg(sk, doc, &p, "through", CMD)?) } else { None };
|
||||
// A through-point next to the start leaves a line whose direction no constraint holds (#11001).
|
||||
if through.as_ref().is_some_and(|q| q.pos().dist(at.pos()) < CONNECT_TOL) {
|
||||
return Err(bad(CMD, "the through point must lie away from the start point"));
|
||||
}
|
||||
let mut params = p.clone();
|
||||
params["at"] = json!([at.pos().x, at.pos().y]);
|
||||
let angle_expression = if mode == "angle" {
|
||||
|
||||
@@ -326,6 +326,25 @@ fn construction_tangents_respect_arc_sweeps_and_invalid_inputs_are_atomic() {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn a_second_point_next_to_the_first_is_refused() {
|
||||
// #11001: a through-point 0.0000001 mm from the start made an infinite line whose direction
|
||||
// Horizontal no longer held, and a line that short collapsed onto the origin.
|
||||
let mut s = new_sketch();
|
||||
for (id, p) in [
|
||||
("sketch.construction_line", json!({"at":[0,0],"through":[0.0000001,0]})),
|
||||
("sketch.construction_line", json!({"at":[5,5],"through":[5,5.0000005]})),
|
||||
("sketch.line", json!({"points":[[0,0],[0.0000001,0]]})),
|
||||
("sketch.line", json!({"points":[[5,5],[10,5],[10,5.0000005]]})),
|
||||
] {
|
||||
let before = s.doc.to_json();
|
||||
assert!(s.execute(id, &p).is_err(), "{id} {p}");
|
||||
assert_eq!(s.doc.to_json(), before, "{id} {p}");
|
||||
}
|
||||
run(&mut s, "sketch.construction_line", json!({"at":[0,0],"through":[0.00001,0]}));
|
||||
run(&mut s, "sketch.line", json!({"points":[[5,5],[5.00001,5]]}));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn construction_relations_follow_source_edits_without_an_auxiliary_dimension() {
|
||||
let mut s = new_sketch();
|
||||
|
||||
Reference in New Issue
Block a user