[81] Aussenbemassung im Massstab der Ansicht statt fest 1:100

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
Claude committed 2026-11-04 15:02:43 +00:00
1 parent 4c61000fea
commit 4bd49d3b0c
6 files changed
+36 -7

No files matched your search

+9 -4
View File
@@ -1206,8 +1206,13 @@ fn auto_dims(root: &Map<String, Value>, ctx: &Ctx, prefix: &str, scale: f64) ->
.collect()
}
fn autodim_ops(root: &Map<String, Value>, ctx: &Ctx) -> Vec<Op> {
let dims = auto_dims(root, ctx, "autodim", 100.0);
/// Massstab der Ansicht für die Kettenabstände (`scale` in der Anfrage, sonst 1:100).
fn autodim_scale(v: &Value) -> f64 {
v.get("scale").and_then(Value::as_f64).filter(|s| s.is_finite() && *s > 0.0).unwrap_or(100.0)
}
fn autodim_ops(root: &Map<String, Value>, v: &Value, ctx: &Ctx) -> Vec<Op> {
let dims = auto_dims(root, ctx, "autodim", autodim_scale(v));
if dims.is_empty() {
return Vec::new();
}
@@ -1311,7 +1316,7 @@ pub fn ops(root: &Map<String, Value>, v: &Value, ctx: &Ctx, ids: &mut IdGen) ->
},
"dimround" => dimround_ops(root, v, ctx, ids),
"dimension" => dimension_ops(root, v, ctx, ids),
"autodim" => autodim_ops(root, ctx),
"autodim" => autodim_ops(root, v, ctx),
_ => return None,
})
}
@@ -1385,7 +1390,7 @@ pub fn preview(root: &Map<String, Value>, v: &Value, ctx: &Ctx, pts: &[V], p: &m
"dimension" => dimension_preview(v, pts, p),
"grid" => grid_preview(v, pts, p),
"dimround" => dimround_preview(root, v, ctx, pts, p),
"autodim" => p.ok = !auto_dims(root, ctx, "autodim", 100.0).is_empty(),
"autodim" => p.ok = !auto_dims(root, ctx, "autodim", autodim_scale(v)).is_empty(),
_ => return false,
}
true
+20
View File
@@ -1078,4 +1078,24 @@ mod tests {
.sum();
assert!(n_refs >= 4, "{n_refs}");
}
/// Aussenbemassung im Massstab der Ansicht: 1:50 setzt die Ketten halb so weit von der Wand wie 1:100.
#[test]
fn autodim_im_massstab_der_ansicht() {
let r = project();
let offsets = |scale: f64| -> Vec<f64> {
let req = json!({"cmd": "autodim", "scale": scale, "ctx": {"level": "eg"}, "stamp": "s"});
let ops = crate::commands::ops(&r, &crate::model::lenient::typed_for_test(&r), &req.to_string()).unwrap();
ops.iter()
.filter_map(|o| if let Op::Add { items, .. } = o { Some(items) } else { None })
.flatten()
.filter_map(|d| d["geom"]["offset"].as_f64())
.map(f64::abs)
.collect()
};
let (a, b) = (offsets(100.0), offsets(50.0));
assert!(!a.is_empty() && a.len() == b.len());
let (ma, mb) = (a.iter().cloned().fold(0.0, f64::max), b.iter().cloned().fold(0.0, f64::max));
assert!(mb < ma * 0.75, "1:50 {mb} vs 1:100 {ma}");
}
}