mirror of
https://github.com/storytold/cadcraft.git
synced 2026-12-02 02:38:30 -06:00
SCALE: a factor point on the base point re-prompts instead of ending the command (fixes #3475)
At the Specify scale factor prompt, a picked point at the base point gives a factor of zero. The command then cleared the selection and ended without scaling anything or saying why. It now answers "Requires a positive number." and stays at the prompt, keeping the selection and base point, as typed factors and the Reference option already do. Non-finite factors are rejected the same way.
This commit is contained in:
@@ -571,7 +571,9 @@ impl Interactive for SelectThen {
|
||||
}
|
||||
(Op::Scale, 1, inp @ (Input::Point(_) | Input::Text(_) | Input::Enter)) => {
|
||||
let f = match inp {
|
||||
Input::Point(p) => self.pts[0].dist(p),
|
||||
Input::Point(p) => Some(self.pts[0].dist(p))
|
||||
.filter(|f| f.is_finite() && *f > 1e-12)
|
||||
.ok_or_else(|| EngineError::Other("Requires a positive number.".into()))?,
|
||||
Input::Text(t) => {
|
||||
number(&t).filter(|f| f.is_finite() && *f > 0.0).ok_or_else(|| EngineError::Other("Requires a positive number.".into()))?
|
||||
}
|
||||
|
||||
@@ -160,6 +160,7 @@ mod rename_cmdline;
|
||||
mod rotate_reference;
|
||||
mod rotation_grip_input;
|
||||
mod scale_offset_z;
|
||||
mod scale_zero_factor;
|
||||
mod select_keywords;
|
||||
mod select_similar;
|
||||
mod select_underscore_keywords;
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
//! SCALE: a factor point on the base point is rejected and the prompt stays (#3475).
|
||||
|
||||
use cadcraft_engine::Session;
|
||||
use cadcraft_engine::doc::EntityKind;
|
||||
|
||||
fn length(s: &Session) -> f64 {
|
||||
s.doc().unwrap().model.iter().find_map(|e| if let EntityKind::Line(l) = &e.kind { Some(l.a.xy().dist(l.b.xy())) } else { None }).unwrap()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn scale_factor_point_on_base_point_keeps_the_prompt() {
|
||||
let mut s = Session::new();
|
||||
s.cmdline("LINE 0,0 10,0").unwrap();
|
||||
s.cmdline("").unwrap();
|
||||
s.cmdline("SCALE").unwrap();
|
||||
s.cmdline("ALL").unwrap();
|
||||
s.cmdline("").unwrap();
|
||||
s.cmdline("0,0").unwrap();
|
||||
let before = length(&s);
|
||||
let _ = s.cmdline("0,0");
|
||||
assert!(s.running.is_some(), "the command ended: {:?}", s.log);
|
||||
assert_eq!(length(&s), before);
|
||||
assert!(!s.selection().is_empty(), "the selection was cleared");
|
||||
s.cmdline("0,3").unwrap();
|
||||
assert!(length(&s) > before, "line not scaled: {}", length(&s));
|
||||
}
|
||||
Reference in New Issue
Block a user