Merge pull request #179 from tbreckle/fix/177-centerline-to-construction
fix(sketch): a centerline can be switched straight to construction
This commit is contained in:
2 files changed
+21
-2
No files matched your search
@@ -1738,14 +1738,18 @@ fn construction(s: &mut Session, p: &Value) -> Result<Value> {
|
|||||||
let cs: Vec<usize> =
|
let cs: Vec<usize> =
|
||||||
ids.iter().map(|id| sk.curve_index(id).ok_or_else(|| bad(cmd, format!("unknown curve `{id}`")))).collect::<Result<_>>()?;
|
ids.iter().map(|id| sk.curve_index(id).ok_or_else(|| bad(cmd, format!("unknown curve `{id}`")))).collect::<Result<_>>()?;
|
||||||
// The selection switches together (a slot or polygon as a whole): to construction
|
// The selection switches together (a slot or polygon as a whole): to construction
|
||||||
// unless all of it already is. Projected curves may switch too.
|
// unless all of it already is. Projected curves may switch too. A centerline that
|
||||||
|
// becomes construction stops being a centerline (one line type at a time).
|
||||||
let to = want.unwrap_or_else(|| !cs.iter().all(|c| sk.curves.get(*c).is_some_and(|c| c.construction)));
|
let to = want.unwrap_or_else(|| !cs.iter().all(|c| sk.curves.get(*c).is_some_and(|c| c.construction)));
|
||||||
let mut n = 0;
|
let mut n = 0;
|
||||||
for c in cs {
|
for c in cs {
|
||||||
if let Some(cu) = sk.curves.get_mut(c)
|
if let Some(cu) = sk.curves.get_mut(c)
|
||||||
&& cu.construction != to
|
&& (cu.construction != to || to && cu.centerline)
|
||||||
{
|
{
|
||||||
cu.construction = to;
|
cu.construction = to;
|
||||||
|
if to {
|
||||||
|
cu.centerline = false;
|
||||||
|
}
|
||||||
n += 1;
|
n += 1;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -237,6 +237,21 @@ fn construction_toggle_takes_shapes_out_of_profiles_and_back() {
|
|||||||
assert!(s.execute("sketch.construction", &json!({"curves": ["nope"]})).is_err());
|
assert!(s.execute("sketch.construction", &json!({"curves": ["nope"]})).is_err());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#[test]
|
||||||
|
fn centerline_can_become_construction_directly() {
|
||||||
|
let mut s = new_sketch();
|
||||||
|
let l = curve_ids(&run(&mut s, "sketch.line", json!({"points": [[0, 0], [20, 0]]})));
|
||||||
|
run(&mut s, "sketch.centerline", json!({ "curves": l, "value": true }));
|
||||||
|
let r = run(&mut s, "sketch.construction", json!({ "curves": l, "value": true }));
|
||||||
|
assert_eq!(r["changed"], 1);
|
||||||
|
let sk = sketch(&s);
|
||||||
|
assert!(sk.curves.iter().filter(|c| l.contains(&c.id)).all(|c| c.construction && !c.centerline));
|
||||||
|
// And back to a centerline.
|
||||||
|
run(&mut s, "sketch.centerline", json!({ "curves": l, "value": true }));
|
||||||
|
let sk = sketch(&s);
|
||||||
|
assert!(sk.curves.iter().filter(|c| l.contains(&c.id)).all(|c| c.centerline && !c.construction));
|
||||||
|
}
|
||||||
|
|
||||||
#[test]
|
#[test]
|
||||||
fn projected_geometry_can_become_construction() {
|
fn projected_geometry_can_become_construction() {
|
||||||
let mut s = Session::default();
|
let mut s = Session::default();
|
||||||
|
|||||||
Reference in new issue
Block a user