[K4] Zeichenbefehle im Kern: Elemente, Vorschauen, Gruppen-Zuordnung

Alle Erzeuge-Befehle bauen ihre Elemente im Kern: cmd_create.rs (Wand, Decke,
Raum, Treppe, Öffnung, Dach, Stütze, Extrusion), cmd_draw.rs (2D-Formen,
Texte, Bemassung, autodim), cmd_solid.rs (solid, solidbool, voidbox, terrain,
Deckenöffnung, Dachhof, Schnittlinie). Vorschauen über doc_create_preview(_again)
ohne JSON je Mausschritt, Abfragen über doc_create_query; Gruppen-Zuordnung als
`group` im Request ersetzt activeGroupOps. TS hält nur die Zustandsautomaten
(commands/createCore.ts). Ersetzte TS-Geometrie und alte Werkzeug-Commits in
tools/tools.ts gelöscht. Gleichheit alt/neu mit zeitweiligen Zufallstests
geprüft (s. TODO.md). Die drei Gruppen hängen über den gemeinsamen Dispatcher
zusammen und sind deshalb ein Commit.
This commit is contained in:
Claude committed 2026-10-29 15:21:04 +00:00
1 parent 23993e9607
commit 61263efe13
92 files changed
+4169 -4744

No files matched your search

