[109] [101] Schraffuren: Generator als eigenes Crate (hatchgen), render3d-Live-Schnitt/Druck-SVG/SVG-PlanView zeichnen Schichtmuster mit dem Kern-Generator, Putz/Keramik/Faserzement mit Schraffur (Punktfeld), Standards aktualisieren im Ressourcen-Manager
This commit is contained in:
38 files changed
+1004
-74
No files matched your search
Generated
+8
@@ -1107,6 +1107,13 @@ dependencies = [
|
||||
"tendril",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dossier-hatch"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "downcast-rs"
|
||||
version = "1.2.1"
|
||||
@@ -4013,6 +4020,7 @@ version = "0.1.0"
|
||||
dependencies = [
|
||||
"bytemuck",
|
||||
"console_error_panic_hook",
|
||||
"dossier-hatch",
|
||||
"env_logger",
|
||||
"js-sys",
|
||||
"naga",
|
||||
|
||||
@@ -7,7 +7,7 @@ members = ["."]
|
||||
# nutzen kann. kernel2d: analog — eigenstaendiger 2D-Geometrie-Kern, als
|
||||
# Pfad-Abhaengigkeit von dossier-core (src-tauri/core) eingebunden, ausserhalb
|
||||
# des cad-tauri-Workspace.
|
||||
exclude = ["render2d", "render3d", "kernel2d", "dwgimport", "trucksolid"]
|
||||
exclude = ["render2d", "render3d", "kernel2d", "dwgimport", "trucksolid", "hatchgen"]
|
||||
|
||||
[package]
|
||||
name = "cad-tauri"
|
||||
|
||||
Generated
+9
@@ -29,6 +29,7 @@ name = "dossier-core"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"console_error_panic_hook",
|
||||
"dossier-hatch",
|
||||
"i_overlay",
|
||||
"kernel2d",
|
||||
"render3d",
|
||||
@@ -39,6 +40,13 @@ dependencies = [
|
||||
"zmij",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "dossier-hatch"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "equivalent"
|
||||
version = "1.0.3"
|
||||
@@ -162,6 +170,7 @@ dependencies = [
|
||||
name = "render3d"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"dossier-hatch",
|
||||
"serde",
|
||||
]
|
||||
|
||||
|
||||
@@ -15,13 +15,15 @@ crate-type = ["cdylib", "rlib"]
|
||||
[features]
|
||||
default = []
|
||||
# Browser-/Node-Bindings (wasm-bindgen); nur fuer wasm32-unknown-unknown.
|
||||
web = ["dep:wasm-bindgen", "dep:console_error_panic_hook"]
|
||||
web = ["dep:wasm-bindgen", "dep:console_error_panic_hook", "dossier-hatch/web"]
|
||||
|
||||
[dependencies]
|
||||
i_overlay = { version = "9.1", default-features = false }
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
serde_json = { version = "1", features = ["preserve_order", "float_roundtrip"] }
|
||||
kernel2d = { path = "../kernel2d" }
|
||||
# Schraffur-Generator + JS-Zahlsemantik (auch von render3d genutzt), s. hatchgen/src/lib.rs.
|
||||
dossier-hatch = { path = "../hatchgen" }
|
||||
# Analytischer Schnitt-Extraktor (`section::cut_section`, GPU-frei, nur serde) für Schnitt/Ansicht im Kern ([K3c]).
|
||||
render3d = { path = "../render3d", default-features = false }
|
||||
# Kürzeste Dezimaldarstellung wie serde_json (Zahlen, die früher über JSON reisten, bitgleich nachbilden).
|
||||
|
||||
@@ -30,7 +30,7 @@ pub mod room_area;
|
||||
pub mod room_boundary;
|
||||
pub mod polygon_holes;
|
||||
pub mod js_fmt;
|
||||
pub mod jsmath;
|
||||
pub use dossier_hatch::jsmath;
|
||||
pub mod stairs3d;
|
||||
pub mod mesh3d;
|
||||
pub mod ceilings3d;
|
||||
@@ -38,8 +38,8 @@ pub mod columns3d;
|
||||
pub mod drawing2d_3d;
|
||||
pub mod openings3d;
|
||||
pub mod wall_mesh_cut;
|
||||
pub mod jsnum;
|
||||
pub mod hatch;
|
||||
pub use dossier_hatch::jsnum;
|
||||
pub use dossier_hatch::hatch;
|
||||
pub mod hatch_flat;
|
||||
pub mod plan;
|
||||
pub mod plan_buf;
|
||||
|
||||
@@ -250,6 +250,9 @@ pub enum HatchPattern {
|
||||
/// Naturstein ([109]): Diagonale in Doppellinien.
|
||||
#[serde(rename = "stone")]
|
||||
Stone,
|
||||
/// Punktfeld ([109], Putz): feine Punkte im versetzten Raster.
|
||||
#[serde(rename = "dots")]
|
||||
Dots,
|
||||
#[serde(other)]
|
||||
#[ts(skip)]
|
||||
Unknown,
|
||||
|
||||
@@ -2051,6 +2051,7 @@ fn write_hatch_words(out: &mut Vec<f64>, h: &HatchRender, color: f64) {
|
||||
HatchPattern::Earth => 9.0,
|
||||
HatchPattern::Gravel => 10.0,
|
||||
HatchPattern::Stone => 11.0,
|
||||
HatchPattern::Dots => 12.0,
|
||||
_ => 2.0,
|
||||
};
|
||||
let kind = match h.kind {
|
||||
|
||||
@@ -527,7 +527,7 @@ fn dash_seg(a: V2, b: V2, cycle: &[f64]) -> Vec<(V2, V2)> {
|
||||
fn is_curve_pattern(p: Pattern) -> bool {
|
||||
matches!(
|
||||
p,
|
||||
Pattern::Insulation | Pattern::InsulationHard | Pattern::InsulationWave | Pattern::Timber | Pattern::Earth | Pattern::Gravel | Pattern::Stone
|
||||
Pattern::Insulation | Pattern::InsulationHard | Pattern::InsulationWave | Pattern::Timber | Pattern::Earth | Pattern::Gravel | Pattern::Stone | Pattern::Dots
|
||||
)
|
||||
}
|
||||
|
||||
|
||||
@@ -245,10 +245,18 @@ fn fill_parallel(poly: &[V2], angle: f64, spacing: f64, out: &mut Vec<(V2, V2)>)
|
||||
}
|
||||
}
|
||||
|
||||
/// Muster, die der Kern-Generator als Linien/Polylinien erzeugt (Schichtmuster, Streu-/Punktmuster, Doppellinien).
|
||||
fn is_generated(p: Pattern) -> bool {
|
||||
matches!(
|
||||
p,
|
||||
Pattern::Insulation | Pattern::InsulationHard | Pattern::InsulationWave | Pattern::Timber | Pattern::Earth | Pattern::Gravel | Pattern::Stone | Pattern::Dots
|
||||
)
|
||||
}
|
||||
|
||||
/// Schraffurlinien in Papier-mm (`hatchLines`).
|
||||
fn hatch_lines(poly_mm: &[V2], h: &Hatch, mm_per_m: f64) -> Vec<(V2, V2)> {
|
||||
let unit_mm = (1.0 / 90.0) * mm_per_m;
|
||||
let tile_mm = (if h.pattern == Pattern::Insulation { 10.0 } else { 8.0 }) * h.scale * unit_mm;
|
||||
let tile_mm = 8.0 * h.scale * unit_mm;
|
||||
let spacing = jsnum::max(0.5, tile_mm);
|
||||
let angle = (h.angle * PI) / 180.0;
|
||||
let mut segs = Vec::new();
|
||||
@@ -256,9 +264,6 @@ fn hatch_lines(poly_mm: &[V2], h: &Hatch, mm_per_m: f64) -> Vec<(V2, V2)> {
|
||||
if h.pattern == Pattern::Crosshatch {
|
||||
fill_parallel(poly_mm, angle + PI / 2.0, spacing, &mut segs);
|
||||
}
|
||||
if h.pattern == Pattern::Insulation {
|
||||
fill_parallel(poly_mm, angle - PI / 4.0, spacing, &mut segs);
|
||||
}
|
||||
segs
|
||||
}
|
||||
|
||||
@@ -351,6 +356,16 @@ fn entry(out: &mut Out, view: &View, i: usize, hatches: &[(i32, Hatch, i32)], m:
|
||||
let (a, b) = (run[0], run[run.len() - 1]);
|
||||
out.el(1, "line", &line_attrs(m.at(a.x, a.y), m.at(b.x, b.y), &hatch_color, pen, Some(&hdash)));
|
||||
}
|
||||
} else if is_generated(h.pattern) {
|
||||
// Schicht-/Streumuster ([109]): dieselben Linien wie Szene und Chunk-Pfad (Kern-Generator).
|
||||
for run in hatch::build_hatch_runs(&pts, &h) {
|
||||
let p: Vec<V2> = run.iter().map(|q| m.at(q.x, q.y)).collect();
|
||||
match p.len() {
|
||||
0 | 1 => {}
|
||||
2 => out.el(1, "line", &line_attrs(p[0], p[1], &hatch_color, pen, Some(&hdash))),
|
||||
_ => out.el(1, "polyline", &polyline_attrs(&p, &hatch_color, pen, Some(&hdash))),
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// Strichmuster der Schraffur (null und [] gleich: keins).
|
||||
for (a, b) in hatch_lines(&pts_mm, &h, k) {
|
||||
|
||||
@@ -84,6 +84,12 @@ pub fn run_root(lk: &crate::document::Lookup, name: &str, text: &str) -> Result<
|
||||
"penDeleteOps" => json(&crate::pens::delete_pen_ops(root, text)),
|
||||
// Standard-Bibliothek ([100]–[102], `standards.rs`): fehlende Standard-Ressourcen als Ops.
|
||||
"standardsMergeOps" => json(&crate::standards::merge_ops(root)),
|
||||
// „Standards aktualisieren" ([109]): Abweichungen vom heutigen Standard / Ops für die gewählten (`text` = JSON-Liste `"<Liste>:<id>"`).
|
||||
"standardsUpdatePlan" => json(&crate::standards::update_plan(root)),
|
||||
"standardsUpdateOps" => {
|
||||
let sel: Vec<String> = serde_json::from_str(text).map_err(|e| format!("standardsUpdateOps: {e}"))?;
|
||||
json(&crate::standards::update_ops(root, &sel))
|
||||
}
|
||||
"penSeedOps" => {
|
||||
let a: serde_json::Value = serde_json::from_str(text).map_err(|e| format!("penSeedOps: {e}"))?;
|
||||
json(&crate::pens::seed_standard_ops(root, a["id"].as_str().unwrap_or(""), a["name"].as_str().unwrap_or("")))
|
||||
|
||||
@@ -104,6 +104,14 @@ pub fn hatches() -> Vec<Value> {
|
||||
// Holzfaser: Welle über die Dicke.
|
||||
layer("std-h-holzfaser", "SIA Dämmung Holzfaser", "insulationWave", 1.0),
|
||||
solid("std-h-gips", "SIA Gips", "#cfcfcf"),
|
||||
// Putz (innen/aussen): feines, ruhiges Punktfeld entlang der Schicht (Teilung 2 cm). Eine Schraffur
|
||||
// ohne Massstabsgrenze: in 1:100 und gröber wird sie ein feiner Grauton, wer Putz dort leer will,
|
||||
// wählt „SIA Ohne Schraffur".
|
||||
json!({"id": "std-h-putz", "name": "SIA Putz", "pattern": "dots", "scale": 0.4, "angle": 0, "relativeToWall": true, "color": INK, "lineWeight": 0.1}),
|
||||
// Keramik (Fliesen, Platten): feines Kreuzraster 45°.
|
||||
lines("std-h-keramik", "SIA Keramik", "crosshatch", 0.015, 45.0, false, 0.1, ""),
|
||||
// Faserzement: dichte Diagonale 135° (Plattenwerkstoff, gegenläufig zu Backstein/Beton).
|
||||
lines("std-h-faserzement", "SIA Faserzement", "diagonal", 0.02, 135.0, false, 0.1, ""),
|
||||
// Estrich/Überzug: feines Punktfeld (punktierte Diagonale).
|
||||
lines("std-h-estrich", "SIA Estrich", "diagonal", 0.025, 45.0, false, 0.1, "std-ls-schraffur-punkt"),
|
||||
solid("std-h-stahl", "SIA Stahl", INK),
|
||||
@@ -166,12 +174,12 @@ pub fn components() -> Vec<Value> {
|
||||
Mat { id: "std-c-holzfaser", name: "Holzfaser", abbrev: "HF", fill: "#ffffff", elev: "#b08a5a", hatch: "std-h-holzfaser", lambda: Some(0.04), density: Some(140.0), rf: "RF3", tex: None, prio: 24.0, pattern: None },
|
||||
Mat { id: "std-c-trittschall", name: "Trittschalldämmung", abbrev: "TSD", fill: "#ffffff", elev: "#efe6a8", hatch: "std-h-daemmung-weich", lambda: Some(0.035), density: Some(100.0), rf: "RF1", tex: None, prio: 19.0, pattern: None },
|
||||
Mat { id: "std-c-gipskarton", name: "Gipskarton", abbrev: "GK", fill: "#cfcfcf", elev: "#f4f4f2", hatch: "std-h-gips", lambda: Some(0.25), density: Some(800.0), rf: "RF1", tex: Some(("Plaster001", 1.0)), prio: 12.0, pattern: None },
|
||||
Mat { id: "std-c-innenputz", name: "Innenputz", abbrev: "IP", fill: "#ffffff", elev: "#f5f3ee", hatch: "std-h-ohne", lambda: Some(0.7), density: Some(1400.0), rf: "RF1", tex: Some(("Plaster001", 1.0)), prio: 10.0, pattern: None },
|
||||
Mat { id: "std-c-aussenputz", name: "Aussenputz", abbrev: "AP", fill: "#ffffff", elev: "#e9e3d6", hatch: "std-h-ohne", lambda: Some(0.87), density: Some(1800.0), rf: "RF1", tex: Some(("Plaster001", 1.0)), prio: 10.0, pattern: None },
|
||||
Mat { id: "std-c-innenputz", name: "Innenputz", abbrev: "IP", fill: "#ffffff", elev: "#f5f3ee", hatch: "std-h-putz", lambda: Some(0.7), density: Some(1400.0), rf: "RF1", tex: Some(("Plaster001", 1.0)), prio: 10.0, pattern: None },
|
||||
Mat { id: "std-c-aussenputz", name: "Aussenputz", abbrev: "AP", fill: "#ffffff", elev: "#e9e3d6", hatch: "std-h-putz", lambda: Some(0.87), density: Some(1800.0), rf: "RF1", tex: Some(("Plaster001", 1.0)), prio: 10.0, pattern: None },
|
||||
Mat { id: "std-c-zementestrich", name: "Zementestrich", abbrev: "ZE", fill: "#ffffff", elev: "#cfcac0", hatch: "std-h-estrich", lambda: Some(1.4), density: Some(2000.0), rf: "RF1", tex: Some(("Concrete048", 2.0)), prio: 30.0, pattern: None },
|
||||
// Bodenbeläge ([100]): Muster im Grundriss (Oberseite der Decke) und im 3D.
|
||||
Mat { id: "std-c-parkett", name: "Parkett", abbrev: "PA", fill: "#ffffff", elev: "#c9a06b", hatch: "std-h-holz", lambda: Some(0.13), density: Some(650.0), rf: "RF3", tex: Some(("Wood095", 1.0)), prio: 8.0, pattern: sp("runningBond", None, 0.6, Some(0.1), None) },
|
||||
Mat { id: "std-c-keramik", name: "Keramikplatten", abbrev: "KP", fill: "#ffffff", elev: "#d8d4cc", hatch: "std-h-ohne", lambda: Some(1.3), density: Some(2300.0), rf: "RF1", tex: None, prio: 9.0, pattern: sp("grid", None, 0.3, Some(0.3), None) },
|
||||
Mat { id: "std-c-keramik", name: "Keramikplatten", abbrev: "KP", fill: "#ffffff", elev: "#d8d4cc", hatch: "std-h-keramik", lambda: Some(1.3), density: Some(2300.0), rf: "RF1", tex: None, prio: 9.0, pattern: sp("grid", None, 0.3, Some(0.3), None) },
|
||||
Mat { id: "std-c-glas", name: "Glas", abbrev: "GL", fill: "#d6ecf3", elev: "#a9c8d4", hatch: "std-h-ohne", lambda: Some(1.0), density: Some(2500.0), rf: "RF1", tex: None, prio: 70.0, pattern: None },
|
||||
Mat { id: "std-c-stahl", name: "Stahl", abbrev: "ST", fill: INK, elev: "#7d8287", hatch: "std-h-stahl", lambda: Some(50.0), density: Some(7850.0), rf: "RF1", tex: Some(("Metal063", 1.0)), prio: 110.0, pattern: None },
|
||||
Mat { id: "std-c-aluminium", name: "Aluminium", abbrev: "AL", fill: "#8c8c8c", elev: "#b9bcbf", hatch: "std-h-alu", lambda: Some(160.0), density: Some(2700.0), rf: "RF1", tex: Some(("Metal063", 1.0)), prio: 105.0, pattern: None },
|
||||
@@ -185,7 +193,7 @@ pub fn components() -> Vec<Value> {
|
||||
Mat { id: "std-c-boden-deckel", name: "Holzschalung Boden-Deckel", abbrev: "BD", fill: "#ffffff", elev: "#a9824f", hatch: "std-h-holz", lambda: Some(0.13), density: Some(450.0), rf: "RF3", tex: Some(("WoodSiding008", 1.0)), prio: 41.0, pattern: sp("boardBatten", Some("vertical"), 0.2, None, Some(0.06)) },
|
||||
Mat { id: "std-c-schindeln", name: "Holzschindeln", abbrev: "SCH", fill: "#ffffff", elev: "#9c8566", hatch: "std-h-holz", lambda: Some(0.13), density: Some(450.0), rf: "RF3", tex: Some(("Wood095", 0.5)), prio: 41.0, pattern: sp("shingles", None, 0.1, Some(0.12), None) },
|
||||
Mat { id: "std-c-trapezblech", name: "Trapezblech", abbrev: "TB", fill: INK, elev: "#9aa1a6", hatch: "std-h-stahl", lambda: Some(50.0), density: Some(7850.0), rf: "RF1", tex: Some(("CorrugatedSteel005", 1.0)), prio: 108.0, pattern: sp("trapezoid", Some("vertical"), 0.2, None, Some(0.06)) },
|
||||
Mat { id: "std-c-faserzement", name: "Faserzementplatten", abbrev: "FZ", fill: "#ffffff", elev: "#a6a8a6", hatch: "std-h-ohne", lambda: Some(0.6), density: Some(1800.0), rf: "RF1", tex: None, prio: 42.0, pattern: sp("grid", None, 1.25, Some(0.625), None) },
|
||||
Mat { id: "std-c-faserzement", name: "Faserzementplatten", abbrev: "FZ", fill: "#ffffff", elev: "#a6a8a6", hatch: "std-h-faserzement", lambda: Some(0.6), density: Some(1800.0), rf: "RF1", tex: None, prio: 42.0, pattern: sp("grid", None, 1.25, Some(0.625), None) },
|
||||
Mat { id: "std-c-tonziegel", name: "Tonziegel", abbrev: "ZI", fill: "#ffffff", elev: "#b3583c", hatch: "std-h-backstein", lambda: Some(1.0), density: Some(1900.0), rf: "RF1", tex: Some(("RoofingTiles013A", 1.0)), prio: 15.0, pattern: sp("grid", Some("horizontal"), 0.21, Some(0.34), None) },
|
||||
];
|
||||
list.iter()
|
||||
@@ -263,6 +271,11 @@ fn remap(v: &mut Value, key: &str, ids: &HashMap<String, String>) {
|
||||
/// gleichem Namen (Gross-/Kleinschreibung egal); Verweise neuer Einträge (Schraffur → Linienstil, Bauteil →
|
||||
/// Schraffur, Aufbau → Bauteil/Fugen-Linienstil) zeigen dann auf den vorhandenen Eintrag.
|
||||
pub fn merge_ops(root: &Map<String, Value>) -> Vec<Value> {
|
||||
merge_plan(root).0
|
||||
}
|
||||
|
||||
/// Wie [`merge_ops`], dazu die Umleitung Standard-id → vorhandene id (gleichnamige Einträge).
|
||||
fn merge_plan(root: &Map<String, Value>) -> (Vec<Value>, HashMap<String, String>) {
|
||||
let mut ids: HashMap<String, String> = HashMap::new();
|
||||
let mut ops = Vec::new();
|
||||
for (key, items) in library() {
|
||||
@@ -299,6 +312,175 @@ pub fn merge_ops(root: &Map<String, Value>) -> Vec<Value> {
|
||||
ops.push(json!({"kind": "setField", "key": key, "value": add}));
|
||||
}
|
||||
}
|
||||
(ops, ids)
|
||||
}
|
||||
|
||||
// ── „Standards aktualisieren" ([109]) ────────────────────────────────────────
|
||||
//
|
||||
// Projekte, die mit älteren Standards angelegt wurden, behalten deren Definitionen („Standards laden"
|
||||
// ergänzt nur). „Aktualisieren" gleicht Standard-Einträge (gleiche id wie ein Eintrag der Bibliothek) mit
|
||||
// der heutigen Definition ab. Regel:
|
||||
// - Verglichen werden nur die vom Standard geführten Felder (`managed`); Name und eigene Zusatzfelder
|
||||
// bleiben unangetastet. Ein vom Standard geführtes Feld, das die neue Definition nicht mehr hat, wird
|
||||
// entfernt (z. B. ein früherer `lineStyleId`).
|
||||
// - Ob jemand einen Standard-Eintrag selbst geändert hat, lässt sich nicht erkennen (frühere Fassungen sind
|
||||
// nicht gespeichert). Darum nennt der Plan jede Abweichung einzeln; vorgewählt sind alle Einträge,
|
||||
// deren Name noch dem Standard entspricht, umbenannte (`renamed`) sind abgewählt. Gewählt wird im Dialog.
|
||||
// - Verweise (Schraffur, Linienstil, Bauteil) werden nur gesetzt, wenn das Ziel im Projekt existiert bzw.
|
||||
// gleichzeitig ergänzt wird; fehlende Standard-Einträge werden wie bei „Standards laden" angehängt.
|
||||
|
||||
type Valid<'a> = HashMap<&'a str, std::collections::HashSet<String>>;
|
||||
|
||||
/// Felder, die der Standard je Liste führt.
|
||||
fn managed(key: &str) -> &'static [&'static str] {
|
||||
match key {
|
||||
"lineStyles" => &["color", "dash", "kind", "zigzag"],
|
||||
"hatches" => &[
|
||||
"pattern", "scale", "angle", "color", "lineWeight", "relativeToWall", "lineStyleId", "kind", "lines", "density", "lengthMin", "lengthMax", "seed",
|
||||
],
|
||||
"components" => &[
|
||||
"color", "background", "hatchId", "viewHatchId", "joinPriority", "fireClass", "elevationColor", "standardId", "lambda", "density", "material", "surfacePattern",
|
||||
"abbrev",
|
||||
],
|
||||
_ => &["layers"],
|
||||
}
|
||||
}
|
||||
|
||||
/// Zahlen gleich nach Wert (1 == 1.0), sonst strukturell.
|
||||
fn same(a: &Value, b: &Value) -> bool {
|
||||
match (a, b) {
|
||||
(Value::Number(x), Value::Number(y)) => x.as_f64() == y.as_f64(),
|
||||
(Value::Array(x), Value::Array(y)) => x.len() == y.len() && x.iter().zip(y).all(|(p, q)| same(p, q)),
|
||||
(Value::Object(x), Value::Object(y)) => x.len() == y.len() && x.iter().all(|(k, v)| y.get(k).is_some_and(|w| same(v, w))),
|
||||
_ => a == b,
|
||||
}
|
||||
}
|
||||
|
||||
/// Ziel eines Verweises im Projekt (nach Umleitung gleichnamiger Einträge), sonst `None`.
|
||||
fn ref_target(ref_key: &str, id: &str, valid: &Valid, ids: &HashMap<String, String>) -> Option<String> {
|
||||
let list = match ref_key {
|
||||
"lineStyleId" | "jointLineStyleId" => "lineStyles",
|
||||
"hatchId" | "viewHatchId" => "hatches",
|
||||
_ => "components",
|
||||
};
|
||||
let id = ids.get(id).map(String::as_str).unwrap_or(id);
|
||||
valid.get(list).is_some_and(|v| v.contains(id)).then(|| id.to_string())
|
||||
}
|
||||
|
||||
/// Neue Fassung eines vorhandenen Standard-Eintrags (nur geführte Felder; Verweise auf fehlende Ziele
|
||||
/// bleiben wie sie sind) und die Namen der geänderten Felder.
|
||||
fn updated(key: &str, old: &Value, std: &Value, valid: &Valid, ids: &HashMap<String, String>) -> (Value, Vec<String>) {
|
||||
let mut new = old.clone();
|
||||
let mut fields = Vec::new();
|
||||
for f in managed(key) {
|
||||
let mut want = std.get(*f).cloned();
|
||||
if let Some(Value::String(id)) = &want {
|
||||
if matches!(*f, "lineStyleId" | "hatchId" | "viewHatchId") {
|
||||
match ref_target(f, id, valid, ids) {
|
||||
Some(ok) => want = Some(json!(ok)),
|
||||
None => continue, // Ziel fehlt: Verweis bleibt
|
||||
}
|
||||
}
|
||||
}
|
||||
if *f == "layers" {
|
||||
if let Some(Value::Array(ls)) = &mut want {
|
||||
for l in ls {
|
||||
for rk in ["componentId", "jointLineStyleId"] {
|
||||
if let Some(id) = l[rk].as_str().map(String::from) {
|
||||
match ref_target(rk, &id, valid, ids) {
|
||||
Some(ok) => l[rk] = json!(ok),
|
||||
None => return (old.clone(), Vec::new()),
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let have = old.get(*f);
|
||||
let differs = match (&want, have) {
|
||||
(Some(w), Some(h)) => !same(w, h),
|
||||
(None, None) => false,
|
||||
(None, Some(h)) => !h.is_null(),
|
||||
(Some(w), None) => !w.is_null(),
|
||||
};
|
||||
if differs {
|
||||
fields.push((*f).to_string());
|
||||
match want {
|
||||
Some(w) => new[*f] = w,
|
||||
None => {
|
||||
if let Some(o) = new.as_object_mut() {
|
||||
o.remove(*f);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
(new, fields)
|
||||
}
|
||||
|
||||
/// Eine Abweichung: (Liste, id, Name, geänderte Felder, umbenannt, neue Fassung).
|
||||
type Change = (String, String, String, Vec<String>, bool, Value);
|
||||
|
||||
fn update_changes(root: &Map<String, Value>) -> (Vec<Change>, usize) {
|
||||
let (merge, ids) = merge_plan(root);
|
||||
let mut valid: Valid = HashMap::new();
|
||||
let mut added = 0;
|
||||
for (key, _) in library() {
|
||||
let set = valid.entry(key).or_default();
|
||||
if let Some(a) = root.get(key).and_then(Value::as_array) {
|
||||
set.extend(a.iter().filter_map(|e| e["id"].as_str().map(String::from)));
|
||||
}
|
||||
for op in &merge {
|
||||
let list = match op["kind"].as_str() {
|
||||
Some("add") if op["collection"] == key => op["items"].as_array(),
|
||||
Some("setField") if op["key"] == key => op["value"].as_array(),
|
||||
_ => None,
|
||||
};
|
||||
for it in list.into_iter().flatten() {
|
||||
added += 1;
|
||||
if let Some(i) = it["id"].as_str() {
|
||||
set.insert(i.to_string());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
let mut out = Vec::new();
|
||||
for (key, items) in library() {
|
||||
let Some(existing) = root.get(key).and_then(Value::as_array) else { continue };
|
||||
for std in &items {
|
||||
let Some(id) = std["id"].as_str() else { continue };
|
||||
let Some(old) = existing.iter().find(|e| e["id"] == id) else { continue };
|
||||
let (new, fields) = updated(key, old, std, &valid, &ids);
|
||||
if fields.is_empty() {
|
||||
continue;
|
||||
}
|
||||
let name = old["name"].as_str().unwrap_or(id).to_string();
|
||||
let renamed = name_key(old) != name_key(std);
|
||||
out.push((key.to_string(), id.to_string(), name, fields, renamed, new));
|
||||
}
|
||||
}
|
||||
(out, added)
|
||||
}
|
||||
|
||||
/// Abweichungen der Standard-Einträge im Projekt von der heutigen Bibliothek: je Eintrag
|
||||
/// `{collection, id, name, fields, renamed}`; dazu `added` = Anzahl fehlender Standard-Einträge.
|
||||
pub fn update_plan(root: &Map<String, Value>) -> Value {
|
||||
let (changes, added) = update_changes(root);
|
||||
json!({
|
||||
"added": added,
|
||||
"changes": changes.iter().map(|c| json!({"collection": c.0, "id": c.1, "name": c.2, "fields": c.3, "renamed": c.4})).collect::<Vec<_>>(),
|
||||
})
|
||||
}
|
||||
|
||||
/// Ops für „Standards aktualisieren": fehlende Standards anhängen und die gewählten Einträge (`selected` =
|
||||
/// `"<Liste>:<id>"`) ersetzen — ein Undo-Schritt. Unbekannte Auswahl wird ignoriert.
|
||||
pub fn update_ops(root: &Map<String, Value>, selected: &[String]) -> Vec<Value> {
|
||||
let mut ops = merge_ops(root);
|
||||
for (key, id, _, _, _, new) in update_changes(root).0 {
|
||||
if selected.contains(&format!("{key}:{id}")) {
|
||||
ops.push(json!({"kind": "replace", "collection": key, "entity": new}));
|
||||
}
|
||||
}
|
||||
ops
|
||||
}
|
||||
|
||||
@@ -361,6 +543,104 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn putz_keramik_faserzement_haben_schraffur() {
|
||||
let r = apply(&empty_root(), &merge_ops(&empty_root()));
|
||||
let p: Project = serde_json::from_value(Value::Object(r)).unwrap();
|
||||
for (comp, hatch) in [("std-c-innenputz", "std-h-putz"), ("std-c-aussenputz", "std-h-putz"), ("std-c-keramik", "std-h-keramik"), ("std-c-faserzement", "std-h-faserzement")] {
|
||||
assert_eq!(p.components.iter().find(|c| c.id == comp).unwrap().hatch_id, hatch);
|
||||
}
|
||||
assert_eq!(p.hatches.iter().find(|h| h.id == "std-h-putz").unwrap().pattern, crate::model::HatchPattern::Dots);
|
||||
}
|
||||
|
||||
fn alt_projekt() -> Map<String, Value> {
|
||||
// Projekt mit Standards vom 29.10.: alte EPS-Schraffur, Putz ohne Schraffur, eine umbenannte und
|
||||
// eine eigene Schraffur.
|
||||
let mut root = apply(&empty_root(), &merge_ops(&empty_root()));
|
||||
let hs = root.get_mut("hatches").unwrap().as_array_mut().unwrap();
|
||||
hs.retain(|h| h["id"] != "std-h-putz");
|
||||
for h in hs.iter_mut() {
|
||||
if h["id"] == "std-h-eps" {
|
||||
h["pattern"] = json!("insulation");
|
||||
}
|
||||
if h["id"] == "std-h-xps" {
|
||||
h["name"] = json!("Meine XPS");
|
||||
h["pattern"] = json!("diagonal");
|
||||
}
|
||||
}
|
||||
hs.push(json!({"id": "mine", "name": "Eigene", "pattern": "diagonal", "scale": 1, "angle": 0, "color": "#000"}));
|
||||
for c in root.get_mut("components").unwrap().as_array_mut().unwrap() {
|
||||
if c["id"] == "std-c-innenputz" {
|
||||
c["hatchId"] = json!("std-h-ohne");
|
||||
}
|
||||
}
|
||||
root
|
||||
}
|
||||
|
||||
fn apply_all(root: &Map<String, Value>, ops: &[Value]) -> Map<String, Value> {
|
||||
let mut r = root.clone();
|
||||
for op in ops {
|
||||
match op["kind"].as_str().unwrap() {
|
||||
"add" => r.get_mut(op["collection"].as_str().unwrap()).unwrap().as_array_mut().unwrap().extend(op["items"].as_array().unwrap().iter().cloned()),
|
||||
"setField" => {
|
||||
r.insert(op["key"].as_str().unwrap().into(), op["value"].clone());
|
||||
}
|
||||
"replace" => {
|
||||
let list = r.get_mut(op["collection"].as_str().unwrap()).unwrap().as_array_mut().unwrap();
|
||||
let i = list.iter().position(|e| e["id"] == op["entity"]["id"]).unwrap();
|
||||
list[i] = op["entity"].clone();
|
||||
}
|
||||
k => panic!("{k}"),
|
||||
}
|
||||
}
|
||||
r
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn aktualisieren_listet_abweichungen_und_ersetzt_gewaehlte() {
|
||||
let root = alt_projekt();
|
||||
let plan = update_plan(&root);
|
||||
assert_eq!(plan["added"], 1, "Putz-Schraffur fehlt");
|
||||
let ch = plan["changes"].as_array().unwrap();
|
||||
let find = |id: &str| ch.iter().find(|c| c["id"] == id);
|
||||
assert_eq!(find("std-h-eps").unwrap()["fields"], json!(["pattern"]));
|
||||
assert_eq!(find("std-h-eps").unwrap()["renamed"], false);
|
||||
assert_eq!(find("std-h-xps").unwrap()["renamed"], true, "umbenannt: abgewählt");
|
||||
assert!(find("std-h-xps").unwrap()["fields"].as_array().unwrap().iter().any(|f| f == "pattern"));
|
||||
assert_eq!(find("std-c-innenputz").unwrap()["fields"], json!(["hatchId"]), "Verweis zeigt künftig auf die ergänzte Putz-Schraffur");
|
||||
assert!(find("mine").is_none() && find("std-h-beton").is_none(), "Eigenes und Unverändertes nicht");
|
||||
let ops = update_ops(&root, &["hatches:std-h-eps".to_string(), "components:std-c-innenputz".to_string()]);
|
||||
let after = apply_all(&root, &ops);
|
||||
let get = |k: &str, id: &str| after[k].as_array().unwrap().iter().find(|e| e["id"] == id).unwrap().clone();
|
||||
assert_eq!(get("hatches", "std-h-eps")["pattern"], "insulationHard");
|
||||
assert_eq!(get("hatches", "std-h-xps")["pattern"], "diagonal", "nicht gewählt: bleibt");
|
||||
assert_eq!(get("components", "std-c-innenputz")["hatchId"], "std-h-putz");
|
||||
assert!(after["hatches"].as_array().unwrap().iter().any(|h| h["id"] == "std-h-putz"));
|
||||
let left = update_plan(&after);
|
||||
assert_eq!(left["added"], 0);
|
||||
assert!(left["changes"].as_array().unwrap().iter().all(|c| c["id"] == "std-h-xps"));
|
||||
let all: Vec<String> = left["changes"].as_array().unwrap().iter().map(|c| format!("{}:{}", c["collection"].as_str().unwrap(), c["id"].as_str().unwrap())).collect();
|
||||
let done = apply_all(&after, &update_ops(&after, &all));
|
||||
assert!(update_plan(&done)["changes"].as_array().unwrap().is_empty());
|
||||
let p: Project = serde_json::from_value(Value::Object(done)).unwrap();
|
||||
assert!(crate::project_refs::dangling_refs(&p).is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn aktualisieren_entfernt_nicht_mehr_gefuehrte_felder_und_laesst_zusatzfelder() {
|
||||
let mut root = apply(&empty_root(), &merge_ops(&empty_root()));
|
||||
for h in root.get_mut("hatches").unwrap().as_array_mut().unwrap() {
|
||||
if h["id"] == "std-h-eps" {
|
||||
h["lineStyleId"] = json!("std-ls-voll");
|
||||
h["myNote"] = json!("bleibt");
|
||||
}
|
||||
}
|
||||
let after = apply_all(&root, &update_ops(&root, &["hatches:std-h-eps".to_string()]));
|
||||
let eps = after["hatches"].as_array().unwrap().iter().find(|h| h["id"] == "std-h-eps").unwrap();
|
||||
assert!(eps.get("lineStyleId").is_none());
|
||||
assert_eq!(eps["myNote"], "bleibt");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn zweites_laden_verdoppelt_nichts() {
|
||||
let once = apply(&empty_root(), &merge_ops(&empty_root()));
|
||||
|
||||
@@ -42,10 +42,15 @@ fn pattern_id(p: HatchPattern) -> f64 {
|
||||
HatchPattern::Solid => 1.0,
|
||||
HatchPattern::Diagonal => 2.0,
|
||||
HatchPattern::Crosshatch => 3.0,
|
||||
HatchPattern::Insulation | HatchPattern::InsulationHard | HatchPattern::InsulationWave => 4.0,
|
||||
// 3D-Schnittflächen (render3d) kennen nur die Grundmuster: nächstliegendes ([109]).
|
||||
HatchPattern::Timber | HatchPattern::Earth => 3.0,
|
||||
HatchPattern::Gravel | HatchPattern::Stone => 2.0,
|
||||
// Ab 4: Muster-Code des Kern-Generators (render3d zeichnet die Linien selbst, [109]).
|
||||
HatchPattern::Insulation => 4.0,
|
||||
HatchPattern::InsulationHard => 6.0,
|
||||
HatchPattern::InsulationWave => 7.0,
|
||||
HatchPattern::Timber => 8.0,
|
||||
HatchPattern::Earth => 9.0,
|
||||
HatchPattern::Gravel => 10.0,
|
||||
HatchPattern::Stone => 11.0,
|
||||
HatchPattern::Dots => 12.0,
|
||||
_ => 0.0,
|
||||
}
|
||||
}
|
||||
|
||||
Generated
+114
@@ -0,0 +1,114 @@
|
||||
# This file is automatically @generated by Cargo.
|
||||
# It is not intended for manual editing.
|
||||
version = 4
|
||||
|
||||
[[package]]
|
||||
name = "bumpalo"
|
||||
version = "3.20.3"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "72f5acc6cb2ba439de613abc23857ec3d78374d8ed5ac84e9d11336e87da8649"
|
||||
|
||||
[[package]]
|
||||
name = "cfg-if"
|
||||
version = "1.0.5"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "4e7648175b45a9a48536d676f68d918270699102aa8dab5496df06904c914600"
|
||||
|
||||
[[package]]
|
||||
name = "dossier-hatch"
|
||||
version = "0.1.0"
|
||||
dependencies = [
|
||||
"wasm-bindgen",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "once_cell"
|
||||
version = "1.21.4"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9f7c3e4beb33f85d45ae3e3a1792185706c8e16d043238c593331cc7cd313b50"
|
||||
|
||||
[[package]]
|
||||
name = "proc-macro2"
|
||||
version = "1.0.107"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "985e7ec9bb745e6ce6535b544d84d6cd6f7ad8bd711c398938ae983b91a766d9"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "quote"
|
||||
version = "1.0.47"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "1fbf4db142a473a8d80c26bbf18454ed458bf8d26c8219c331daecfdbd079001"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "rustversion"
|
||||
version = "1.0.23"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "cf54715a573b99ac80df0bc206da022bcd442c974952c7b9720069370852e21f"
|
||||
|
||||
[[package]]
|
||||
name = "syn"
|
||||
version = "3.0.9"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "d78c8dee4c7bf0e14673097256fed6142ce9d3b85a408189d07482442145823b"
|
||||
dependencies = [
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"unicode-ident",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "unicode-ident"
|
||||
version = "1.0.27"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "a2c754d6c33795a1c324727428e5a7dedb5b06195f9890bdbcba760d3e246563"
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen"
|
||||
version = "0.2.129"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "9bb54f33acc68fd454578d9820b0bde1a1a3d17aa17bb7b6595806d02886d409"
|
||||
dependencies = [
|
||||
"cfg-if",
|
||||
"once_cell",
|
||||
"rustversion",
|
||||
"wasm-bindgen-macro",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro"
|
||||
version = "0.2.129"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "2e29d0c35b16e224a7eeb5cd2d25e3e1968fbd65604117b44d3b789d00ee8535"
|
||||
dependencies = [
|
||||
"quote",
|
||||
"wasm-bindgen-macro-support",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-macro-support"
|
||||
version = "0.2.129"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "6f501a8bc3719dba86ef8ae4728879c08001bea749eb1333ac5b91e040e2a6b7"
|
||||
dependencies = [
|
||||
"bumpalo",
|
||||
"proc-macro2",
|
||||
"quote",
|
||||
"syn",
|
||||
"wasm-bindgen-shared",
|
||||
]
|
||||
|
||||
[[package]]
|
||||
name = "wasm-bindgen-shared"
|
||||
version = "0.2.129"
|
||||
source = "registry+https://github.com/rust-lang/crates.io-index"
|
||||
checksum = "23f0c9c52aa7cd7d77769a4cfe2a9adb1b331f489a41d912ce14513d5ab995c6"
|
||||
dependencies = [
|
||||
"unicode-ident",
|
||||
]
|
||||
@@ -0,0 +1,20 @@
|
||||
# Kein eigener [workspace]-Block (wie render3d): der Parent `src-tauri/Cargo.toml` schliesst das Crate per
|
||||
# `exclude` aus; es baut standalone (`cd hatchgen && cargo test`) und als Pfad-Abhaengigkeit von core/render3d.
|
||||
|
||||
[package]
|
||||
name = "dossier-hatch"
|
||||
version = "0.1.0"
|
||||
edition = "2021"
|
||||
description = "Schraffur-Generator (Linien, Schichtmuster) als eigenes Crate: dossier-core (Plan/Schnitt/Ansicht) und render3d (Live-Schnitt) zeichnen damit dieselben Linien. Nur JS-Zahlsemantik (jsnum, jsmath), keine weiteren Abhaengigkeiten."
|
||||
license = "AGPL-3.0-or-later"
|
||||
|
||||
[lib]
|
||||
name = "dossier_hatch"
|
||||
|
||||
[features]
|
||||
default = []
|
||||
# Math-Aufrufe der JS-Engine (bitgleich zu TS), nur wasm32; vom Kern (Feature "web") durchgereicht.
|
||||
web = ["dep:wasm-bindgen"]
|
||||
|
||||
[dependencies]
|
||||
wasm-bindgen = { version = "0.2", optional = true }
|
||||
@@ -50,6 +50,7 @@ pub enum Pattern {
|
||||
Earth = 9,
|
||||
Gravel = 10,
|
||||
Stone = 11,
|
||||
Dots = 12,
|
||||
}
|
||||
|
||||
impl Pattern {
|
||||
@@ -66,6 +67,7 @@ impl Pattern {
|
||||
9 => Pattern::Earth,
|
||||
10 => Pattern::Gravel,
|
||||
11 => Pattern::Stone,
|
||||
12 => Pattern::Dots,
|
||||
_ => Pattern::Diagonal,
|
||||
}
|
||||
}
|
||||
@@ -417,6 +419,7 @@ pub fn build_hatch_runs(poly: &[V2], hatch: &Hatch) -> Vec<Run> {
|
||||
Pattern::Timber => return timber_band_runs(poly, hatch, scale),
|
||||
Pattern::Earth => return earth_runs(poly, hatch, scale),
|
||||
Pattern::Gravel => return gravel_runs(poly, hatch, scale),
|
||||
Pattern::Dots => return dots_runs(poly, hatch, scale),
|
||||
_ => {}
|
||||
}
|
||||
let spacing_m = 8.0 * scale * PX_TO_M;
|
||||
@@ -659,6 +662,45 @@ fn gravel_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
|
||||
runs
|
||||
}
|
||||
|
||||
/// Punktfeld (Putz, SIA 400): feine, ruhige Punkte im versetzten Raster, entlang der Schicht ausgerichtet
|
||||
/// (Schichtmuster: Laufrichtung = Schraffurwinkel, Bänder wie bei der Dämmung). Teilung entlang u = 0.05 m ·
|
||||
/// scale; die Reihen füllen die Schichtdicke gleichmässig (Reihenabstand ≈ 0.87 · Teilung, mindestens eine
|
||||
/// Reihe in der Schichtmitte, damit auch dünne Putzschichten Punkte bekommen). Jeder Punkt ein winziger
|
||||
/// Strich (30 % der Teilung); nur Punkte, die ganz in der Fläche liegen (ruhiger Rand).
|
||||
fn dots_runs(poly: &[V2], hatch: &Hatch, scale: f64) -> Vec<Run> {
|
||||
let Some(b) = band_frame(poly, hatch, scale) else { return Vec::new() };
|
||||
let pitch = (0.05 * scale).max(0.004);
|
||||
let half_dot = 0.15 * pitch;
|
||||
if (b.u1 - b.u0) / pitch > BAND_MAX_POINTS {
|
||||
return Vec::new();
|
||||
}
|
||||
let mut runs = Vec::new();
|
||||
for &(vc, half) in &b.rows {
|
||||
let k = (2.0 * half / (0.87 * pitch)).round().max(1.0);
|
||||
if k > 5_000.0 {
|
||||
continue;
|
||||
}
|
||||
let step = 2.0 * half / k;
|
||||
let mut r = 0.0;
|
||||
while r < k {
|
||||
let v = vc - half + (r + 0.5) * step;
|
||||
let shift = if r.rem_euclid(2.0) == 0.0 { 0.0 } else { 0.5 };
|
||||
let mut i = ((b.u0 - b.ua) / pitch).floor() - 1.0;
|
||||
while b.ua + (i + shift) * pitch <= b.u1 + pitch {
|
||||
let cu = b.ua + (i + shift) * pitch;
|
||||
let (a, e) = (b.at(cu - half_dot, v), b.at(cu + half_dot, v));
|
||||
let kept = clip_segment_to_polygon(a, e, poly);
|
||||
if kept.len() == 1 && hypot2(kept[0].1.x - kept[0].0.x, kept[0].1.y - kept[0].0.y) > 1.9 * half_dot {
|
||||
runs.push(vec![a, e]);
|
||||
}
|
||||
i += 1.0;
|
||||
}
|
||||
r += 1.0;
|
||||
}
|
||||
}
|
||||
runs
|
||||
}
|
||||
|
||||
// ── Random-Schraffur ────────────────────────────────────────────────────────
|
||||
|
||||
/// mulberry32 (deterministischer 32-bit-PRNG).
|
||||
@@ -1006,10 +1048,38 @@ mod tests {
|
||||
assert!((st / d - 2.0).abs() < 0.1, "{st} / {d}");
|
||||
}
|
||||
|
||||
/// Putz: ruhiges Punktfeld entlang der Schicht, nur ganze Punkte, stabil, versetzte Reihen; auch eine
|
||||
/// dünne Putzschicht (1.5 cm) bekommt mindestens eine Reihe.
|
||||
#[test]
|
||||
fn putz_punktfeld() {
|
||||
let mut h = hatch(Pattern::Dots);
|
||||
h.angle = 0.0;
|
||||
h.scale = 0.4; // Teilung 2 cm
|
||||
let sq = band(1.0, 0.1);
|
||||
let runs = build_hatch_runs(&sq, &h);
|
||||
// 10 cm: 5 Reihen à ~50 Punkte
|
||||
assert!((200..300).contains(&runs.len()), "{}", runs.len());
|
||||
assert!(runs.iter().all(|r| r.len() == 2 && (r[1].x - r[0].x - 0.006).abs() < 1e-9 && r[0].y == r[1].y), "Punkte sind winzige Striche");
|
||||
let (lo, hi) = extent(&runs, |p| p.x);
|
||||
assert!(lo >= 0.0 && hi <= 1.0);
|
||||
assert_eq!(runs, build_hatch_runs(&sq, &h));
|
||||
let (ylo, yhi) = extent(&runs, |p| p.y);
|
||||
assert!(ylo > 0.0 && yhi < 0.1);
|
||||
// dünne Schicht
|
||||
let thin = build_hatch_runs(&band(1.0, 0.015), &h);
|
||||
assert!(thin.len() > 30, "{}", thin.len());
|
||||
assert!(thin.iter().all(|r| r[0].y >= 0.0 && r[0].y <= 0.015));
|
||||
// versetzte Reihen: mindestens zwei Phasen in x
|
||||
let mut phases: Vec<i64> = runs.iter().map(|r| ((r[0].x / 0.02).rem_euclid(1.0) * 100.0).round() as i64 % 100).collect();
|
||||
phases.sort();
|
||||
phases.dedup();
|
||||
assert!(phases.len() >= 2, "{phases:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn schichtmuster_entartet_leer() {
|
||||
let p = vec![v2(0.0, 0.0), v2(f64::INFINITY, 0.0), v2(1.0, 1.0)];
|
||||
for pat in [Pattern::InsulationHard, Pattern::InsulationWave, Pattern::Timber, Pattern::Earth, Pattern::Gravel, Pattern::Stone] {
|
||||
for pat in [Pattern::InsulationHard, Pattern::InsulationWave, Pattern::Timber, Pattern::Earth, Pattern::Gravel, Pattern::Stone, Pattern::Dots] {
|
||||
assert!(build_hatch_runs(&p, &hatch(pat)).is_empty(), "{pat:?}");
|
||||
}
|
||||
// Linie ohne Dicke
|
||||
File renamed without changes.
File renamed without changes.
@@ -0,0 +1,6 @@
|
||||
//! Schraffur-Generator ([109]): `hatch` (Linien-, Schicht-, Streumuster), `jsnum`/`jsmath` (JS-Zahlsemantik).
|
||||
//! Gemeinsam genutzt von `dossier-core` (Re-Export unter `crate::hatch` usw.) und `render3d` (Live-Schnitt).
|
||||
|
||||
pub mod hatch;
|
||||
pub mod jsmath;
|
||||
pub mod jsnum;
|
||||
@@ -57,6 +57,8 @@ web = [
|
||||
|
||||
[dependencies]
|
||||
serde = { version = "1", features = ["derive"] }
|
||||
# Schraffur-Generator des Kerns (Live-Schnitt zeichnet dieselben Musterlinien wie Plan/Schnitt, [109]).
|
||||
dossier-hatch = { path = "../hatchgen" }
|
||||
# JSON-Modell (dieselbe Ableitung wie der native Push): im Web-Pfad zur Laufzeit
|
||||
# geparst; optional, nur mit Feature "web".
|
||||
serde_json = { version = "1", optional = true }
|
||||
|
||||
@@ -34,6 +34,7 @@
|
||||
//! Rechteck (4 Ecken, siehe `section.rs`) — Fan-Triangulierung genuegt.
|
||||
|
||||
use crate::section::{cut_section, CutPolygon, SectionPlane};
|
||||
use dossier_hatch::hatch::{build_hatch_runs, v2, Hatch as GenHatch, HatchKind, Pattern};
|
||||
use crate::section_boolean::subtract_dominant_bands;
|
||||
use crate::types::{RoofLayerInput, SlabInput, WallInput};
|
||||
|
||||
@@ -78,6 +79,12 @@ const CUT_LINE_MM_TO_WORLD: f32 = 0.01;
|
||||
/// sichtbar VOR den Cut-Caps liegen (die exakt auf der Ebene sitzen).
|
||||
const CUT_LINE_LIFT: f32 = 0.002;
|
||||
|
||||
/// Ab dieser Muster-Id zeichnet NICHT der Cap-Shader, sondern der Kern-Generator (`dossier_hatch`, derselbe
|
||||
/// wie in Plan/Schnitt — Dämmschlange, Zickzack, Welle, Holzkreuz, Naturstein, Erdreich, Kies, Punktfeld):
|
||||
/// die Ids sind die Muster-Codes des Generators (`Pattern::from_code`). Der Shader füllt solche Flächen leer
|
||||
/// (Papier); die Linien kommen als Ribbons (`build_cut_cap_lines`).
|
||||
pub const GENERATED_PATTERN_MIN: u32 = 4;
|
||||
|
||||
/// Fallback-Muster-Id, wenn ein Cut-Polygon keine `hatch` traegt: 2 = diagonal
|
||||
/// (45°) — reproduziert mit `angle_rad = 0`, `scale = 1` exakt das fruehere fest
|
||||
/// verdrahtete 45°-Muster (Rueckwaertskompatibilitaet fuer Waende/Decken ohne
|
||||
@@ -138,7 +145,8 @@ pub fn build_cut_caps(
|
||||
// cos/sin rechnen kann.
|
||||
let (pattern, angle_rad, scale, line_weight) = match poly.hatch {
|
||||
Some(h) => (
|
||||
h.pattern as f32,
|
||||
// Generator-Muster: Shader zeichnet nichts (Id 0), die Linien kommen als Ribbons.
|
||||
if h.pattern >= GENERATED_PATTERN_MIN { 0.0 } else { h.pattern as f32 },
|
||||
h.angle.to_radians(),
|
||||
h.scale.max(0.05),
|
||||
h.line_weight.max(0.0),
|
||||
@@ -229,10 +237,53 @@ pub fn build_cut_cap_lines(
|
||||
let b = to_world(poly.pts[(k + 1) % n]);
|
||||
push_line_ribbon(&mut verts, a, b, normal, half_w, color);
|
||||
}
|
||||
push_generated_hatch(&mut verts, poly, &to_world, normal);
|
||||
}
|
||||
verts
|
||||
}
|
||||
|
||||
/// Muster-Tinte der Generator-Schraffur (wie `ink` im Cap-Shader).
|
||||
const HATCH_INK: [f32; 3] = [0.06, 0.06, 0.06];
|
||||
|
||||
/// Musterlinien eines Cut-Polygons mit Generator-Muster (`GENERATED_PATTERN_MIN`) als Ribbons: dieselben
|
||||
/// Linien wie im 2D-Schnitt (`dossier_hatch::hatch::build_hatch_runs`, Polygon (u,v) in Metern, Winkel und
|
||||
/// Skala der Bauteil-Schraffur). Breite wie die Shader-Linien (mm-Papier -> Welt über `CUT_LINE_MM_TO_WORLD`).
|
||||
fn push_generated_hatch(
|
||||
out: &mut Vec<f32>,
|
||||
poly: &CutPolygon,
|
||||
to_world: &dyn Fn([f32; 2]) -> [f32; 3],
|
||||
normal: [f32; 3],
|
||||
) {
|
||||
let Some(h) = poly.hatch else { return };
|
||||
if h.pattern < GENERATED_PATTERN_MIN || poly.pts.len() < 3 {
|
||||
return;
|
||||
}
|
||||
let gen = GenHatch {
|
||||
pattern: Pattern::from_code(h.pattern as f64),
|
||||
kind: HatchKind::Vector,
|
||||
random: false,
|
||||
scale: h.scale.max(0.05) as f64,
|
||||
angle: h.angle as f64,
|
||||
line_weight: h.line_weight as f64,
|
||||
origin: None,
|
||||
seed: None,
|
||||
density: None,
|
||||
length_min: None,
|
||||
length_max: None,
|
||||
dash: Vec::new(),
|
||||
motif: None,
|
||||
};
|
||||
let pts: Vec<_> = poly.pts.iter().map(|p| v2(p[0] as f64, p[1] as f64)).collect();
|
||||
let half_w = (h.line_weight.max(0.0) * CUT_LINE_MM_TO_WORLD * 0.5).max(1e-4);
|
||||
for run in build_hatch_runs(&pts, &gen) {
|
||||
for w in run.windows(2) {
|
||||
let a = to_world([w[0].x as f32, w[0].y as f32]);
|
||||
let b = to_world([w[1].x as f32, w[1].y as f32]);
|
||||
push_line_ribbon(out, a, b, normal, half_w, HATCH_INK);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Legt ein flaches Ribbon-Quad (2 Dreiecke) der halben Breite `half_w` um die
|
||||
/// Kante `a`->`b`, verbreitert IN der Schnittebene (senkrecht zur Kante ueber
|
||||
/// `cross(normal, dir)`), und schreibt es als 6 Vertices `[pos, color]` in `out`.
|
||||
@@ -333,6 +384,43 @@ mod tests {
|
||||
}
|
||||
}
|
||||
|
||||
/// Generator-Muster (Id >= 4, hier 4 Daemmschlange): der Shader bekommt Id 0 (Papier), die Linien kommen als
|
||||
/// Ribbons aus dem Kern-Generator in den Cut-Linien — mehr Dreiecke als ohne Muster, alle in der Schnittebene.
|
||||
#[test]
|
||||
fn generator_muster_kommt_als_ribbons() {
|
||||
let mk = |pattern: u32| WallInput {
|
||||
top_drop: [0.0, 0.0],
|
||||
start: [0.0, 0.0],
|
||||
end: [3.0, 0.0],
|
||||
thickness: 0.3,
|
||||
height: 2.5,
|
||||
base_elevation: 0.0,
|
||||
color: [0.8, 0.8, 0.8],
|
||||
openings: vec![],
|
||||
layers: None,
|
||||
holes: vec![],
|
||||
material_index: None,
|
||||
hatch: Some(Hatch { pattern, angle: -90.0, scale: 1.0, line_weight: 0.13, top_angle: None }),
|
||||
cut: None,
|
||||
start_cut: None,
|
||||
end_cut: None,
|
||||
};
|
||||
let plane = SectionPlane::looking_plus_x(1.5);
|
||||
let caps = build_cut_caps(&plane, &[mk(4)], &[], &[]);
|
||||
assert!(!caps.is_empty());
|
||||
for i in 0..caps.len() / CAP_FLOATS_PER_VERTEX {
|
||||
assert_eq!(caps[i * CAP_FLOATS_PER_VERTEX + 5], 0.0, "Shader zeichnet kein Muster");
|
||||
}
|
||||
let plain = build_cut_cap_lines(&plane, &[mk(0)], &[], &[]);
|
||||
for pat in [4u32, 6, 7, 8, 9, 10, 11, 12] {
|
||||
let lines = build_cut_cap_lines(&plane, &[mk(pat)], &[], &[]);
|
||||
assert!(lines.len() > plain.len() + 6 * CUT_LINE_FLOATS_PER_VERTEX * 10, "Muster {pat}: Musterlinien fehlen");
|
||||
assert_eq!(lines.len() % CUT_LINE_FLOATS_PER_VERTEX, 0);
|
||||
}
|
||||
// Diagonale/Kreuz bleiben im Shader (keine Ribbons)
|
||||
assert_eq!(build_cut_cap_lines(&plane, &[mk(2)], &[], &[]).len(), plain.len());
|
||||
}
|
||||
|
||||
/// Ohne `hatch` faellt jedes Cap-Polygon auf das Diagonalmuster (Id 2,
|
||||
/// angle 0, scale 1) zurueck — das reproduziert das fruehere fixe 45°-Muster.
|
||||
#[test]
|
||||
|
||||
@@ -374,7 +374,8 @@ fn fs_main(in : VsOut) -> @location(0) vec4<f32> {
|
||||
/// passend zur 2D-Schnittkonvention `HATCH_INK`): es variiert das MUSTER, nicht die
|
||||
/// Farbe. Muster-Ids: 0 = none (leer/weiss), 1 = solid (Vollton),
|
||||
/// 2 = diagonal (Linienschar, `angle` steuert die Neigung — 0° = horizontal, wie
|
||||
/// im 2D), 3 = crosshatch (Kreuz), 4 = insulation (Zickzack/Daemmung).
|
||||
/// im 2D), 3 = crosshatch (Kreuz); ab 4 (Daemmung, Holz, Naturstein, Erdreich, Kies, Putz) kommen die Musterlinien
|
||||
/// aus dem Kern-Generator (`dossier_hatch`, Ribbons in `section_fill`), der Shader zeichnet dort Papier.
|
||||
pub const CAP_WGSL: &str = r#"
|
||||
struct Globals {
|
||||
view_proj : mat4x4<f32>,
|
||||
@@ -459,10 +460,6 @@ fn fs_main(in : VsOut) -> @location(0) vec4<f32> {
|
||||
let sv = dv / spacing;
|
||||
let fw_u = fwidth(su);
|
||||
let fw_v = fwidth(sv);
|
||||
let cell = spacing * 2.0;
|
||||
let tri = abs(fract(du / cell) - 0.5) * 2.0; // 0..1 Dreieckswelle (Daemmung)
|
||||
let fb = fract(dv / cell);
|
||||
let fw_zig = fwidth(fb) + fwidth(tri);
|
||||
|
||||
// none (0): leere (weisse) Schnittflaeche — wie „keine Schraffur" im 2D.
|
||||
if (pattern == 0) {
|
||||
@@ -485,14 +482,9 @@ fn fs_main(in : VsOut) -> @location(0) vec4<f32> {
|
||||
line_band(sv, half_s, fw_v),
|
||||
line_band(su, half_s, fw_u)
|
||||
);
|
||||
} else {
|
||||
// insulation (4, Daemmung): Zickzack. Die Quer-Position (dv) folgt einer
|
||||
// Dreieckswelle entlang der Lauf-Achse (du) — ein durchgehender Zickzack.
|
||||
let d = min(abs(fb - tri), min(abs(fb - tri + 1.0), abs(fb - tri - 1.0)));
|
||||
let aa = max(fw_zig, 1e-5);
|
||||
let hw = half / cell;
|
||||
line = 1.0 - smoothstep(hw, hw + aa, d);
|
||||
}
|
||||
// Ids ab 4 (Daemmung, Holz, Naturstein, Erdreich, Kies, Putz ...) zeichnet der Kern-Generator als
|
||||
// Ribbons (section_fill::push_generated_hatch); der Shader laesst die Flaeche leer (Papier).
|
||||
|
||||
let color = mix(paper, ink, clamp(line, 0.0, 1.0));
|
||||
return vec4<f32>(color, 1.0);
|
||||
|
||||
@@ -27,7 +27,7 @@ pub type Rgb = [f32; 3];
|
||||
/// siehe 2D-Direktive `HATCH_INK`) und wandert deshalb bewusst NICHT mit.
|
||||
///
|
||||
/// `pattern`: 0 = none (leer/weiss), 1 = solid (Vollton), 2 = diagonal (45°),
|
||||
/// 3 = crosshatch (Kreuz), 4 = insulation (Zickzack/Daemmung). Die Zuordnung ist
|
||||
/// 3 = crosshatch (Kreuz), ab 4 = Muster-Code des Kern-Generators (`dossier_hatch::Pattern`: 4 Daemmschlange, 6-7 Hartschaum/Welle, 8 Holz, 9 Erdreich, 10 Kies, 11 Naturstein, 12 Punktfeld). Die Zuordnung ist
|
||||
/// mit der TS-Seite (`toWalls3d::hatchPatternId`) und dem Shader synchron zu halten.
|
||||
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
|
||||
pub struct Hatch {
|
||||
|
||||
Reference in new issue
Block a user