fix(engine): distinguish TRIM pick failures and unblock formatting

This commit is contained in:
Zaxaerith
2026-11-15 16:23:24 +08:00
parent 41c2a99a22
commit 149ba217ef
3 changed files with 13 additions and 14 deletions
+2 -4
View File
@@ -86,12 +86,10 @@ pub fn specs() -> Vec<CommandSpec> {
.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)
+5 -2
View File
@@ -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())
@@ -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(