-41
View File
@@ -1,41 +0,0 @@
//! 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
}
-21
View File
@@ -32,24 +32,3 @@ pub fn bulge_from_sagitta_point(ax: f64, ay: f64, bx: f64, by: f64, px: f64, py:
pub fn bulge_point_at(ax: f64, ay: f64, bx: f64, by: f64, bulge: f64, t: f64) -> Vec<f64> {
b::point_at(ax, ay, bx, by, bulge, t)
}
#[wasm_bindgen]
pub fn bulge_through_point(ax: f64, ay: f64, tx: f64, ty: f64, bx: f64, by: f64) -> f64 {
b::through_point(ax, ay, tx, ty, bx, by)
}
/// `[cx, cy, r, a0, a1]` (CCW) oder leer.
#[wasm_bindgen]
pub fn arc_through_points(ax: f64, ay: f64, tx: f64, ty: f64, bx: f64, by: f64) -> Vec<f64> {
b::arc_through_points(ax, ay, tx, ty, bx, by)
}
#[wasm_bindgen]
pub fn arc_from_start_end_radius(ax: f64, ay: f64, bx: f64, by: f64, r: f64, nx: f64, ny: f64) -> Vec<f64> {
b::arc_from_start_end_radius(ax, ay, bx, by, r, nx, ny)
}
#[wasm_bindgen]
pub fn arc_from_start_end_direction(ax: f64, ay: f64, bx: f64, by: f64, dx: f64, dy: f64) -> Vec<f64> {
b::arc_from_start_end_direction(ax, ay, bx, by, dx, dy)
}
+72
View File
@@ -0,0 +1,72 @@
//! Bindungen der Zeichenbefehle (`crate::cmd_create`): Vorschau je Mausschritt (Optionen als JSON, die
//! Punkte flach) und Treffer-Abfragen zwischen den Schritten. Der Commit läuft über `doc_cmd_commit`.
//!
//! Je Mausschritt ändern sich meist nur die Punkte: die zuletzt gelesenen Optionen bleiben hier liegen,
//! `doc_create_preview_again` rechnet mit ihnen (kein JSON hin und kein Parsen je Mausschritt — die
//! Wand-Vorschau ist sonst langsamer als die frühere TS-Fassung).
use super::document::with_doc;
use crate::cmd_create::Req;
use serde_json::Value;
use std::cell::RefCell;
use wasm_bindgen::prelude::wasm_bindgen;
thread_local! {
static LAST_REQ: RefCell<Option<Req>> = const { RefCell::new(None) };
}
fn run(h: u32, req: &Req, pts: &[f64]) -> Vec<f64> {
if pts.len() % 2 != 0 {
return Vec::new();
}
with_doc(h, |d| crate::cmd_create::preview_req(d.root(), req, pts).flat()).unwrap_or_default()
}
/// Vorschau eines Zeichenbefehls auf dem Dokument `h`: `[ok, nInfo, info…, Formen…]` (Formen wie
/// `doc_cmd_preview`); leer bei Fehler. Merkt sich die Optionen für [`doc_create_preview_again`].
#[wasm_bindgen]
pub fn doc_create_preview(h: u32, req_json: &str, pts: &[f64]) -> Vec<f64> {
let req = serde_json::from_str::<Value>(req_json).ok().filter(Value::is_object).map(Req::new);
let out = req.as_ref().map_or_else(Vec::new, |r| run(h, r, pts));
LAST_REQ.with(|l| *l.borrow_mut() = req);
out
}
/// Wie [`doc_create_preview`] mit den zuletzt übergebenen Optionen (nur neue Punkte).
#[wasm_bindgen]
pub fn doc_create_preview_again(h: u32, pts: &[f64]) -> Vec<f64> {
LAST_REQ.with(|l| l.borrow().as_ref().map_or_else(Vec::new, |r| run(h, r, pts)))
}
/// Treffer-Abfrage eines Zeichenbefehls (`crate::cmd_create::query`), Antwort-JSON (Zahlen mit
/// Nicht-endlich-Marken); Fehler als Text mit `\u{1}` vorn.
#[wasm_bindgen]
pub fn doc_create_query(h: u32, req_json: &str) -> String {
let v: Value = match serde_json::from_str(req_json) {
Ok(v) => v,
Err(e) => return format!("\u{1}Zeichen-Abfrage: {e}"),
};
match with_doc(h, |d| crate::cmd_create::query(d.root(), &v)) {
Some(Some(Ok(v))) => v.to_string(),
Some(Some(Err(e))) => format!("\u{1}{e}"),
Some(None) => "\u{1}Unbekannte Zeichen-Abfrage".to_string(),
None => "\u{1}Dokument nicht offen".to_string(),
}
}
/// B-Rep-Beschreibung eines Körpers (`crate::cmd_solid::extruded_solid_spec`) als JSON (Zahlen mit
/// Nicht-endlich-Marken); leer = keine Beschreibung oder kein Körper.
#[wasm_bindgen]
pub fn extruded_solid_spec_json(solid_json: &str, floor_z: f64) -> String {
serde_json::from_str::<Value>(solid_json)
.ok()
.and_then(|s| crate::cmd_solid::extruded_solid_spec(&s, floor_z))
.map_or_else(String::new, |v| v.to_string())
}
/// Gelände-TIN aus Höhenlinien (`crate::cmd_solid::terrain_from_contours`) als JSON; `id` des Netzes.
#[wasm_bindgen]
pub fn terrain_from_contours_json(contours_json: &str, id: &str) -> String {
let c: Value = serde_json::from_str(contours_json).unwrap_or(Value::Null);
crate::cmd_solid::terrain_from_contours(c.as_array().map(Vec::as_slice).unwrap_or(&[]), id).to_string()
}
-6
View File
@@ -2,12 +2,6 @@
use wasm_bindgen::prelude::wasm_bindgen;
/// Punkte einer (gedrehten) Ellipse, `n` gleichverteilte Parameterschritte.
#[wasm_bindgen]
pub fn curves_ellipse_flat(cx: f64, cy: f64, rx: f64, ry: f64, rotation: f64, n: f64) -> Vec<f64> {
crate::curves::ellipse(cx, cy, rx, ry, rotation, n)
}
/// Kubische Bezier-Kette (Anker·Griff·Griff·Anker …); unter 4 Punkten unverändert.
#[wasm_bindgen]
pub fn curves_bezier_chain_flat(pts: &[f64], segs_per_curve: f64) -> Vec<f64> {
+1 -57
View File
@@ -8,7 +8,7 @@
//! Kaputte Eingaben (ungerade Längen, falsche Zählungen, ungültige Indizes) ergeben ein
//! leeres Ergebnis statt eines Panics.
use kernel2d::{self as k, TangentTarget, Vec2};
use kernel2d::{self as k, Vec2};
use wasm_bindgen::prelude::wasm_bindgen;
// --- Lesen -------------------------------------------------------------------
@@ -61,16 +61,6 @@ fn pt_lists(buf: &[f64]) -> Option<Vec<Vec<Vec2>>> {
(0..n).map(|_| r.count().and_then(|m| r.pts(m))).collect()
}
fn tangent_target(buf: &[f64]) -> Option<TangentTarget> {
match *buf {
[kind, ax, ay, bx, by] if kind == 0.0 => {
Some(TangentTarget::Line { a: Vec2::new(ax, ay), b: Vec2::new(bx, by) })
}
[kind, cx, cy, r, _] if kind == 1.0 => Some(TangentTarget::Circle { center: Vec2::new(cx, cy), r }),
_ => None,
}
}
// --- Schreiben ---------------------------------------------------------------
fn push_pts(out: &mut Vec<f64>, pts: &[Vec2]) {
@@ -107,40 +97,13 @@ const EMPTY_LIST: [f64; 1] = [0.0];
// --- Punkt/Strecke, Fläche, Kreise ---------------------------------------------
#[wasm_bindgen]
pub fn k2_point_segment_distance(px: f64, py: f64, ax: f64, ay: f64, bx: f64, by: f64) -> f64 {
k::point_segment_distance(Vec2::new(px, py), Vec2::new(ax, ay), Vec2::new(bx, by))
}
#[wasm_bindgen]
pub fn k2_signed_area(p: &[f64]) -> f64 {
pts(p).map_or(0.0, |p| k::signed_area(&p))
}
#[wasm_bindgen]
pub fn k2_is_ccw(p: &[f64]) -> bool {
pts(p).is_some_and(|p| k::is_ccw(&p))
}
#[wasm_bindgen]
pub fn k2_circle_circle_intersect(c1x: f64, c1y: f64, r1: f64, c2x: f64, c2y: f64, r2: f64) -> Vec<f64> {
enc_pts(&k::circle_circle_intersect(Vec2::new(c1x, c1y), r1, Vec2::new(c2x, c2y), r2))
}
#[wasm_bindgen]
pub fn k2_tangent_circle_centers(t1: &[f64], t2: &[f64], r: f64) -> Vec<f64> {
let (Some(t1), Some(t2)) = (tangent_target(t1), tangent_target(t2)) else { return Vec::new() };
enc_pts(&k::tangent_circle_centers(t1, t2, r))
}
// --- Offset ------------------------------------------------------------------
#[wasm_bindgen]
pub fn k2_offset_segment(ax: f64, ay: f64, bx: f64, by: f64, d: f64) -> Vec<f64> {
let (a, b) = k::offset_segment(Vec2::new(ax, ay), Vec2::new(bx, by), d);
vec![a.x, a.y, b.x, b.y]
}
// --- Trim / Extend -----------------------------------------------------------
@@ -151,25 +114,6 @@ pub fn k2_offset_segment(ax: f64, ay: f64, bx: f64, by: f64, d: f64) -> Vec<f64>
// --- Ecken -------------------------------------------------------------------
/// `[cx, cy, radius, tAx, tAy, tBx, tBy, startAngle, endAngle]` oder leer.
#[wasm_bindgen]
pub fn k2_fillet_corner(cx: f64, cy: f64, p1x: f64, p1y: f64, p2x: f64, p2y: f64, r: f64) -> Vec<f64> {
match k::fillet_corner(Vec2::new(cx, cy), Vec2::new(p1x, p1y), Vec2::new(p2x, p2y), r) {
Some(f) => vec![
f.center.x,
f.center.y,
f.radius,
f.tangent_a.x,
f.tangent_a.y,
f.tangent_b.x,
f.tangent_b.y,
f.start_angle,
f.end_angle,
],
None => Vec::new(),
}
}
// --- Split / Join / Segment löschen / Bruch ----------------------------------------
+1 -1
View File
@@ -8,7 +8,6 @@ mod polygon;
mod roof;
mod sun;
mod site_rules;
mod auto_dimensions;
mod kennzahlen;
mod bulge;
mod stair;
@@ -40,6 +39,7 @@ mod text_layout;
mod grips;
mod project_refs;
mod commands;
mod cmd_create;
use wasm_bindgen::prelude::wasm_bindgen;
-12
View File
@@ -8,15 +8,3 @@ use wasm_bindgen::prelude::wasm_bindgen;
pub fn rooms_detect(walls: &[f64], gap_tol: f64, min_area: f64, offset_to_inner: bool) -> Vec<f64> {
rb::detect(walls, gap_tol, min_area, offset_to_inner)
}
/// Umriss der Zelle um den Punkt `[nPkt, x, y, …]`, leer = keine.
#[wasm_bindgen]
pub fn room_from_point(px: f64, py: f64, walls: &[f64], gap_tol: f64, offset_to_inner: bool) -> Vec<f64> {
rb::from_point(px, py, walls, gap_tol, offset_to_inner)
}
/// Wie `room_from_point`, aber auf fertigen Wand-Innenflächen (ohne Offset).
#[wasm_bindgen]
pub fn room_from_point_faces(px: f64, py: f64, faces: &[f64], gap_tol: f64) -> Vec<f64> {
rb::from_point_faces(px, py, faces, gap_tol)
}
-18
View File
@@ -3,26 +3,8 @@
use crate::stair as s;
use wasm_bindgen::prelude::wasm_bindgen;
/// Parameter (16 Zahlen) + Gesamt-Steighöhe → flache Treppengeometrie; Unsinn → leer.
#[wasm_bindgen]
pub fn stair_geometry_flat(params: &[f64], total_rise: f64) -> Vec<f64> {
s::geometry(params, total_rise)
}
/// Plan-Aussenlinie: `[0, n, x, y …]` (Polygon) oder `[1, …]` (Wendel).
#[wasm_bindgen]
pub fn stair_outline_flat(params: &[f64]) -> Vec<f64> {
s::outline(params)
}
/// Schnittaufteilung aus flacher Geometrie und Schnitthöhe über der Treppen-UK.
#[wasm_bindgen]
pub fn stair_cut_flat(geometry: &[f64], cut_rise: f64) -> Vec<f64> {
s::cut(geometry, cut_rise)
}
/// Vorgabe-Stufenzahl aus Steighöhe und Lauflänge.
#[wasm_bindgen]
pub fn stair_default_step_count(total_rise: f64, run_length: f64) -> u32 {
s::default_step_count(total_rise, run_length)
}