Merge Analyse-Module nach Rust (Schatten, Baurecht, Aussenbemassung, Kennzahlen); TODO.md [K1]/[K2] nachgefuehrt, CLAUDE.md: hoechstens 2 Agents, Modell je Aufgabe
CLI-Gegenprobe identisch: Parzelle 320 m2, zulaessig 66 m2, Verstoss 2.296 m2, Sonnenhoehe auf 6 Stellen. Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
19 files changed
+1548
-387
No files matched your search
@@ -0,0 +1,41 @@
|
||||
//! Bindungen der automatischen Aussenbemassung (`crate::auto_dimensions`).
|
||||
|
||||
use crate::auto_dimensions::{self, OpeningIn, WallIn};
|
||||
use crate::flat_read::Reader;
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
fn read_walls(buf: &[f64]) -> Option<Vec<WallIn>> {
|
||||
let mut r = Reader::new(buf);
|
||||
let n = r.count()?;
|
||||
let mut out = Vec::with_capacity(n.min(1 << 16));
|
||||
for _ in 0..n {
|
||||
out.push(WallIn { start: [r.num()?, r.num()?], end: [r.num()?, r.num()?], thickness: r.num()? });
|
||||
}
|
||||
Some(out)
|
||||
}
|
||||
|
||||
fn read_openings(buf: &[f64]) -> Option<Vec<OpeningIn>> {
|
||||
let mut r = Reader::new(buf);
|
||||
let n = r.count()?;
|
||||
let mut out = Vec::with_capacity(n.min(1 << 16));
|
||||
for _ in 0..n {
|
||||
let wall = r.count()?;
|
||||
out.push(OpeningIn { wall, jamb_start: [r.num()?, r.num()?], jamb_end: [r.num()?, r.num()?] });
|
||||
}
|
||||
Some(out)
|
||||
}
|
||||
|
||||
/// Wände `[n, (x0, y0, x1, y1, dicke)…]`, Öffnungen `[n, (wandIndex, ax, ay, bx, by)…]`
|
||||
/// → `[n, (seite, kette, abstand, nPkt, x, y, …)…]` (Seite 0..3 = Süd/Ost/Nord/West,
|
||||
/// Kette 0..2 = Öffnungen/Vor-Rücksprünge/Gesamt).
|
||||
#[wasm_bindgen]
|
||||
pub fn autodim_chains(walls: &[f64], openings: &[f64], scale_denominator: f64) -> Vec<f64> {
|
||||
let (Some(w), Some(o)) = (read_walls(walls), read_openings(openings)) else { return vec![0.0] };
|
||||
let chains = auto_dimensions::auto_exterior_dimensions(&w, &o, scale_denominator);
|
||||
let mut out = vec![chains.len() as f64];
|
||||
for c in chains {
|
||||
out.extend([c.side as f64, c.chain as f64, c.offset, c.pts.len() as f64]);
|
||||
out.extend(c.pts.into_iter().flatten());
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -0,0 +1,50 @@
|
||||
//! Bindungen der Kennzahlen-Rechenteile (`crate::kennzahlen`).
|
||||
|
||||
use crate::flat_read::pairs;
|
||||
use crate::flat_read::Reader;
|
||||
use crate::kennzahlen::{self, RoomIn, SolidIn};
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
/// Grundriss `[x0, y0, …]`, Kreisradius (NaN = kein Kreis), Höhe, Verjüngung → m³.
|
||||
#[wasm_bindgen]
|
||||
pub fn kz_solid_volume(points: &[f64], circle_r: f64, height: f64, taper: f64) -> f64 {
|
||||
kennzahlen::solid_volume(&pairs(points), circle_r, height, taper)
|
||||
}
|
||||
|
||||
fn read_rooms(buf: &[f64]) -> Option<Vec<RoomIn>> {
|
||||
let mut r = Reader::new(buf);
|
||||
let n = r.count()?;
|
||||
let mut out = Vec::with_capacity(n.min(1 << 16));
|
||||
for _ in 0..n {
|
||||
let (level, category) = (r.count()?, r.count()?);
|
||||
out.push(RoomIn { level, category, boundary: r.ring()? });
|
||||
}
|
||||
Some(out)
|
||||
}
|
||||
|
||||
fn read_solids(buf: &[f64]) -> Option<Vec<SolidIn>> {
|
||||
let mut r = Reader::new(buf);
|
||||
let n = r.count()?;
|
||||
let mut out = Vec::with_capacity(n.min(1 << 16));
|
||||
for _ in 0..n {
|
||||
let subtract = r.num()? != 0.0;
|
||||
let (circle_r, height, taper) = (r.num()?, r.num()?, r.num()?);
|
||||
out.push(SolidIn { subtract, points: r.ring()?, circle_r, height, taper });
|
||||
}
|
||||
Some(out)
|
||||
}
|
||||
|
||||
/// Räume `[n, (geschoss, kategorie, nPkt, x, y, …)…]`, Körper
|
||||
/// `[n, (abzug 0/1, radius|NaN, höhe, verjüngung, nPkt, x, y, …)…]`, Parzellenzahl, Parzellenring
|
||||
/// `[x0, y0, …]` → `[gv, parzelle|NaN, (6 Kategorie-Summen je Geschoss)…]`.
|
||||
#[wasm_bindgen]
|
||||
pub fn kz_area_sums(n_levels: u32, rooms: &[f64], solids: &[f64], parcel_area: f64, parcel_ring: &[f64]) -> Vec<f64> {
|
||||
let rooms = read_rooms(rooms).unwrap_or_default();
|
||||
let solids = read_solids(solids).unwrap_or_default();
|
||||
let s = kennzahlen::area_sums(n_levels.min(1 << 16) as usize, &rooms, &solids, parcel_area, &pairs(parcel_ring));
|
||||
let mut out = vec![s.gv, s.parcel.unwrap_or(f64::NAN)];
|
||||
for l in s.by_level {
|
||||
out.extend(l);
|
||||
}
|
||||
out
|
||||
}
|
||||
@@ -6,6 +6,10 @@
|
||||
mod kernel2d;
|
||||
mod polygon;
|
||||
mod roof;
|
||||
mod sun;
|
||||
mod site_rules;
|
||||
mod auto_dimensions;
|
||||
mod kennzahlen;
|
||||
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
|
||||
@@ -0,0 +1,45 @@
|
||||
//! Bindungen des Baurechts (`crate::site_rules`).
|
||||
|
||||
use crate::flat::{decode, encode};
|
||||
use crate::flat_read::Reader;
|
||||
use crate::site_rules::{self, BuildingLine, SiteRules};
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
/// `[nPkt, x, y, …, nAbstände, d0, d1, …, nLinien, (ax, ay, bx, by)…]`.
|
||||
fn read_rules(buf: &[f64]) -> Option<SiteRules> {
|
||||
let mut r = Reader::new(buf);
|
||||
let parcel = r.ring()?;
|
||||
let n = r.count()?;
|
||||
let mut setbacks = Vec::with_capacity(n.min(1 << 16));
|
||||
for _ in 0..n {
|
||||
setbacks.push(r.num()?);
|
||||
}
|
||||
let n = r.count()?;
|
||||
let mut lines = Vec::with_capacity(n.min(1 << 16));
|
||||
for _ in 0..n {
|
||||
lines.push(BuildingLine { a: [r.num()?, r.num()?], b: [r.num()?, r.num()?] });
|
||||
}
|
||||
Some(SiteRules { parcel, setbacks, lines })
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn site_multi_polygon_area(polys: &[f64]) -> f64 {
|
||||
site_rules::multi_polygon_area(&decode(polys).unwrap_or_default())
|
||||
}
|
||||
|
||||
#[wasm_bindgen]
|
||||
pub fn site_allowed_area(rules: &[f64]) -> Vec<f64> {
|
||||
encode(&read_rules(rules).map(|r| site_rules::allowed_area(&r)).unwrap_or_default())
|
||||
}
|
||||
|
||||
/// `[gültig, Parzelle, zulässig, Verstoss, HöheÜberschritten, …flat(zulässig), …flat(Verstösse)]`;
|
||||
/// ungültig → `[0]`. `footprint` = Teile der Gebäude-Grundfläche (`flat`), `max_top` NaN = keine.
|
||||
#[wasm_bindgen]
|
||||
pub fn site_check(rules: &[f64], footprint: &[f64], max_height: f64, max_top: f64) -> Vec<f64> {
|
||||
let (Some(r), Some(fp)) = (read_rules(rules), decode(footprint)) else { return vec![0.0] };
|
||||
let Some(c) = site_rules::check_site_rules(&r, &fp, max_height, max_top) else { return vec![0.0] };
|
||||
let mut out = vec![1.0, c.parcel_area, c.allowed_area, c.violation_area, if c.height_exceeded { 1.0 } else { 0.0 }];
|
||||
out.extend(encode(&c.allowed));
|
||||
out.extend(encode(&c.violations));
|
||||
out
|
||||
}
|
||||
@@ -0,0 +1,59 @@
|
||||
//! Bindungen von Sonnenstand und Schatten (`crate::sun`).
|
||||
|
||||
use crate::flat_read::pairs;
|
||||
use crate::flat::{decode, encode};
|
||||
use crate::flat_read::Reader;
|
||||
use crate::sun::{self, Prism, SunPosition};
|
||||
use wasm_bindgen::prelude::wasm_bindgen;
|
||||
|
||||
/// `[azimut, höhe]` in Grad.
|
||||
#[wasm_bindgen]
|
||||
pub fn sun_position(lat: f64, lon: f64, unix_ms: f64) -> Vec<f64> {
|
||||
let s = sun::sun_position(lat, lon, unix_ms);
|
||||
vec![s.azimuth, s.elevation]
|
||||
}
|
||||
|
||||
/// Grundriss als `[x0, y0, x1, y1, …]` → Schatten-Ring im selben Format.
|
||||
#[wasm_bindgen]
|
||||
pub fn sun_shadow_of_prism(footprint: &[f64], z_bottom: f64, z_top: f64, azimuth: f64, elevation: f64) -> Vec<f64> {
|
||||
let r = sun::shadow_of_prism(&pairs(footprint), z_bottom, z_top, SunPosition { azimuth, elevation });
|
||||
r.into_iter().flatten().collect()
|
||||
}
|
||||
|
||||
fn read_prisms(buf: &[f64]) -> Option<Vec<Prism>> {
|
||||
let mut r = Reader::new(buf);
|
||||
let n = r.count()?;
|
||||
let mut out = Vec::with_capacity(n.min(1 << 16));
|
||||
for _ in 0..n {
|
||||
let (z_bottom, z_top) = (r.num()?, r.num()?);
|
||||
out.push(Prism { footprint: r.ring()?, z_bottom, z_top });
|
||||
}
|
||||
Some(out)
|
||||
}
|
||||
|
||||
fn read_clouds(buf: &[f64]) -> Option<Vec<Vec<[f64; 3]>>> {
|
||||
let mut r = Reader::new(buf);
|
||||
let n = r.count()?;
|
||||
let mut out = Vec::with_capacity(n.min(1 << 16));
|
||||
for _ in 0..n {
|
||||
let k = r.count()?;
|
||||
out.push(r.points3(k)?);
|
||||
}
|
||||
Some(out)
|
||||
}
|
||||
|
||||
/// Prismen `[n, (zUnten, zOben, nPkt, x, y, …)…]` und Punktwolken `[n, (nPkt, x, y, z, …)…]`
|
||||
/// → vereinigter Schatten (Polygone, `flat`-Kodierung).
|
||||
#[wasm_bindgen]
|
||||
pub fn sun_shadow_union(prisms: &[f64], clouds: &[f64], azimuth: f64, elevation: f64) -> Vec<f64> {
|
||||
let (Some(p), Some(c)) = (read_prisms(prisms), read_clouds(clouds)) else { return encode(&[]) };
|
||||
encode(&sun::shadow_union(&p, &c, SunPosition { azimuth, elevation }))
|
||||
}
|
||||
|
||||
/// Ein Polygon (`flat`, erstes Polygon zählt) → lochfreie Teile (`flat`, je ein Ring).
|
||||
#[wasm_bindgen]
|
||||
pub fn sun_without_holes(poly: &[f64]) -> Vec<f64> {
|
||||
let Some(first) = decode(poly).and_then(|p| p.into_iter().next()) else { return encode(&[]) };
|
||||
let parts: Vec<_> = sun::without_holes(&first).into_iter().map(|r| vec![r]).collect();
|
||||
encode(&parts)
|
||||
}
|
||||
Reference in new issue
Block a user