* claim: #6173 * Sketch: conic curves take the id prefix n, not the constraints' k (#6173)
This commit is contained in:
committed by
GitHub
parent
be2168f70d
commit
a3ee8957f4
@@ -328,3 +328,28 @@ fn commands_that_add_nothing_report_empty_lists() {
|
||||
let r = run(&mut s, "sketch.move_point", json!({"point": strs(&c["points"])[1], "to": [12, 6]}));
|
||||
assert_eq!(r["created"], json!({"points": [], "curves": [], "constraints": [], "dimensions": []}), "{r}");
|
||||
}
|
||||
|
||||
/// Conic curves take the curve prefix `n`, not the constraints' `k` (#6173): however a conic
|
||||
/// is created — drawn, a Move/Copy copy, a pattern copy — its id still says it is a curve.
|
||||
#[test]
|
||||
fn conic_curves_take_the_n_prefix_not_the_constraints_k() {
|
||||
let mut s = new_sketch();
|
||||
let drawn = run(&mut s, "sketch.conic", json!({"start": [80, 490], "end": [100, 490], "apex": [90, 505], "rho": 0.5}));
|
||||
let conic = strs(&drawn["curves"])[0].clone();
|
||||
assert_eq!(conic, "n1", "a drawn conic starts its own counter");
|
||||
|
||||
// A constraint keeps its prefix, and it no longer shares a counter with conics.
|
||||
run(&mut s, "sketch.constraint.fix", json!({"entity": format!("{conic}.start")}));
|
||||
let sk = sketch(&s);
|
||||
assert!(sk.constraints.iter().any(|k| k.id == "k1"), "constraint ids: {:?}", sk.constraints.iter().map(|k| &k.id).collect::<Vec<_>>());
|
||||
|
||||
let copy = run(&mut s, "sketch.move", json!({"entities": [conic], "translate": [40, 0], "copy": true}));
|
||||
assert_eq!(strs(©["curves"]), vec!["n2".to_string()], "a Move/Copy copy continues the conic counter");
|
||||
|
||||
let pattern = run(&mut s, "sketch.pattern.rectangular", json!({"entities": [conic], "count": 2, "spacing": 40}));
|
||||
let made: Vec<String> = strs(&pattern["curves"]);
|
||||
assert!(!made.is_empty(), "{pattern}");
|
||||
for id in made {
|
||||
assert!(id.starts_with('n'), "a pattern copy keeps the conic prefix: {id}");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -2300,7 +2300,7 @@ fn copy_through(
|
||||
(kind, "e")
|
||||
}
|
||||
CurveKind::Spline { .. } => (kind, "s"),
|
||||
CurveKind::Conic { .. } => (kind, "k"),
|
||||
CurveKind::Conic { .. } => (kind, "n"),
|
||||
CurveKind::Line { a, b } => (CurveKind::Line { a: m(a), b: m(b) }, "l"),
|
||||
CurveKind::Circle { c, r } => (CurveKind::Circle { c: m(c), r: r * scale_r }, "c"),
|
||||
CurveKind::Arc { c, a, b } => {
|
||||
|
||||
@@ -692,16 +692,16 @@ fn dragging_a_conic_reads_rho_off_the_cursor_and_its_apex_slides_like_any_point(
|
||||
// Grabbed on the curve itself (its midpoint, at the default rho of 0.5): `rho` follows the
|
||||
// cursor, read off where it falls between the chord's midpoint (20, 0) and the apex (20,
|
||||
// 20). The three defining points stay exactly where they were.
|
||||
drag(&mut s, "k1", [20.0, 10.0], [20.0, 14.0]);
|
||||
drag(&mut s, "n1", [20.0, 10.0], [20.0, 14.0]);
|
||||
assert!((rho(&s) - 0.7).abs() < 1e-6, "rho after drag: {}", rho(&s));
|
||||
assert!(pt(&s, "k1.start").dist(v(0.0, 0.0)) < 1e-9);
|
||||
assert!(pt(&s, "k1.end").dist(v(40.0, 0.0)) < 1e-9);
|
||||
assert!(pt(&s, "k1.apex").dist(v(20.0, 20.0)) < 1e-9);
|
||||
assert!(pt(&s, "n1.start").dist(v(0.0, 0.0)) < 1e-9);
|
||||
assert!(pt(&s, "n1.end").dist(v(40.0, 0.0)) < 1e-9);
|
||||
assert!(pt(&s, "n1.apex").dist(v(20.0, 20.0)) < 1e-9);
|
||||
|
||||
// Grabbed on the apex itself: it slides like any other point (not a `rho` edit), and `rho`
|
||||
// is unaffected.
|
||||
drag(&mut s, "k1.apex", [20.0, 20.0], [10.0, 30.0]);
|
||||
assert!(pt(&s, "k1.apex").dist(v(10.0, 30.0)) < 1e-9);
|
||||
drag(&mut s, "n1.apex", [20.0, 20.0], [10.0, 30.0]);
|
||||
assert!(pt(&s, "n1.apex").dist(v(10.0, 30.0)) < 1e-9);
|
||||
assert!((rho(&s) - 0.7).abs() < 1e-6, "rho after apex drag: {}", rho(&s));
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user