Merge commit 'bbef69e' into worktree-agent-a244c57ef64c1f5c9
# Conflicts: # TODO.md # src/plan/__golden__/komplex-grundriss-dg-100.txt # src/plan/__golden__/komplex-grundriss-dg-50.txt # src/plan/__golden__/komplex-grundriss-eg-100.txt # src/plan/__golden__/komplex-grundriss-eg-50.txt # src/plan/__golden__/komplex-grundriss-og-100.txt # src/plan/__golden__/komplex-grundriss-og-50.txt # src/plan/__golden__/komplex-grundriss-ug-100.txt # src/plan/__golden__/komplex-grundriss-ug-50.txt # src/plan/__golden__/muster-grundriss-eg-100.txt # src/plan/__golden__/muster-grundriss-eg-50.txt
This commit is contained in:
25 files changed
+668
-90
No files matched your search
@@ -150,6 +150,10 @@ pub fn plan_context_with(c: &Ctx, out: &mut Vec<Primitive>, drawing_obstacles: &
|
||||
for q in super::drawings::grid_bubble_prims(c) {
|
||||
o.add_prim(&q);
|
||||
}
|
||||
// [157] Baugruben (Sohle, Böschungsoberkante, Böschungsschraffur): keine Höhenkote darauf.
|
||||
for q in out.iter().filter(|q| matches!(q, Primitive::Line { cls, color: Some(k), .. } if cls == "context-line" && k == EXCAVATION_INK)) {
|
||||
o.add_prim(q);
|
||||
}
|
||||
o
|
||||
});
|
||||
terrain_contours(c, t, out, &house(), obst);
|
||||
@@ -247,14 +251,14 @@ pub(super) fn terrain_footprint(p: &Project, floor: &str) -> Vec<Vec<Vec2>> {
|
||||
crate::polygon_bool::union(&parts).into_iter().filter_map(|poly| poly.into_iter().next()).filter(|r| r.len() >= 3).map(|r| r.iter().map(|q| v2(q[0], q[1])).collect()).collect()
|
||||
}
|
||||
|
||||
fn seg_dist(q: Vec2, a: [f64; 2], b: [f64; 2]) -> f64 {
|
||||
pub(super) fn seg_dist(q: Vec2, a: [f64; 2], b: [f64; 2]) -> f64 {
|
||||
let (dx, dy) = (b[0] - a[0], b[1] - a[1]);
|
||||
let l2 = dx * dx + dy * dy;
|
||||
let t = if l2 > 0.0 { (((q.x - a[0]) * dx + (q.y - a[1]) * dy) / l2).clamp(0.0, 1.0) } else { 0.0 };
|
||||
(q.x - a[0] - t * dx).hypot(q.y - a[1] - t * dy)
|
||||
}
|
||||
|
||||
fn inside(q: Vec2, ring: &[Vec2]) -> bool {
|
||||
pub(super) fn inside(q: Vec2, ring: &[Vec2]) -> bool {
|
||||
let mut c = false;
|
||||
let n = ring.len();
|
||||
for i in 0..n {
|
||||
@@ -608,14 +612,18 @@ fn terrain_contours(c: &Ctx, t: &TerrainMesh, out: &mut Vec<Primitive>, house: &
|
||||
}
|
||||
|
||||
/// [68] Baugrube im Grundriss: Sohle (Böschungsfuss) und Böschungsoberkante, Böschungsschraffur.
|
||||
/// [150] Böschungsoberkante und -schraffur (Gelände) enden am Fussabdruck `house`; die Sohle bleibt.
|
||||
/// [150] Böschungsoberkante und -schraffur (Gelände) enden am Fussabdruck `house`; [157] die Sohle auch.
|
||||
fn excavation_lines(c: &Ctx, e: &Excavation, out: &mut Vec<Primitive>, bands: &mut Vec<Primitive>, house: &[Vec<Vec2>]) {
|
||||
let ring: Vec<Vec2> = e.outline.iter().copied().filter(|q| q.x.is_finite() && q.y.is_finite()).collect();
|
||||
if ring.len() < 3 {
|
||||
return;
|
||||
}
|
||||
// [157] Die Sohle endet ebenfalls am Gebäude: wo es über die Grube reicht (Anbau ohne Untergeschoss),
|
||||
// liegt sie unter dem Boden — vorher lief sie als 0.25-mm-Linie quer durch den Raum.
|
||||
for i in 0..ring.len() {
|
||||
out.push(ink_line(ring[i], ring[(i + 1) % ring.len()], 0.25, EXCAVATION_INK, None));
|
||||
for (a, b) in outside(ring[i], ring[(i + 1) % ring.len()], house) {
|
||||
out.push(ink_line(a, b, 0.25, EXCAVATION_INK, None));
|
||||
}
|
||||
}
|
||||
// [137] Pick-Fläche = Wirkbereich (Sohle + Böschungen), ohne Gelände nur die Sohle.
|
||||
let hull = crate::excavation::terrains(c.p).into_iter().map(|t| crate::excavation::affected_hull(&crate::excavation::site_terrain(c.p, t), &e.id)).find(|h| h.len() >= 3);
|
||||
@@ -665,12 +673,18 @@ pub fn plan_section_lines(c: &Ctx, out: &mut Vec<Primitive>) {
|
||||
return;
|
||||
}
|
||||
let greyed = Some(c.greyed(SECTION_LINE_CATEGORY));
|
||||
// [157] Marken und Beschriftung in Papiergrösse (bei 1:100 wie bisher 6 mm Marke, 5 mm Schrift); kleiner als
|
||||
// 1:100 (Situation 1:200/1:500) auf dem Papier mit (100/n)^0.5 kleiner, sonst stehen die Marken ineinander.
|
||||
let n = if c.a.scale.is_finite() && c.a.scale > 0.0 { c.a.scale } else { 100.0 };
|
||||
let k = if n <= 100.0 { n / 100.0 } else { (n / 100.0).sqrt() };
|
||||
for level in &c.p.drawing_levels {
|
||||
if !matches!(level.kind, DrawingLevelKind::Section | DrawingLevelKind::Elevation) {
|
||||
continue;
|
||||
}
|
||||
let Some([p0, p1]) = level.line_points else { continue };
|
||||
let f = crate::plan::misc::section_line(p0.x, p0.y, p1.x, p1.y, level.direction_sign.unwrap_or(1.0));
|
||||
let tag = section_label_tag(&level.name);
|
||||
let label_w = crate::text_layout::text_width_em(&tag, false) * SECTION_LABEL_H * k;
|
||||
let f = crate::plan::misc::section_line_sized(p0.x, p0.y, p1.x, p1.y, level.direction_sign.unwrap_or(1.0), k, label_w);
|
||||
if f.is_empty() {
|
||||
continue;
|
||||
}
|
||||
@@ -698,8 +712,8 @@ pub fn plan_section_lines(c: &Ctx, out: &mut Vec<Primitive>) {
|
||||
} else if f[i] == 5.0 {
|
||||
out.push(Primitive::DrawingText {
|
||||
at: v2(f[i + 1], f[i + 2]),
|
||||
text: section_label_tag(&level.name),
|
||||
height_m: SECTION_LABEL_H,
|
||||
text: tag.clone(),
|
||||
height_m: SECTION_LABEL_H * k,
|
||||
angle: 0.0,
|
||||
color: SECTION_LINE_INK.into(),
|
||||
marks: None,
|
||||
@@ -769,6 +783,57 @@ mod tests {
|
||||
assert_eq!(top_context(&out, -30.0, 0.0), None);
|
||||
}
|
||||
|
||||
/// [157] Schnitt-/Ansichtsmarken in Papiergrösse (1:50 wie 1:100, 1:500 um √5 kleiner statt 1/5), die
|
||||
/// Beschriftung steht vor der Pfeilspitze (auch bei senkrechtem Pfeil nicht auf dem Pfeil, „Nord“ oben) und
|
||||
/// zählt zum Ausmass des Plans (oben nicht abgeschnitten).
|
||||
#[test]
|
||||
fn schnittmarken_papiergroesse_beschriftung_frei() {
|
||||
let level = |name: &str, a: [f64; 2], b: [f64; 2]| -> DrawingLevel {
|
||||
serde_json::from_value(serde_json::json!({ "id": name, "name": name, "kind": "elevation", "visible": true, "locked": false,
|
||||
"linePoints": [{ "x": a[0], "y": a[1] }, { "x": b[0], "y": b[1] }] })).unwrap()
|
||||
};
|
||||
// Pfeil nach unten (Ansicht Nord, oben im Plan) und nach links/rechts.
|
||||
let p = Project { drawing_levels: vec![level("Ansicht Nord", [10.0, 20.0], [0.0, 20.0]), level("Ansicht West", [-5.0, 10.0], [-5.0, 0.0]), level("Ansicht Ost", [15.0, 0.0], [15.0, 10.0])], ..Default::default() };
|
||||
let run = |scale: f64| {
|
||||
let a = super::super::domains::PlanArgs::parse(1.0, &format!(r#"{{"show": ["90"], "scale": {scale}, "global": true}}"#)).unwrap();
|
||||
let mut out = Vec::new();
|
||||
plan_section_lines(&Ctx::new(&p, &a), &mut out);
|
||||
out
|
||||
};
|
||||
let marks = |out: &[Primitive]| -> Vec<(Vec2, Vec2)> { out.iter().filter_map(|q| match q { Primitive::Line { a, b, dash: None, .. } => Some((*a, *b)), _ => None }).collect() };
|
||||
let len = |m: &[(Vec2, Vec2)]| m.iter().map(|(a, b)| (b.x - a.x).hypot(b.y - a.y)).fold(0.0, f64::max);
|
||||
// 1:50 gleich gross auf dem Papier (halb im Modell), 1:500 auf dem Papier um (1/5)^0.5 kleiner.
|
||||
let (m50, m100, m500) = (marks(&run(50.0)), marks(&run(100.0)), marks(&run(500.0)));
|
||||
assert!((len(&m50) / len(&m100) - 0.5).abs() < 1e-9, "{} {}", len(&m50), len(&m100));
|
||||
assert!((len(&m500) / len(&m100) - 5.0f64.sqrt()).abs() < 1e-9, "{} {}", len(&m100), len(&m500));
|
||||
for scale in [100.0, 500.0] {
|
||||
let out = run(scale);
|
||||
let m = marks(&out);
|
||||
for q in &out {
|
||||
let Primitive::DrawingText { at, text, height_m, .. } = q else { continue };
|
||||
// Schriftkasten (Inter-Breite, Versalhöhe 0.75) gegen alle Markenstriche.
|
||||
let w = crate::text_layout::text_width_em(text, false) * height_m;
|
||||
let (x0, y0, x1, y1) = (at.x, at.y, at.x + w, at.y + 0.75 * height_m);
|
||||
for (a, b) in &m {
|
||||
for k in 0..=20 {
|
||||
let t = k as f64 / 20.0;
|
||||
let (x, y) = (a.x + (b.x - a.x) * t, a.y + (b.y - a.y) * t);
|
||||
assert!(!(x > x0 && x < x1 && y > y0 && y < y1), "1:{scale} {text} {at:?} auf Strich {a:?}–{b:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
// Ausmass des Plans umfasst die Beschriftung der Ansicht Nord (über y = 20).
|
||||
let a = super::super::domains::PlanArgs::parse(1.0, r#"{"show": ["90"], "scale": 100, "global": true}"#).unwrap();
|
||||
let d = super::super::domains::plan_domains(&p, &a).unwrap();
|
||||
let top = out_top(&run(100.0));
|
||||
assert!(d.bounds.is_some_and(|b| b[3] >= top - 1e-9), "{:?} < {top}", d.bounds);
|
||||
}
|
||||
|
||||
fn out_top(out: &[Primitive]) -> f64 {
|
||||
out.iter().filter_map(|q| if let Primitive::DrawingText { at, height_m, .. } = q { Some(at.y + height_m) } else { None }).fold(f64::NEG_INFINITY, f64::max)
|
||||
}
|
||||
|
||||
/// [140] Höhenlinien enden an der Gebäudegrundfläche (Wände vereinigt, ganzer Aussenring).
|
||||
#[test]
|
||||
fn hoehenlinien_enden_am_gebaeude() {
|
||||
@@ -933,6 +998,56 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// [157] Die Sohle der Baugrube liegt unter dem Gebäude, wo es über die Grube reicht (Eingangs-Anbau ohne
|
||||
/// Untergeschoss): dort keine Sohlenlinie quer durch den Raum (vorher 0.25 mm durch „E.07 Eingang“);
|
||||
/// ausserhalb des Gebäudes bleibt sie.
|
||||
#[test]
|
||||
fn baugrubensohle_endet_am_gebaeude() {
|
||||
let mut p = sample_with_walls(serde_json::json!([
|
||||
["h1", "eg", 14.0, 0.0, 26.0, 0.0], ["h2", "eg", 26.0, 0.0, 26.0, 8.0], ["h3", "eg", 26.0, 8.0, 14.0, 8.0], ["h4", "eg", 14.0, 8.0, 14.0, 0.0],
|
||||
["a1", "eg", 18.5, 8.0, 18.5, 12.0], ["a2", "eg", 18.5, 12.0, 21.5, 12.0], ["a3", "eg", 21.5, 12.0, 21.5, 8.0]
|
||||
]));
|
||||
// Grube mit Arbeitsraum: Nordrand bei y = 10 läuft durch den Anbau.
|
||||
let pit = Excavation { id: "bg".into(), outline: vec![v2(12.0, -2.0), v2(28.0, -2.0), v2(28.0, 10.0), v2(12.0, 10.0)], bottom: -3.0, ..Default::default() };
|
||||
p.context = Some(vec![ContextObject::Excavation(pit)]);
|
||||
let a = super::super::domains::PlanArgs::parse(1.0, r#"{"floor": "eg", "scale": 100}"#).unwrap();
|
||||
let mut out = Vec::new();
|
||||
plan_context(&Ctx::new(&p, &a), &mut out);
|
||||
let sohle: Vec<(Vec2, Vec2)> = out.iter().filter_map(|q| match q { Primitive::Line { a, b, color: Some(c), weight_mm, .. } if c == EXCAVATION_INK && (*weight_mm - 0.25).abs() < 1e-9 => Some((*a, *b)), _ => None }).collect();
|
||||
let north: Vec<&(Vec2, Vec2)> = sohle.iter().filter(|(a, b)| (a.y - 10.0).abs() < 1e-9 && (b.y - 10.0).abs() < 1e-9).collect();
|
||||
assert!(north.iter().any(|(a, b)| a.x.min(b.x) < 13.0), "Sohle ausserhalb fehlt: {north:?}");
|
||||
for (a, b) in &north {
|
||||
let m = (a.x + b.x) / 2.0;
|
||||
assert!(!(m > 18.5 && m < 21.5), "Sohle im Anbau: {a:?}–{b:?}");
|
||||
}
|
||||
assert_eq!(sohle.iter().filter(|(a, b)| (a.x - 12.0).abs() < 1e-9 && (b.x - 12.0).abs() < 1e-9).count(), 1, "Westrand ganz");
|
||||
}
|
||||
|
||||
/// [157] Höhenkoten nicht auf der Baugrube: die Beschriftung einer Höhenlinie liegt nicht auf Sohle,
|
||||
/// Böschungsoberkante oder Böschungsschraffur (vorher „-2.5“/„-2.2“ in der Böschung, Musterhaus komplex EG).
|
||||
#[test]
|
||||
fn hoehenkoten_nicht_auf_der_baugrube() {
|
||||
let t = TerrainMesh { id: "t".into(), positions: vec![0.0, 0.0, 0.0, 60.0, 0.0, 6.0, 60.0, 40.0, 6.0, 0.0, 40.0, 0.0], indices: vec![0.0, 1.0, 2.0, 0.0, 2.0, 3.0], contour_interval: Some(0.1), ..Default::default() };
|
||||
let pit = Excavation { id: "bg".into(), outline: vec![v2(20.0, 5.0), v2(40.0, 5.0), v2(40.0, 35.0), v2(20.0, 35.0)], bottom: 0.5, ..Default::default() };
|
||||
let p = Project { context: Some(vec![ContextObject::Excavation(pit), ContextObject::TerrainMesh(t)]), ..Default::default() };
|
||||
let a = super::super::domains::PlanArgs::parse(1.0, r#"{"show": ["02"], "scale": 100}"#).unwrap();
|
||||
let mut out = Vec::new();
|
||||
plan_context(&Ctx::new(&p, &a), &mut out);
|
||||
let pit_lines: Vec<(Vec2, Vec2)> = out.iter().filter_map(|q| match q { Primitive::Line { a, b, color: Some(c), .. } if c == EXCAVATION_INK => Some((*a, *b)), _ => None }).collect();
|
||||
let labels: Vec<(String, Vec<[f64; 2]>)> = out.iter().filter_map(label_rect).collect();
|
||||
assert!(!pit_lines.is_empty() && !labels.is_empty(), "{} {}", pit_lines.len(), labels.len());
|
||||
for (t, r) in &labels {
|
||||
let flat: Vec<f64> = r.iter().flat_map(|q| [q[0], q[1]]).collect();
|
||||
for (a, b) in &pit_lines {
|
||||
for k in 0..=20 {
|
||||
let f = k as f64 / 20.0;
|
||||
let (x, y) = (a.x + (b.x - a.x) * f, a.y + (b.y - a.y) * f);
|
||||
assert!(!crate::plan::pick::point_in_polygon(x, y, &flat), "Kote {t} auf der Baugrube: {a:?}–{b:?}");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// [150] Beschriftungen der Höhenlinien überdecken sich nicht (auch wo die Zähllinien eng liegen), halten
|
||||
/// Abstand entlang der Linie und liegen nicht auf der Bemassung.
|
||||
#[test]
|
||||
|
||||
@@ -848,7 +848,7 @@ fn abbreviate(text: &str, n: usize) -> String {
|
||||
}
|
||||
|
||||
/// [140] Hindernisse für Raumstempel aus den schon erzeugten Domänen: Treppen (alle Striche), Türschwenk-Bögen,
|
||||
/// Stützen, Beschriftungen des Kontexts (Höhenlinien-Koten) und die Zeichnungen, denen Stempel ausweichen
|
||||
/// Stützen, Beschriftungen des Kontexts (Höhenlinien-Koten), Schnittführungen ([157]) und die Zeichnungen, denen Stempel ausweichen
|
||||
/// (Bemassung, Koten, Texte, Symbole; `drawings::stamp_obstacle_prims`).
|
||||
#[cfg(test)]
|
||||
fn stamp_obstacles(c: &Ctx, d: &DomainPrims) -> super::stamp_place::Obstacles {
|
||||
@@ -881,6 +881,12 @@ fn stamp_obstacles_with(d: &DomainPrims, drawn: super::stamp_place::Obstacles) -
|
||||
o.add_prim(q);
|
||||
}
|
||||
}
|
||||
// [157] Schnittführungen (Linie, Marken, Beschriftung): der Stempel steht neben der Linie, nicht darauf.
|
||||
for q in &d.sections {
|
||||
if matches!(q, Primitive::Line { .. } | Primitive::DrawingText { .. }) {
|
||||
o.add_prim(q);
|
||||
}
|
||||
}
|
||||
o
|
||||
}
|
||||
|
||||
@@ -1222,6 +1228,20 @@ fn domains_after(c: &Ctx, out: &mut DomainPrims, bounds: &mut Bounds) {
|
||||
if c.a.global {
|
||||
// [150] Schnittführungen zuerst: ihre Beschriftungen sind Hindernisse der Höhenlinien-Beschriftungen.
|
||||
super::context::plan_section_lines(c, &mut out.sections);
|
||||
// [157] Marken und Beschriftungen der Schnittführungen gehören zum Ausmass (sonst oben abgeschnitten).
|
||||
for q in &out.sections {
|
||||
match q {
|
||||
Primitive::Line { a, b, .. } => {
|
||||
bounds.acc(a.x, a.y);
|
||||
bounds.acc(b.x, b.y);
|
||||
}
|
||||
Primitive::DrawingText { at, text, height_m, .. } => {
|
||||
bounds.acc(at.x, at.y);
|
||||
bounds.acc(at.x + crate::text_layout::text_width_em(text, false) * height_m, at.y + height_m);
|
||||
}
|
||||
_ => {}
|
||||
}
|
||||
}
|
||||
let mut o = drawn.clone();
|
||||
for q in out.sections.iter().filter(|q| matches!(q, Primitive::DrawingText { .. })) {
|
||||
o.add_prim(q);
|
||||
@@ -1631,6 +1651,34 @@ mod tests {
|
||||
assert_eq!(stamp(&p).0, pole);
|
||||
}
|
||||
|
||||
/// [157] Schnittführung quer durch den Raum: der Stempel steht neben der strichpunktierten Linie, nicht
|
||||
/// darauf (vorher lief „A-A“ durch Raumnamen und Fläche, Musterhaus komplex OG/DG).
|
||||
#[test]
|
||||
fn raumstempel_weicht_schnittlinie_aus() {
|
||||
let mut p = sample();
|
||||
let r = p.rooms.as_mut().unwrap().iter_mut().find(|r| r.floor_id == "eg").unwrap();
|
||||
let q = [(0.0, 0.0), (7.0, 0.0), (7.0, 5.0), (0.0, 5.0)];
|
||||
r.boundary = q.iter().map(|&(x, y)| Vec2 { x: x + 50.0, y: y + 50.0 }).collect();
|
||||
r.stamp_anchor = None;
|
||||
r.stamp = None;
|
||||
let id = r.id.clone();
|
||||
p.drawing_levels.retain(|l| !matches!(l.kind, DrawingLevelKind::Section | DrawingLevelKind::Elevation));
|
||||
let t = serde_json::json!({ "floor": "eg", "show": ["20", "60", "80", "90"], "grey": [], "scale": 100, "global": true }).to_string();
|
||||
let a = PlanArgs::parse(1.0, &t).unwrap();
|
||||
let stamp = |p: &Project| {
|
||||
let out = plan_domains(p, &a).unwrap();
|
||||
out.rooms.iter().find_map(|q| match q { Primitive::Text { at, room_id: Some(rid), doc, extra_lines, base_pt, .. } if *rid == id => Some((*at, doc.clone(), extra_lines.clone(), *base_pt)), _ => None }).unwrap()
|
||||
};
|
||||
let (pole, ..) = stamp(&p);
|
||||
// Schnitt A-A senkrecht durch den Pol (x = 53.5), über den Raum hinaus.
|
||||
let level: DrawingLevel = serde_json::from_value(serde_json::json!({ "id": "sx", "name": "Schnitt A-A", "kind": "section", "visible": true, "locked": false,
|
||||
"linePoints": [{ "x": 53.5, "y": 44.0 }, { "x": 53.5, "y": 61.0 }] })).unwrap();
|
||||
p.drawing_levels.push(level);
|
||||
let (at, doc, extra, pt) = stamp(&p);
|
||||
let (w, _) = stamp_size_m(&doc, &extra, pt, 100.0);
|
||||
assert!((at.x - 53.5).abs() > w / 2.0, "Stempel auf der Schnittlinie: {at:?} (Pol {pole:?}, Breite {w})");
|
||||
}
|
||||
|
||||
/// [140] Teil 6: Treppe und Türschwenk sind Hindernisse (Strecken bzw. Sektor), Bogenwände nicht.
|
||||
#[test]
|
||||
fn stempel_hindernisse_aus_domaenen() {
|
||||
|
||||
@@ -856,15 +856,19 @@ fn emit_inner(c: &Ctx, d: &Drawing2D, attrs: Attrs, geom: &Drawing2DGeom, greyed
|
||||
i += 1.0;
|
||||
}
|
||||
let mut i = 0.0;
|
||||
let mut labels: Vec<(f64, String)> = Vec::new();
|
||||
while i <= *segments {
|
||||
let x = at.x + i * segment_length;
|
||||
em.seg(v(x, at.y), v(x, at.y - tick_len));
|
||||
let dist = i * segment_length;
|
||||
let dist_text = if dist.is_finite() && dist.trunc() == dist { js_number(dist) } else { to_fixed(dist, 2) };
|
||||
let label = if i == *segments { format!("{dist_text}m") } else { dist_text };
|
||||
em.text(v(x + text_h * 0.25, at.y - tick_len - text_h * 1.2), label, text_h);
|
||||
labels.push((i, label));
|
||||
i += 1.0;
|
||||
}
|
||||
for (i, label) in scalebar_labels(labels, segment_length.abs(), text_h) {
|
||||
em.text(v(at.x + i * segment_length + text_h * 0.25, at.y - tick_len - text_h * 1.2), label, text_h);
|
||||
}
|
||||
}
|
||||
Drawing2DGeom::Pointmarker { at } => {
|
||||
let f = symbol_factor_at(p, &d.level_id, scale);
|
||||
@@ -1007,6 +1011,56 @@ fn dimension_segment(em: &mut Em, a: Vec2, b: Vec2, offset: f64, st: &DimStyle)
|
||||
}
|
||||
|
||||
/// Achsraster ([112]): Achsen strichpunktiert, an den Enden Blasen mit der Beschriftung.
|
||||
/// [157] Beschriftungen des Massstabsbalkens (Teilstrich-Index, Text), ausgedünnt: liegen die Teilstriche
|
||||
/// (`seg` Modell-m) enger als eine Zahl breit ist (Schrift `text_h`, Inter-Metrik + 0.4 Schrifthöhe Luft),
|
||||
/// nur jeder k-te (k = 1, 2, 5, 10 …); 0 und das Ende („…m“) immer, die Zahl vor dem Ende entfällt, wenn sie
|
||||
/// sonst hineinragt.
|
||||
fn scalebar_labels(labels: Vec<(f64, String)>, seg: f64, text_h: f64) -> Vec<(f64, String)> {
|
||||
let width = |s: &str| crate::text_layout::text_width_em(s, false) * text_h + 0.4 * text_h;
|
||||
let Some(last) = labels.last().map(|l| l.0) else { return labels };
|
||||
if !(seg > 0.0) || !seg.is_finite() {
|
||||
return labels;
|
||||
}
|
||||
let need = labels.iter().filter(|l| l.0 < last).map(|l| width(&l.1)).fold(0.0, f64::max);
|
||||
let k = [1.0, 2.0, 5.0, 10.0, 20.0, 50.0, 100.0, 200.0, 500.0].into_iter().find(|k| k * seg >= need).unwrap_or(last.max(1.0));
|
||||
let mut out: Vec<(f64, String)> = labels.into_iter().filter(|l| l.0 % k == 0.0 || l.0 == last).collect();
|
||||
// Vor dem Ende: die vorletzte Zahl muss neben dem Ende Platz haben (sonst weg, ausser der 0).
|
||||
while out.len() >= 2 {
|
||||
let (j, ref s) = out[out.len() - 2];
|
||||
if (last - j) * seg >= width(s) || j == 0.0 {
|
||||
break;
|
||||
}
|
||||
out.remove(out.len() - 2);
|
||||
}
|
||||
// Reicht der ganze Balken nicht für „0“ und das Ende: nur das Ende.
|
||||
if out.len() == 2 && out[0].0 == 0.0 && last * seg < width(&out[0].1) {
|
||||
out.remove(0);
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// [157] Wie weit die Blase (Radius `r`) am Achsende `end` in Richtung `dir` hinaus muss, damit sie mit Luft
|
||||
/// (10 % des Radius) ausserhalb jedes Gebäuderings liegt; 0, wenn sie schon frei ist (höchstens 60 m).
|
||||
fn bubble_shift(end: Vec2, dir: Vec2, r: f64, house: &[Vec<Vec2>]) -> f64 {
|
||||
if !(r > 0.0) || house.is_empty() || !(end.x.is_finite() && end.y.is_finite() && dir.x.is_finite() && dir.y.is_finite()) {
|
||||
return 0.0;
|
||||
}
|
||||
let clear = |c: Vec2| {
|
||||
house.iter().all(|ring| {
|
||||
!super::context::inside(c, ring) && (0..ring.len()).all(|k| super::context::seg_dist(c, [ring[k].x, ring[k].y], [ring[(k + 1) % ring.len()].x, ring[(k + 1) % ring.len()].y]) > r * 1.1)
|
||||
})
|
||||
};
|
||||
let step = r / 4.0;
|
||||
let mut t = 0.0;
|
||||
while t <= 60.0 {
|
||||
if clear(v(end.x + dir.x * (t + r), end.y + dir.y * (t + r))) {
|
||||
return t;
|
||||
}
|
||||
t += step;
|
||||
}
|
||||
0.0
|
||||
}
|
||||
|
||||
fn emit_grid(em: &mut Em, spec: &crate::grid::Spec, diameter: f64, house: &[Vec<Vec2>]) {
|
||||
use crate::grid::Shape;
|
||||
// [153] Achsen strichpunktiert in Papier-mm (vorher mit dem Massstab in Modell-Meter vorskaliert).
|
||||
@@ -1015,12 +1069,35 @@ fn emit_grid(em: &mut Em, spec: &crate::grid::Spec, diameter: f64, house: &[Vec<
|
||||
let w = jsnum::min(em.weight, XLINE_WEIGHT_MM.max(0.18));
|
||||
let r = diameter / 2.0;
|
||||
let text_h = diameter * 0.5;
|
||||
for ax in spec.axes() {
|
||||
// [157] Blasen vor das Gebäude: endet eine gerade Achse im Gebäude (Anbau über die Rasterlinie), rückt
|
||||
// ihre Blase entlang der Achse hinaus; alle Blasen derselben Seite (gleiche Richtung) gleich weit.
|
||||
let axes = spec.axes();
|
||||
let side = |d: (f64, f64)| ((d.0 * 1e3).round() as i64, (d.1 * 1e3).round() as i64);
|
||||
let mut shift: HashMap<(i64, i64), f64> = HashMap::new();
|
||||
for ax in axes.iter().filter(|ax| matches!(ax.shape, Shape::Line { .. })) {
|
||||
for (end, dir) in ax.bubbles.iter().flatten() {
|
||||
let t = bubble_shift(v(end.0, end.1), v(dir.0, dir.1), r, house);
|
||||
let e = shift.entry(side(*dir)).or_insert(0.0);
|
||||
*e = e.max(t);
|
||||
}
|
||||
}
|
||||
for ax in axes {
|
||||
let line = matches!(ax.shape, Shape::Line { .. });
|
||||
let shift_of = |dir: (f64, f64)| if line { shift.get(&side(dir)).copied().unwrap_or(0.0) } else { 0.0 };
|
||||
match ax.shape {
|
||||
Shape::Line { a, b } => {
|
||||
for (p0, p1) in super::context::outside(v(a.0, a.1), v(b.0, b.1), house) {
|
||||
em.line(p0, p1, w, Some(&dash), dash_ref);
|
||||
}
|
||||
// Verlängerung bis zur hinausgerückten Blase (nur ausserhalb des Gebäudes).
|
||||
for (end, dir) in ax.bubbles.iter().flatten() {
|
||||
let t = shift_of(*dir);
|
||||
if t > 0.0 {
|
||||
for (p0, p1) in super::context::outside(v(end.0, end.1), v(end.0 + dir.0 * t, end.1 + dir.1 * t), house) {
|
||||
em.line(p0, p1, w, Some(&dash), dash_ref);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
Shape::Arc { c, r: rad, a0, a1 } => {
|
||||
let dash_v = Some(dash.to_vec());
|
||||
@@ -1038,7 +1115,8 @@ fn emit_grid(em: &mut Em, spec: &crate::grid::Spec, diameter: f64, house: &[Vec<
|
||||
}
|
||||
}
|
||||
for (end, dir) in ax.bubbles.iter().flatten() {
|
||||
let c = v(end.0 + dir.0 * r, end.1 + dir.1 * r);
|
||||
let t = shift_of(*dir);
|
||||
let c = v(end.0 + dir.0 * (t + r), end.1 + dir.1 * (t + r));
|
||||
em.circle(c, r, "none", Some(None));
|
||||
let n = ax.label.chars().count() as f64;
|
||||
em.text(v(c.x - text_h * 0.3 * n, c.y - text_h * 0.35), ax.label.clone(), text_h);
|
||||
@@ -1869,6 +1947,62 @@ mod tests {
|
||||
assert_eq!(prims.iter().filter(|q| matches!(q, Primitive::DrawingCircle { .. })).count(), 8, "Blasen bleiben");
|
||||
}
|
||||
|
||||
/// [157] Blasen gehören vor das Gebäude: endet eine Achse im Gebäude (Anbau über die Rasterlinie), rückt
|
||||
/// die Blase entlang der Achse nach aussen, alle Blasen derselben Seite gleich weit (eine Reihe), die Achse
|
||||
/// läuft ausserhalb bis zur Blase; Blasen, die schon frei liegen, bleiben auf der Reihe.
|
||||
#[test]
|
||||
fn achsblasen_ausserhalb_des_gebaeudes() {
|
||||
// Anbau 1.5..3.5 × 3..6.5: das obere Ende von Achse 2 (x = 2.5, extend 1 → y = 5) liegt darin.
|
||||
let p = project(serde_json::json!({"extrudedSolids": [{"id": "s", "type": "extrudedSolid", "levelId": "eg", "height": 3,
|
||||
"points": [{"x": 1.5, "y": 3}, {"x": 3.5, "y": 3}, {"x": 3.5, "y": 6.5}, {"x": 1.5, "y": 6.5}]}]}));
|
||||
let grid = drawing(serde_json::json!({"shape": "grid", "origin": {"x": 0, "y": 0}, "angle": 0,
|
||||
"a": [{"label": "1", "pos": 0}, {"label": "2", "pos": 2.5}, {"label": "3", "pos": 5}], "b": [{"label": "A", "pos": 0}, {"label": "B", "pos": 4}], "extend": 1}));
|
||||
let prims = render(&p, grid, 100.0);
|
||||
let circles: Vec<(Vec2, f64)> = prims.iter().filter_map(|q| if let Primitive::DrawingCircle { center, r, .. } = q { Some((*center, *r)) } else { None }).collect();
|
||||
assert_eq!(circles.len(), 10);
|
||||
let inside = |q: Vec2, r: f64| q.x + r > 1.5 && q.x - r < 3.5 && q.y + r > 3.0 && q.y - r < 6.5;
|
||||
for (c, r) in &circles {
|
||||
assert!(!inside(*c, *r), "Blase im Gebäude: {c:?}");
|
||||
}
|
||||
// Obere Reihe (Achsen 1–3) auf einer Höhe über dem Anbau.
|
||||
let top: Vec<f64> = circles.iter().filter(|(c, _)| c.y > 4.5).map(|(c, _)| c.y).collect();
|
||||
assert_eq!(top.len(), 3, "{circles:?}");
|
||||
assert!(top.iter().all(|y| (y - top[0]).abs() < 1e-9 && *y > 6.5), "{top:?}");
|
||||
// Untere Reihe unverändert (y = -1 − r).
|
||||
assert!(circles.iter().filter(|(c, _)| c.y < 0.0).all(|(c, r)| (c.y - (-1.0 - r)).abs() < 1e-9));
|
||||
// Achse 2 läuft oberhalb des Anbaus bis an die Blase.
|
||||
let segs: Vec<(Vec2, Vec2)> = prims.iter().filter_map(|q| match q { Primitive::Line { a, b, dash: Some(Some(_)), .. } => Some((*a, *b)), _ => None }).collect();
|
||||
let r = circles[0].1;
|
||||
assert!(segs.iter().any(|(a, b)| (a.x - 2.5).abs() < 1e-9 && (a.y.max(b.y) - (top[0] - r)).abs() < 1e-6 && a.y.min(b.y) >= 6.5 - 1e-9), "{segs:?}");
|
||||
}
|
||||
|
||||
/// [157] Massstabsbalken im kleinen Massstab: die Zahlen (3 mm Papier) stehen nicht ineinander — liegen
|
||||
/// die Teilstriche enger als eine Beschriftung, wird nur jede k-te beschriftet (immer 0 und das Ende mit „m“).
|
||||
#[test]
|
||||
fn massstabsbalken_zahlen_ueberlappen_nicht() {
|
||||
let p = project(serde_json::json!({}));
|
||||
let bar = drawing(serde_json::json!({"shape": "scalebar", "at": {"x": 0, "y": 0}, "segmentLength": 1, "segments": 5}));
|
||||
let labels = |scale: f64| -> Vec<(f64, String, f64)> {
|
||||
render(&p, bar.clone(), scale).iter().filter_map(|q| if let Primitive::DrawingText { at, text, height_m, .. } = q { Some((at.x, text.clone(), *height_m)) } else { None }).collect()
|
||||
};
|
||||
// 1:100: 1 m = 10 mm Papier, alle sechs Zahlen.
|
||||
assert_eq!(labels(100.0).iter().map(|l| l.1.as_str()).collect::<Vec<_>>(), ["0", "1", "2", "3", "4", "5m"]);
|
||||
// 1:500: 1 m = 2 mm Papier — jede zweite Zahl, die 4 entfällt neben „5m“; nichts überlappt.
|
||||
let l = labels(500.0);
|
||||
assert_eq!(l.iter().map(|l| l.1.as_str()).collect::<Vec<_>>(), ["0", "2", "5m"], "{l:?}");
|
||||
for w in l.windows(2) {
|
||||
let width = crate::text_layout::text_width_em(&w[0].1, false) * w[0].2;
|
||||
assert!(w[1].0 - w[0].0 > width, "{l:?}");
|
||||
}
|
||||
// 1:200: 1 m = 5 mm Papier — 0 vorne, „5m“ am Ende, nichts überlappt.
|
||||
let l = labels(200.0);
|
||||
assert!(l.first().is_some_and(|x| x.1 == "0") && l.last().is_some_and(|x| x.1 == "5m"), "{l:?}");
|
||||
for w in l.windows(2) {
|
||||
let width = crate::text_layout::text_width_em(&w[0].1, false) * w[0].2;
|
||||
assert!(w[1].0 - w[0].0 > width, "{l:?}");
|
||||
}
|
||||
}
|
||||
|
||||
/// [112] Raster erscheint in jedem Geschoss, bei `levels` nur in den genannten.
|
||||
#[test]
|
||||
fn achsraster_je_geschoss() {
|
||||
|
||||
@@ -11,7 +11,7 @@
|
||||
//! bei zu kurzer Linie):
|
||||
//! ```text
|
||||
//! 2 line [2, art (0 Hauptlinie | 1 Marke), ax, ay, bx, by]
|
||||
//! 5 label [5, x, y] (Kurz-Tag setzt TS)
|
||||
//! 5 label [5, x, y] (unten links; Kurz-Tag setzt der Aufrufer)
|
||||
//! 1 polygon [1, x0, y0 … x3, y3] (unsichtbares Pick-Band)
|
||||
//! ```
|
||||
//!
|
||||
@@ -135,9 +135,18 @@ pub fn bbox(positions: &[f64]) -> Vec<f64> {
|
||||
}
|
||||
|
||||
pub fn section_line(p0x: f64, p0y: f64, p1x: f64, p1y: f64, sign: f64) -> Vec<f64> {
|
||||
if ![p0x, p0y, p1x, p1y, sign].iter().all(|x| x.is_finite()) {
|
||||
section_line_sized(p0x, p0y, p1x, p1y, sign, 1.0, SECTION_LABEL_H * 1.5)
|
||||
}
|
||||
|
||||
/// [157] Wie [`section_line`], Marken × `k` (Papiergrösse: Massstab/100) und die Beschriftung (Breite
|
||||
/// `label_w`, Schrift `SECTION_LABEL_H · k`, Ankerpunkt unten links) mit ihrem Kasten vor der Pfeilspitze —
|
||||
/// in Pfeilrichtung abgesetzt, so dass sie den Pfeil in keiner Richtung überdeckt.
|
||||
pub fn section_line_sized(p0x: f64, p0y: f64, p1x: f64, p1y: f64, sign: f64, k: f64, label_w: f64) -> Vec<f64> {
|
||||
if ![p0x, p0y, p1x, p1y, sign, k, label_w].iter().all(|x| x.is_finite()) || !(k > 0.0) {
|
||||
return Vec::new();
|
||||
}
|
||||
let mark = SECTION_MARK_LEN * k;
|
||||
let label_h = SECTION_LABEL_H * k * 0.75;
|
||||
let (ax, ay) = (p1x - p0x, p1y - p0y);
|
||||
let len = hypot2(ax, ay);
|
||||
if len < 1e-6 {
|
||||
@@ -153,19 +162,20 @@ pub fn section_line(p0x: f64, p0y: f64, p1x: f64, p1y: f64, sign: f64) -> Vec<f6
|
||||
*n += 1;
|
||||
};
|
||||
line(&mut o, &mut n, 0.0, (p0x, p0y), (p1x, p1y));
|
||||
let half = SECTION_MARK_LEN / 2.0;
|
||||
let half = mark / 2.0;
|
||||
for end in [(p0x, p0y), (p1x, p1y)] {
|
||||
line(&mut o, &mut n, 1.0, (end.0 - nx * half, end.1 - ny * half), (end.0 + nx * half, end.1 + ny * half));
|
||||
let base = (end.0 + bnx * half, end.1 + bny * half);
|
||||
let tip = (base.0 + bnx * SECTION_MARK_LEN, base.1 + bny * SECTION_MARK_LEN);
|
||||
let wing_back = (tip.0 - bnx * SECTION_MARK_LEN * 0.4, tip.1 - bny * SECTION_MARK_LEN * 0.4);
|
||||
let w = SECTION_MARK_LEN * 0.25;
|
||||
let tip = (base.0 + bnx * mark, base.1 + bny * mark);
|
||||
let wing_back = (tip.0 - bnx * mark * 0.4, tip.1 - bny * mark * 0.4);
|
||||
let w = mark * 0.25;
|
||||
line(&mut o, &mut n, 1.0, base, tip);
|
||||
line(&mut o, &mut n, 1.0, tip, (wing_back.0 + ux * w, wing_back.1 + uy * w));
|
||||
line(&mut o, &mut n, 1.0, tip, (wing_back.0 - ux * w, wing_back.1 - uy * w));
|
||||
let lx = tip.0 + bnx * SECTION_MARK_LEN * 0.4 - SECTION_LABEL_H * 0.3;
|
||||
let ly = tip.1 + bny * SECTION_MARK_LEN * 0.4 + SECTION_LABEL_H * 0.5;
|
||||
o.extend([5.0, lx, ly]);
|
||||
// Kastenmitte vor der Spitze: Abstand + halbe Ausdehnung des Kastens in Pfeilrichtung.
|
||||
let reach = mark * 0.3 + bnx.abs() * label_w / 2.0 + bny.abs() * label_h / 2.0;
|
||||
let (cx, cy) = (tip.0 + bnx * reach, tip.1 + bny * reach);
|
||||
o.extend([5.0, cx - label_w / 2.0, cy - label_h / 2.0]);
|
||||
n += 1;
|
||||
}
|
||||
let (ox, oy) = (nx * SECTION_PICK_HALF, ny * SECTION_PICK_HALF);
|
||||
|
||||
@@ -217,6 +217,7 @@ fn split_alpha(color: &str) -> (String, Option<String>) {
|
||||
|
||||
fn poly_node(pts: &str, fill: &str, stroke: &str, stroke_mm: f64) -> Vec<(&'static str, String)> {
|
||||
let (fill, fill_opacity) = split_alpha(fill);
|
||||
let opaque = fill_opacity.is_none();
|
||||
let mut a = vec![("points", pts.to_string()), ("fill", fill)];
|
||||
if let Some(o) = fill_opacity {
|
||||
a.push(("fill-opacity", o));
|
||||
@@ -224,6 +225,10 @@ fn poly_node(pts: &str, fill: &str, stroke: &str, stroke_mm: f64) -> Vec<(&'stat
|
||||
if stroke != "none" && stroke_mm > 0.0 {
|
||||
a.push(("stroke", stroke.to_string()));
|
||||
a.push(("stroke-width", js_number(stroke_mm)));
|
||||
} else if opaque && super::svg::seam_fill(&a[1].1) {
|
||||
// [157] Dunkle, deckende Fläche: Haarstrich in der Füllfarbe gegen die Fuge zur Nachbarfläche.
|
||||
a.push(("stroke", a[1].1.clone()));
|
||||
a.push(("stroke-width", js_number(super::svg::SEAM_MM)));
|
||||
} else {
|
||||
a.push(("stroke", "none".to_string()));
|
||||
}
|
||||
@@ -702,6 +707,17 @@ pub fn print_svg_ops(parts: &mut [Part], o: &PrintOptions) -> Option<String> {
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
#[test]
|
||||
fn schwarze_flaeche_mit_haarstrich() {
|
||||
// [157] Dunkle deckende Fläche ohne Strich: Haarstrich in der Füllfarbe (keine helle Fuge im PDF).
|
||||
let a = poly_node("0,0 1,0 1,1", "#0f0f0f", "none", 0.0);
|
||||
assert!(a.contains(&("stroke", "#0f0f0f".to_string())) && a.contains(&("stroke-width", "0.05".to_string())), "{a:?}");
|
||||
let b = poly_node("0,0 1,0 1,1", "#ffffff", "none", 0.0);
|
||||
assert!(b.contains(&("stroke", "none".to_string())), "{b:?}");
|
||||
let c = poly_node("0,0 1,0 1,1", "#0f0f0f", "#222", 0.35);
|
||||
assert!(c.contains(&("stroke", "#222".to_string())), "{c:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn raumfuellung_mit_alpha_als_deckkraft() {
|
||||
let a = poly_node("0,0 1,0 1,1", "#4a6fa526", "none", 0.0);
|
||||
|
||||
@@ -2889,6 +2889,8 @@ pub fn section_primitives_at(out: &Output, mono: bool, hidden_lines: bool, vis:
|
||||
prims.push(q);
|
||||
}
|
||||
}
|
||||
// [157] Verdeckte Kanten kommen hier hinein (unter die Schnittflächen, die sie verdecken).
|
||||
let cut_start = prims.len();
|
||||
for cp in &merged {
|
||||
if cp.pts.len() < 3 {
|
||||
continue;
|
||||
@@ -3021,6 +3023,7 @@ pub fn section_primitives_at(out: &Output, mono: bool, hidden_lines: bool, vis:
|
||||
}
|
||||
};
|
||||
if hidden_lines {
|
||||
let mut hidden: Vec<Primitive> = Vec::new();
|
||||
for e in out.hidden.iter().filter(|e| mesh_shown(e)) {
|
||||
acc.add(e.a[0], e.a[1]);
|
||||
acc.add(e.b[0], e.b[1]);
|
||||
@@ -3028,8 +3031,9 @@ pub fn section_primitives_at(out: &Output, mono: bool, hidden_lines: bool, vis:
|
||||
if let Primitive::Line { dash, .. } = &mut l {
|
||||
*dash = Some(Some(SECTION_HIDDEN_DASH.to_vec()));
|
||||
}
|
||||
prims.push(l);
|
||||
hidden.push(l);
|
||||
}
|
||||
prims.splice(cut_start..cut_start, hidden);
|
||||
}
|
||||
for e in out.visible.iter().filter(|e| mesh_shown(e)) {
|
||||
acc.add(e.a[0], e.a[1]);
|
||||
@@ -4224,6 +4228,23 @@ mod tests {
|
||||
assert!(serde_json::to_string(&prims).unwrap().contains("section-hidden"));
|
||||
}
|
||||
|
||||
/// [157] Verdeckte Kanten liegen hinter der Schnittebene: die Schnittflächen decken sie zu (vorher lagen
|
||||
/// dunkle Strichlinien auf den schwarzen Wänden 1:100, Musterhaus komplex Schnitt A-A Aussenwand).
|
||||
#[test]
|
||||
fn verdeckte_kanten_unter_den_schnittflaechen() {
|
||||
let p = sample();
|
||||
let mut l = level(&p, "schnitt-a");
|
||||
l.hidden_lines = true;
|
||||
let out = compute_section(&p, &l, &[]).unwrap().unwrap();
|
||||
for scale in [50.0, 100.0] {
|
||||
let (prims, _) = section_primitives_at(&out, true, true, &Visibility::default(), scale, Detail::Mittel, false, &CutRules::default());
|
||||
let first_cut = prims.iter().position(|q| matches!(q, Primitive::Polygon { fill, .. } if fill != "none")).expect("Schnittfläche");
|
||||
let hidden: Vec<usize> = prims.iter().enumerate().filter(|(_, q)| matches!(q, Primitive::Line { cls, .. } if cls == "section-hidden")).map(|(i, _)| i).collect();
|
||||
assert!(!hidden.is_empty());
|
||||
assert!(hidden.iter().all(|&i| i < first_cut), "1:{scale}: verdeckte Kante über einer Schnittfläche");
|
||||
}
|
||||
}
|
||||
|
||||
/// [T6]/[68] Gelände mit Baugrube: gestaltetes + gewachsenes Terrain, Erdreich ohne Gebäude-Inneres;
|
||||
/// Fassaden-Geländehöhen fürs Baurecht.
|
||||
#[test]
|
||||
|
||||
@@ -162,6 +162,24 @@ fn op_json(v: &Value) -> String {
|
||||
op(greyed, v.get("opacity").map(|o| o.as_f64().unwrap_or(f64::NAN)))
|
||||
}
|
||||
|
||||
/// [157] Haarstrich (Papier-mm) gegen die Fuge zwischen aneinanderstossenden dunklen Flächen.
|
||||
pub(crate) const SEAM_MM: f64 = 0.05;
|
||||
|
||||
/// [157] Deckend dunkle Füllfarbe (`#rgb`, `#rrggbb`, `#rrggbbff`; jeder Kanal ≤ 0x40), die zwischen zwei
|
||||
/// Flächen eine helle Haarfuge zeigt (Chromium/PDF glätten aneinanderstossende Flächen einzeln): solche
|
||||
/// Flächen ohne eigenen Strich bekommen einen Haarstrich [`SEAM_MM`] in ihrer Farbe — schwarze
|
||||
/// Schnittflächen (Wandecken, Schichten im Schnitt 1:100) bleiben ohne helle Linien dazwischen.
|
||||
pub(crate) fn seam_fill(fill: &str) -> bool {
|
||||
let h = fill.trim().strip_prefix('#').unwrap_or("");
|
||||
let ch = |i: usize, n: usize| u8::from_str_radix(&h[i * n..i * n + n], 16).ok().map(|v| if n == 1 { v * 17 } else { v });
|
||||
let (rgb, alpha) = match h.len() {
|
||||
3 if h.is_ascii() => ([ch(0, 1), ch(1, 1), ch(2, 1)], Some(255)),
|
||||
6 | 8 if h.is_ascii() => ([ch(0, 2), ch(1, 2), ch(2, 2)], if h.len() == 8 { u8::from_str_radix(&h[6..8], 16).ok() } else { Some(255) }),
|
||||
_ => return false,
|
||||
};
|
||||
alpha == Some(255) && rgb.iter().all(|c| c.is_some_and(|c| c <= 0x40))
|
||||
}
|
||||
|
||||
fn op(greyed: bool, opacity: Option<f64>) -> String {
|
||||
if greyed {
|
||||
" opacity=\"0.35\"".into()
|
||||
@@ -252,8 +270,12 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option<String> {
|
||||
Some((o, len)) => part.view.pool(o, len)?.iter().filter(|e| e.is_finite() && **e >= 0.0).map(|e| *e as usize).collect(),
|
||||
None => Vec::new(),
|
||||
};
|
||||
// [157] Dunkle, deckende Fläche ohne eigenen Strich: Haarstrich in der Füllfarbe gegen die Fuge.
|
||||
let seam = !greyed && opacity(4).is_none_or(|a| a >= 1.0) && seam_fill(&fill);
|
||||
let seam_attr = || format!(" stroke=\"{fill}\" stroke-width=\"{}\"", num(SEAM_MM * mm_to_m));
|
||||
if !nse.is_empty() && stroke != "none" && !stroke.is_empty() {
|
||||
out.push(format!("<polygon points=\"{pl}\" fill=\"{fill}\" stroke=\"none\"{}/>", op(greyed, opacity(4))));
|
||||
let st = if seam { seam_attr() } else { " stroke=\"none\"".to_string() };
|
||||
out.push(format!("<polygon points=\"{pl}\" fill=\"{fill}\"{st}{}/>", op(greyed, opacity(4))));
|
||||
// Sichtbare Kantenläufe zum Zusammennähen ([146]), Kanten in Ring-Reihenfolge.
|
||||
let nse_f: Vec<f64> = nse.iter().map(|&e| e as f64).collect();
|
||||
let attrs = format!(" stroke=\"{stroke}\" stroke-width=\"{}\"{}", num(f[2] * mm_to_m), op(greyed, opacity(4)));
|
||||
@@ -261,6 +283,8 @@ pub fn plan_svg(parts: &mut [Part], o: &SvgOptions) -> Option<String> {
|
||||
out.push(String::new());
|
||||
stitch.add(attrs.clone(), run, out.len() - 1);
|
||||
}
|
||||
} else if seam && (stroke == "none" || stroke.is_empty() || !(f[2] > 0.0)) {
|
||||
out.push(format!("<polygon points=\"{pl}\" fill=\"{fill}\"{}{}/>", seam_attr(), op(greyed, opacity(4))));
|
||||
} else {
|
||||
out.push(format!(
|
||||
"<polygon points=\"{pl}\" fill=\"{fill}\" stroke=\"{stroke}\" stroke-width=\"{}\"{}/>",
|
||||
@@ -500,6 +524,58 @@ mod tests {
|
||||
assert!(y(texts[0]) < 2.0 && y(texts[1]) > 2.0, "{texts:?}");
|
||||
}
|
||||
|
||||
/// [157] Haarfuge: zwei schwarze Schnittflächen (Wandecke, Schichten im Schnitt 1:100) stossen aneinander;
|
||||
/// jede deckend dunkle Fläche ohne Strich bekommt einen Haarstrich in ihrer Farbe, der die Fuge schliesst
|
||||
/// (Chromium/PDF glätten die Kanten einzeln → helle Linie). Helle oder durchscheinende Flächen nicht.
|
||||
#[test]
|
||||
fn schwarze_flaechen_ohne_haarfuge() {
|
||||
use crate::model::Vec2;
|
||||
use crate::plan::buf::{View, Writer};
|
||||
use crate::plan::prim::Primitive;
|
||||
let v = |x: f64, y: f64| Vec2 { x, y };
|
||||
let poly = |pts: Vec<Vec2>, fill: &str, nse: Option<Vec<f64>>| Primitive::Polygon {
|
||||
pts,
|
||||
fill: fill.into(),
|
||||
stroke: if nse.is_some() { "#1a1a1a".into() } else { "none".into() },
|
||||
stroke_width_mm: if nse.is_some() { 0.25 } else { 0.0 },
|
||||
hatch: crate::plan::style::no_hatch(),
|
||||
greyed: None,
|
||||
opacity: None,
|
||||
no_stroke_edges: nse,
|
||||
wall_id: None,
|
||||
drawing_id: None,
|
||||
ceiling_id: None,
|
||||
opening_id: None,
|
||||
stair_id: None,
|
||||
room_id: None,
|
||||
extruded_solid_id: None,
|
||||
context_object_id: None,
|
||||
column_id: None,
|
||||
roof_id: None,
|
||||
section_line_id: None,
|
||||
};
|
||||
let mut w = Writer::new(false);
|
||||
let g = w.begin_group();
|
||||
w.push(&poly(vec![v(0.0, 0.0), v(2.0, 0.0), v(2.0, 0.3), v(0.0, 0.3)], "#0f0f0f", None));
|
||||
w.push(&poly(vec![v(2.0, 0.0), v(4.0, 0.0), v(4.0, 0.3), v(2.0, 0.3)], "#111111", Some(vec![3.0])));
|
||||
w.push(&poly(vec![v(0.0, 1.0), v(4.0, 1.0), v(4.0, 2.0)], "#ffffff", None));
|
||||
w.push(&poly(vec![v(0.0, 3.0), v(4.0, 3.0), v(4.0, 4.0)], "#3c3c3c29", None));
|
||||
w.end_group(g);
|
||||
let bytes = w.finish();
|
||||
let view = View::parse(&bytes).unwrap();
|
||||
let n = view.len();
|
||||
let mut parts = vec![Part::new(view, 0, n).unwrap()];
|
||||
let o = SvgOptions { scale_denominator: 100.0, margin_m: 0.5, min_x: 0.0, min_y: 0.0, max_x: 4.0, max_y: 4.0, hatch: false, line_ends: LineEnds::default() };
|
||||
let svg = plan_svg(&mut parts, &o).unwrap();
|
||||
let polys: Vec<&str> = svg.lines().filter(|l| l.starts_with("<polygon")).collect();
|
||||
assert_eq!(polys.len(), 4, "{svg}");
|
||||
assert!(polys[0].contains("fill=\"#0f0f0f\" stroke=\"#0f0f0f\" stroke-width=\"0.005\""), "{}", polys[0]);
|
||||
assert!(polys[1].contains("fill=\"#111111\" stroke=\"#111111\" stroke-width=\"0.005\""), "Kantenlauf-Fläche: {}", polys[1]);
|
||||
assert!(polys[2].contains("stroke=\"none\""), "weiss: {}", polys[2]);
|
||||
assert!(polys[3].contains("stroke=\"none\""), "durchscheinend: {}", polys[3]);
|
||||
assert!(seam_fill("#000") && seam_fill("#1a1a1aff") && !seam_fill("#6e6e6e") && !seam_fill("none") && !seam_fill("#00000080"));
|
||||
}
|
||||
|
||||
/// [146] Wand-Umrisse als volle Linie bzw. offene Kantenläufe (Stossfugen nicht gestrichen) werden
|
||||
/// an der gemeinsamen Ecke zu EINEM Zug genäht (Gehrung statt zweier flacher Enden = keine Kerbe);
|
||||
/// Enden und Ecken stehen einmal am umschliessenden `<g>`.
|
||||
|
||||
Reference in new issue
Block a user