diff --git a/crates/engine/src/cmd/modify.rs b/crates/engine/src/cmd/modify.rs index 592d13b0b..9b8d8af98 100644 --- a/crates/engine/src/cmd/modify.rs +++ b/crates/engine/src/cmd/modify.rs @@ -86,12 +86,10 @@ pub fn specs() -> Vec { .menu(&["Modify", "Trim"]) .alias(&["tr"]) .params(concat!( - "{handle, pick: [x,y]} | {fence: [[x,y],...]} | {crossing: [[x,y],[x,y]]}; ", - "edges?: [hex], edgeMode?: \"extend\"|\"none\", mode?: \"quick\"|\"standard\" ", + "{handle, pick: [x,y]} | {fence: [[x,y],...]} | {crossing: [[x,y],[x,y]]}; edges?: [hex], edgeMode?: \"extend\"|\"none\", mode?: \"quick\"|\"standard\" ", "→ {handles: the object (kept, reshaped) then the new pieces; none when it was erased} (pick) | {trimmed} (fence, crossing). ", "For handle+pick: handle is the object to trim; pick selects the portion of that object to remove ", - "(normally a point on it, away from a cutting intersection); edges are the cutting edges. ", - "The JSON default is standard mode." + "(normally a point on it, away from a cutting intersection); edges are the cutting edges. The JSON default is standard mode." )) .interactive(|_| Ok(Box::new(TrimM::new(false)))), CommandSpec::new("extend", "Extend", trimextend::run_extend) diff --git a/crates/engine/src/cmd/modify/trim.rs b/crates/engine/src/cmd/modify/trim.rs index 214ab6c15..839176a95 100644 --- a/crates/engine/src/cmd/modify/trim.rs +++ b/crates/engine/src/cmd/modify/trim.rs @@ -116,16 +116,19 @@ pub(crate) fn json_pick_error(s: &Session, h: Handle, pick: Vec2, edges: Edges, "No usable boundary intersection was found for either end of the object to extend." } } else { + let pick_param = ln.param_of(pick).clamp(0.0, 1.0); let has_cut = cut.iter().flat_map(|c| intersect_ext(&Segment::Line(ln), c, false)).any(|x| { let t = ln.param_of(x); t > 1e-9 && t < 1.0 - 1e-9 }); if !has_cut { "No usable cutting-edge intersection in the interior of the object to trim." - } else if ln.param_of(pick).is_nan() { + } else if pick_param.is_nan() { return error; + } else if !ln.at(pick_param).near(pick, 1e-9) { + "The `pick` point is off the line and projects onto a cutting intersection; pick away from that intersection." } else { - "The `pick` point projects onto a cutting intersection; pick a portion of the object away from that intersection." + "The `pick` point is at a cutting intersection; pick a portion of the object away from that intersection." } }; EngineError::Other(message.into()) diff --git a/crates/engine/tests/it/trim_extend_json_pick.rs b/crates/engine/tests/it/trim_extend_json_pick.rs index aa15022c9..004ac18e9 100644 --- a/crates/engine/tests/it/trim_extend_json_pick.rs +++ b/crates/engine/tests/it/trim_extend_json_pick.rs @@ -66,15 +66,13 @@ fn extend_execute_pick_selects_the_end_toward_the_boundary() -> TestResult { } #[test] -fn trim_execute_distinguishes_a_pick_projecting_onto_a_cut_from_no_cut() -> TestResult { +fn trim_execute_distinguishes_picks_at_or_projecting_onto_a_cut_from_no_cut() -> TestResult { let (mut s, a, b) = fixture(50.0, 25.0)?; - for pick in [[25, 10], [25, 0]] { - failure( - &mut s, - "trim", - json!({"handle": a.hex(), "edges": [b.hex()], "pick": pick, "mode": "standard"}), - "The `pick` point projects onto a cutting intersection; pick a portion of the object away from that intersection.", - )?; + for (pick, message) in [ + ([25, 10], "The `pick` point is off the line and projects onto a cutting intersection; pick away from that intersection."), + ([25, 0], "The `pick` point is at a cutting intersection; pick a portion of the object away from that intersection."), + ] { + failure(&mut s, "trim", json!({"handle": a.hex(), "edges": [b.hex()], "pick": pick, "mode": "standard"}), message)?; } let (mut s, a, b) = fixture(50.0, 75.0)?; failure(