mirror of
https://github.com/storytold/cadcraft.git
synced 2026-10-24 02:46:51 -06:00
Reject surveyor bearing angles outside 0-90 degrees (#2024)
Found while testing crates/engine/src/units.rs:279-294 (bearing, via parse_dms 297-317) Co-authored-by: Claude Haiku 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Haiku 5.5
parent
cff2eb7262
commit
0fc8e5241c
@@ -302,6 +302,9 @@ fn bearing(t: &str) -> Option<f64> {
|
||||
None => (rest.strip_suffix('w')?, false),
|
||||
};
|
||||
let a = parse_dms(ang_s.trim())?;
|
||||
if !(0.0..=90.0).contains(&a) {
|
||||
return None;
|
||||
}
|
||||
let deg = match (north, east) {
|
||||
(true, true) => 90.0 - a,
|
||||
(true, false) => 90.0 + a,
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
use cadcraft_engine::units::parse_angle;
|
||||
|
||||
#[test]
|
||||
fn bearing_rejects_out_of_range_angles() {
|
||||
for s in ["n100e", "n-45e", "n91e", "s-1w", "n-0.5e"] {
|
||||
assert_eq!(parse_angle(s), None, "{s}");
|
||||
}
|
||||
for s in ["n0e", "n90e", "s45w"] {
|
||||
assert!(parse_angle(s).is_some(), "{s}");
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user