[144] Merge: Öffnungen – Masse ziehen mit, Bogenwände, keine Überlappung, Dachfenster verschieben
This commit is contained in:
28 files changed
+846
-149
No files matched your search
@@ -2837,7 +2837,7 @@ Format · [90] Versionsvergleich · [91] Assistent · [92] Speckle.
|
||||
vorher 16/18 Frames hinterher, nachher 0. Nur im Linux-Container (Chromium) geprüft, NICHT in der Tauri-App/Metal:
|
||||
ob Metal-Present und Webview-Commit dort im selben vsync landen, muss der Mac zeigen. Offen, falls es dort noch
|
||||
nachläuft: Raumstempel nativ zeichnen (vtext kann bisher nur einzeilig/linksbündig, eine Schrift, kein Fett).
|
||||
- ◐ **[144] Öffnungen verschieben.** (6.11., Maintainer: „Türen lassen sich nicht nach Mass oder mit Verschieben
|
||||
- ✅ **[144] Öffnungen verschieben.** (6.11., Maintainer: „Türen lassen sich nicht nach Mass oder mit Verschieben
|
||||
bewegen.") Befund (Browser-Build, Musterhaus): Öffnungen waren keine Transformations-Elemente — Verschieben/m mit
|
||||
nur einer Tür gewählt meldete „Erst Objekte wählen"; Objekt-Info X/Y (Bezugspunkt) tat nichts (`singleTransformSel`
|
||||
ohne Öffnung); Griff-Zug: Tab öffnete kein Längenfeld (Einzelgriff ohne Nachbar → kein Anker), die getippte Zahl
|
||||
@@ -2851,9 +2851,31 @@ Format · [90] Versionsvergleich · [91] Assistent · [92] Speckle.
|
||||
Wand ab Greifpunkt. Tests: Rust `oeffnung_gleitet_entlang_der_wand`, `wand_mit_typ_volumen_und_fuge` (wallLength);
|
||||
vitest `transform.test.ts` (Engine, getippte Distanz/`@x,y`), `transform.openings.test.ts` (alle Öffnungen
|
||||
Musterhaus komplex); e2e `openingMove.spec.ts` (Befehl getippt + Klick, Undo, Objekt-Info, Griff mit Länge).
|
||||
Offen: Bogenwände (Öffnung bleibt stehen), keine Überlappungsprüfung zwischen Öffnungen, Dach-/Deckenöffnungen
|
||||
allein nicht über Verschieben (nur Griffe), Bemassungs-Bezüge auf die gleitende Öffnung werden nicht nachgeführt;
|
||||
nur Linux/Chromium geprüft, nicht in der Tauri-App. · S
|
||||
**Nachtrag 6.11.:** Gemeinsamer Kern-Weg `opening_slide.rs` für Befehl, Griff-Zug (Griff-Anfrage `openingSlide`)
|
||||
und Objekt-Info-Position (`openingPosition`; Store `slideOpening`, ersetzt `grip_opening_slide`/`openingSlidePosition`):
|
||||
(1) Bemassung: Bezüge auf Leibungen/Mitte (auch Autodim-Ketten [81]) folgen über das Nachführen im Dokument
|
||||
(`dim_assoc::sync_ops`) in derselben Undo-Stufe; `opening_point` rechnet in Bogenwänden jetzt auf dem Bogen statt
|
||||
auf der Sehne. (2) Bogenwände [T2]: `position` = Bogenlänge; Verschieben nimmt den Lotfuss des Ziels auf dem Bogen,
|
||||
Griff-Zug ebenso, Griffpunkt auf dem Bogen (`grip_opening_point` mit Bulge), geklemmt an den Bogenenden;
|
||||
Wandwechsel auch in/aus Bogenwände; Vorschau als Ringsektor; Objekt-Info `wallLength` = Bogenlänge.
|
||||
(3) Überlappung: gleitend hält eine Öffnung `MIN_WEB` = 5 cm vor der Nachbaröffnung derselben Wand an
|
||||
(Hinweis „Öffnung hält vor der Nachbaröffnung an"), mitbewegte Öffnungen zählen nicht, schon überlappender
|
||||
Bestand bleibt unverändert und blockiert nicht; Wandwechsel, Kopie und neu gesetzte Öffnungen (`cmd_create`)
|
||||
rücken an die nächste freie Stelle, ohne Platz keine Änderung (Hinweis „kein Platz" beim Wandwechsel). Hinweise
|
||||
aus Befehlen: `commands::result` → `doc_cmd_commit` → `commitCmd.notice`; im Store höchstens alle 2 s derselbe.
|
||||
(4) Dach-/Deckenöffnungen allein: Verschieben/Kopie/Reihe verschieben `hostPoint`, im Umriss des Wirts gehalten
|
||||
(`clamp_inside`, wie der Griff), Vorschau-Rechteck. Tests: Rust `opening_slide` (Anschlag, Bestand, freie Stelle,
|
||||
Bogenlänge), `oeffnung_haelt_vor_der_nachbaroeffnung`, `bemassung_folgt_der_gleitenden_oeffnung` (Befehl, Griff,
|
||||
Objekt-Info, Bogen, Undo), `dachoeffnung_allein_verschieben`, Bogen-Fall in `oeffnung_gleitet_entlang_der_wand`,
|
||||
`oeffnung_pick_und_vorschau` (Setzen), `selection_info` (Bogenlänge); vitest `transform.openings.test.ts` (Store:
|
||||
Bemassung folgt, Erker f5/f6, Dachöffnung), `transform.test.ts` (Anschlag an O1); e2e `openingMove.spec.ts`
|
||||
(Musterhaus: Anschlag an O1 mit Hinweis; Musterhaus komplex: Kette `mass-fenster-eg` folgt Befehl und Objekt-Info,
|
||||
Erker: Abstand ab Wandende aus Bogenlänge, Anschlag f5 vor f6, Verschieben auf dem Bogen). Klick-Zug im alten
|
||||
e2e auf 0.5 m (0.25 m fing seit [147] der Fang am Basispunkt).
|
||||
Offen: Öffnung im Schnitt-Blatt ziehen rechnet weiter auf der Sehne (Bogenwand) — der Commit klemmt aber über den
|
||||
Kern; Tab-Länge beim Griff an Bogenwänden entlang der Sehne über der Öffnung; Vorschau beim Setzen zeigt den
|
||||
Cursor-Ort, nicht die verrückte Lage; `clampInside` steht noch in TS (Griff) und Rust (Befehl); nur Linux/Chromium
|
||||
geprüft, nicht in der Tauri-App. · S
|
||||
- ✅ **[147] Plan öffnet zu stark gezoomt.** (6.11., zwei e2e-Läufe: nach „Neues Projekt" und beim Öffnen von Musterhaus
|
||||
stand die Statusleiste auf „1:9 · 1111 %".) Ursachen: (1) leeres Projekt liefert den Platzhalter-Umriss 0,0–1,1; die
|
||||
eingepasste Ansicht war damit ~1 m breit. (2) Die Ansicht wird nur bei Geschoss-Wechsel (`resetKey = level.id`) neu
|
||||
|
||||
+66
-14
@@ -1,9 +1,9 @@
|
||||
// [144] Türen/Fenster verschieben: allein gewählt gleitet eine Öffnung beim Verschieben (Befehl,
|
||||
// getippte Distanz) entlang ihrer Wand; Objekt-Info setzt die Lage exakt (ab Wandanfang/-ende);
|
||||
// Griff-Zug mit getippter Länge (Tab) schiebt um genau diese Strecke entlang der Wand.
|
||||
// Musterhaus: Tür D1 in W1 (0,0)–(5,0), position 0.8, Breite 0.9.
|
||||
// Musterhaus: Tür D1 in W1 (0,0)–(5,0), position 0.8, Breite 0.9; Fenster O1 in W1 bei 3.0–4.0.
|
||||
import type { Page } from "@playwright/test";
|
||||
import { blurFocus, commandInput, expect, openSample, openTab, test, typeCommand } from "./app";
|
||||
import { blurFocus, commandInput, discardIfAsked, expect, fileMenu, openSample, openTab, test, typeCommand } from "./app";
|
||||
import type {} from "../src/state/testHooks";
|
||||
|
||||
const prompt = (page: Page) => page.locator(".cmdline-prompt");
|
||||
@@ -61,22 +61,24 @@ test("Tür verschieben: Befehl mit getippter Distanz, Rückgängig, Objekt-Info"
|
||||
await page.keyboard.press("ControlOrMeta+z");
|
||||
await expect.poll(() => pos(page)).toBe(0.8);
|
||||
|
||||
// Taste „m" + Zielpunkt per Klick (0.25 m zurück, leicht quer): die Tür folgt entlang der Wand.
|
||||
// Taste „m" + Zielpunkt per Klick (0.5 m zurück, leicht quer): die Tür folgt entlang der Wand.
|
||||
// (0.25 m fing beim eingepassten Zoom der Fang am Basispunkt.)
|
||||
await selectDoor(page);
|
||||
await page.keyboard.press("m");
|
||||
await expect(prompt(page)).toHaveText("Basispunkt klicken");
|
||||
const a = await screenOf(page, 1.25, 0);
|
||||
const b = await screenOf(page, 1.0, 0.05);
|
||||
const b = await screenOf(page, 0.75, 0.05);
|
||||
await page.mouse.move(a.x, a.y);
|
||||
await page.mouse.click(a.x, a.y);
|
||||
await page.mouse.move(b.x, b.y, { steps: 3 });
|
||||
await page.mouse.click(b.x, b.y);
|
||||
await expect(prompt(page)).toHaveText("Befehl:");
|
||||
await expect.poll(async () => Math.abs((await pos(page)) - 0.55) < 0.05).toBe(true);
|
||||
await expect.poll(async () => Math.abs((await pos(page)) - 0.3) < 0.05).toBe(true);
|
||||
await page.keyboard.press("ControlOrMeta+z");
|
||||
await expect.poll(() => pos(page)).toBe(0.8);
|
||||
|
||||
// Objekt-Info: Lage ab Wandanfang und ab Wandende exakt setzen (geklemmt in der Wand).
|
||||
// Objekt-Info: Lage ab Wandanfang und ab Wandende exakt setzen (geklemmt in der Wand und 5 cm vor
|
||||
// dem Fenster O1: 3.0 − 0.05 − 0.9 = 2.05, mit Hinweis).
|
||||
await selectDoor(page);
|
||||
await openTab(page, "Objekt-Info");
|
||||
const field = (label: string) =>
|
||||
@@ -84,18 +86,16 @@ test("Tür verschieben: Befehl mit getippter Distanz, Rückgängig, Objekt-Info"
|
||||
await expect(field("Abstand ab Wandende")).toHaveValue("3.300");
|
||||
await field("Abstand ab Wandende").fill("1");
|
||||
await field("Abstand ab Wandende").press("Enter");
|
||||
await expect.poll(() => pos(page)).toBe(3.1);
|
||||
await expect.poll(() => pos(page)).toBe(2.05);
|
||||
await expect.poll(async () => (await page.evaluate(() => window.__dossierTest!.notices())).some((n) => n.includes("Nachbaröffnung"))).toBe(true);
|
||||
await field("Position (ab Wandanfang)").fill("2");
|
||||
await field("Position (ab Wandanfang)").press("Enter");
|
||||
await expect.poll(() => pos(page)).toBe(2);
|
||||
await field("Position (ab Wandanfang)").fill("99");
|
||||
await field("Position (ab Wandanfang)").press("Enter");
|
||||
await expect.poll(() => pos(page)).toBe(4.1);
|
||||
// Bezugspunkt X (Mitte der Tür, 4.55) um −1 m: Verschieben entlang der Wand.
|
||||
await expect(field("X")).toHaveValue("4.550");
|
||||
await field("X").fill("3.55");
|
||||
// Bezugspunkt X (Mitte der Tür, 2.45) um −1 m: Verschieben entlang der Wand.
|
||||
await expect(field("X")).toHaveValue("2.450");
|
||||
await field("X").fill("1.45");
|
||||
await field("X").press("Enter");
|
||||
await expect.poll(() => pos(page)).toBe(3.1);
|
||||
await expect.poll(() => pos(page)).toBe(1);
|
||||
await expect(commandInput(page)).toBeVisible();
|
||||
});
|
||||
|
||||
@@ -115,3 +115,55 @@ test("Tür: Griff ziehen mit getippter Länge entlang der Wand", async ({ page }
|
||||
await commandInput(page).press("Enter");
|
||||
await expect.poll(() => pos(page)).toBe(1.3);
|
||||
});
|
||||
|
||||
// [144] Musterhaus komplex: Bemassung „mass-fenster-eg" hängt an den Leibungen von eg-f1 (Wand eg-aw-s,
|
||||
// Lage 1.6, Breite 1.8) und folgt; Erker-Bogenwand eg-aw-erker (Halbkreis r = 2, Länge 2π) mit f5 bei 1.2 und
|
||||
// f6 bei 3.6 (je 1 m): Abstand ab Wandende = Bogenlänge, Anschlag an der Nachbaröffnung mit Hinweis.
|
||||
test("Musterhaus komplex: Bemassung folgt, Bogenwand, Nachbaröffnung", async ({ page }) => {
|
||||
test.setTimeout(120_000);
|
||||
await open(page);
|
||||
await fileMenu(page, /Musterhaus \(komplex\)/);
|
||||
await discardIfAsked(page);
|
||||
await expect(page.locator(".project-name")).toHaveText("Musterhaus komplex", { timeout: 30_000 });
|
||||
const posOf = async (id: string) =>
|
||||
Math.round((await page.evaluate(() => window.__dossierTest!.openings())).find((o) => o.id === id)!.position * 1000) / 1000;
|
||||
const dimX = async () => Math.round((await page.evaluate(() => window.__dossierTest!.dimPts("mass-fenster-eg")))[0].x * 1000) / 1000;
|
||||
const x0 = await dimX();
|
||||
|
||||
// Befehl: eg-f1 um 0.5 m entlang der Wand → erste Leibung der Kette ebenso.
|
||||
await blurFocus(page);
|
||||
await page.evaluate(() => window.__dossierTest!.select({ openings: ["eg-f1"] }));
|
||||
await page.getByRole("button", { name: "Verschieben", exact: true }).click();
|
||||
await typeCommand(page, "0,0");
|
||||
await typeCommand(page, "@0.5,0");
|
||||
await expect(prompt(page)).toHaveText("Befehl:");
|
||||
await expect.poll(() => posOf("eg-f1")).toBe(2.1);
|
||||
await expect.poll(dimX).toBe(Math.round((x0 + 0.5) * 1000) / 1000);
|
||||
// Objekt-Info-Position: Kette folgt ebenfalls.
|
||||
await openTab(page, "Objekt-Info");
|
||||
const field = (label: string) =>
|
||||
page.locator("label.objinfo-field").filter({ has: page.locator(".objinfo-flabel", { hasText: label }) }).locator("input");
|
||||
await field("Position (ab Wandanfang)").fill("1");
|
||||
await field("Position (ab Wandanfang)").press("Enter");
|
||||
await expect.poll(() => posOf("eg-f1")).toBe(1);
|
||||
await expect.poll(dimX).toBe(Math.round((x0 - 0.6) * 1000) / 1000);
|
||||
|
||||
// Bogenwand: Abstand ab Wandende aus der Bogenlänge, Anschlag vor f6 (3.6 − 0.05 − 1 = 2.55) mit Hinweis.
|
||||
await blurFocus(page);
|
||||
await page.evaluate(() => window.__dossierTest!.select({ openings: ["eg-f5"] }));
|
||||
await expect(field("Abstand ab Wandende")).toHaveValue((2 * Math.PI - 2.2).toFixed(3));
|
||||
await field("Position (ab Wandanfang)").fill("3");
|
||||
await field("Position (ab Wandanfang)").press("Enter");
|
||||
await expect.poll(() => posOf("eg-f5")).toBe(2.55);
|
||||
await expect.poll(async () => (await page.evaluate(() => window.__dossierTest!.notices())).some((n) => n.includes("Nachbaröffnung"))).toBe(true);
|
||||
// Verschieben-Befehl an einer Bogenwand: f6 (Mitte bei Bogenlänge 4.1, Winkel ≈ 27.5°) um 0.5 m entlang
|
||||
// der Tangente → Lotfuss auf dem Bogen, Lage ≈ 4.1.
|
||||
await blurFocus(page);
|
||||
await page.evaluate(() => window.__dossierTest!.select({ openings: ["eg-f6"] }));
|
||||
await page.getByRole("button", { name: "Verschieben", exact: true }).click();
|
||||
await typeCommand(page, "17,5");
|
||||
await typeCommand(page, "@-0.231,0.443");
|
||||
await expect(prompt(page)).toHaveText("Befehl:");
|
||||
await expect.poll(async () => Math.abs((await posOf("eg-f6")) - 4.1) < 0.03).toBe(true);
|
||||
expect((await page.evaluate(() => window.__dossierTest!.openings())).find((o) => o.id === "eg-f6")!.hostWallId).toBe("eg-aw-erker");
|
||||
});
|
||||
@@ -721,7 +721,9 @@ fn pick_wall<'a>(root: &'a Map<String, Value>, level: &str, p: V) -> Option<(&'a
|
||||
}
|
||||
|
||||
/// Öffnung in eine Wand (`start`/`end` der Host-Wand beim Picken, `pos` = Abstand vom Wandanfang).
|
||||
fn opening_ops(p: &Project, v: &Value, ctx: &Ctx, ids: &mut IdGen) -> Vec<Op> {
|
||||
/// [144] Überlappt sie eine Öffnung derselben Wand, rückt sie an die nächste freie Stelle (Steg 5 cm,
|
||||
/// `opening_slide::place`); ist keine frei, entsteht keine.
|
||||
fn opening_ops(root: &Map<String, Value>, p: &Project, v: &Value, ctx: &Ctx, ids: &mut IdGen) -> Vec<Op> {
|
||||
let (st, en) = (p_of(v, "start"), p_of(v, "end"));
|
||||
let len = match arc_of(st, en, opt_n(v, "bulge")) {
|
||||
Some(a) => a.length(),
|
||||
@@ -729,6 +731,8 @@ fn opening_ops(p: &Project, v: &Value, ctx: &Ctx, ids: &mut IdGen) -> Vec<Op> {
|
||||
};
|
||||
let width = jsnum::max(0.1, jsnum::min(n_of(v, "width"), len));
|
||||
let position = jsnum::max(0.0, jsnum::min(n_of(v, "pos"), jsnum::max(0.0, len - width)));
|
||||
let Some(placed) = crate::opening_slide::place(root, s_of(v, "wall"), len, width, None, position, &|_| false) else { return vec![] };
|
||||
let position = if placed.clamped { placed.position } else { position };
|
||||
let door = s_of(v, "kind") == "door";
|
||||
// Erster Typ der Bibliothek (leere id = keiner, JS-Wahrheitswert).
|
||||
let first = if door { p.door_types.as_ref().and_then(|l| l.first()).map(|t| &t.id) } else { p.window_types.as_ref().and_then(|l| l.first()).map(|t| &t.id) };
|
||||
@@ -982,7 +986,7 @@ pub fn ops(root: &Map<String, Value>, p: &Project, v: &Value) -> Option<Vec<Op>>
|
||||
"room" => room_ops(p, v, &ctx, ids),
|
||||
"wand" => wand_ops(p, v, &ctx, ids),
|
||||
"stair" => stair_ops(p, v, &ctx, ids),
|
||||
"opening" => opening_ops(p, v, &ctx, ids),
|
||||
"opening" => opening_ops(root, p, v, &ctx, ids),
|
||||
"roof" => roof_ops(p, v, &ctx, ids),
|
||||
"column" => column_ops(v, &ctx, ids),
|
||||
"extrude" => extrude_ops(root, v, &ctx, ids),
|
||||
@@ -1269,6 +1273,17 @@ mod tests {
|
||||
let op = &items(&o, 0)[0];
|
||||
assert_eq!(op["position"], 4.8);
|
||||
assert_eq!(op["typeId"], "FT");
|
||||
// [144] Neben eine bestehende Öffnung (2–3) gesetzt: rückt an die nächste freie Stelle; ohne Platz keine.
|
||||
let mut r2 = r.clone();
|
||||
r2.insert("openings".into(), json!([{"id": "a", "hostWallId": "w", "position": 2, "width": 1}]));
|
||||
let place = |pos: f64, width: f64| {
|
||||
let o = ops(&r2, &crate::model::lenient::typed_for_test(&r2), &req(json!({"cmd": "opening", "wall": "w", "start": [0, 0], "end": [6, 0], "kind": "window", "pos": pos, "width": width, "height": 1.2, "sill": 0.9}))).unwrap();
|
||||
o.first().map(|_| items(&o, 0)[0]["position"].as_f64().unwrap())
|
||||
};
|
||||
assert_eq!(place(2.6, 1.0), Some(3.05));
|
||||
assert_eq!(place(1.5, 1.0), Some(0.95));
|
||||
assert_eq!(place(4.0, 1.0), Some(4.0));
|
||||
assert_eq!(place(0.0, 3.0), None);
|
||||
let p = preview(&r, &crate::model::lenient::typed_for_test(&r), &json!({"cmd": "opening", "start": [0, 0], "end": [6, 0], "kind": "window", "width": 1.2, "pos": null}), &[2.0, 1.0]);
|
||||
assert_eq!(p.info[0], 2.0);
|
||||
assert_eq!(p.shapes.count, 2);
|
||||
|
||||
@@ -344,59 +344,87 @@ fn free_openings<'a>(root: &'a Map<String, Value>, sel: &Sel, op: &str, walls: &
|
||||
}
|
||||
|
||||
/// Wandöffnung um `d` verschieben ([144]): die Öffnungsmitte geht nach `Mitte + d`. Liegt das Ziel in
|
||||
/// einer anderen geraden Wand desselben Geschosses (innerhalb der halben Dicke + 5 cm) und nicht mehr in
|
||||
/// der eigenen, wechselt die Öffnung dorthin; sonst gleitet sie um die auf die Wandachse projizierte
|
||||
/// Strecke. `position` auf [0, Wandlänge − Breite] geklemmt. `None`: Wirt fehlt, Bogenwand oder die
|
||||
/// Öffnung passt nicht in die Wand.
|
||||
fn slide_opening(root: &Map<String, Value>, p: &Project, o: &Value, d: (f64, f64)) -> Option<Value> {
|
||||
/// einer anderen Wand desselben Geschosses (innerhalb der halben Dicke + 5 cm) und nicht mehr in der
|
||||
/// eigenen, wechselt die Öffnung dorthin; sonst gleitet sie entlang der Achse (gerade Wand: um die
|
||||
/// projizierte Strecke; Bogenwand [T2]: zum Lotfuss auf dem Bogen, `position` = Bogenlänge). Geklemmt auf
|
||||
/// die Wand und vor Nachbaröffnungen (`opening_slide::place`, Steg 5 cm). `skip`: mitbewegte Öffnungen.
|
||||
/// `None`: Wirt fehlt, die Öffnung passt nicht in die Wand oder dort ist kein Platz. Das `bool` meldet,
|
||||
/// dass eine Nachbaröffnung die Lage begrenzt hat.
|
||||
fn slide_opening(root: &Map<String, Value>, p: &Project, o: &Value, d: (f64, f64), copy: bool, skip: &dyn Fn(&str) -> bool) -> Option<(Value, bool)> {
|
||||
use crate::opening_slide::{place, Axis};
|
||||
let walls = list(root, "walls");
|
||||
let host = walls.iter().find(|w| id_of(w) == wall_host(o))?;
|
||||
let width = num_of(field(o, "width"));
|
||||
let frame = |w: &Value| {
|
||||
let (s, e) = straight_wall(w)?;
|
||||
let len = hypot2(e.0 - s.0, e.1 - s.1);
|
||||
(len > 1e-9 && len.is_finite()).then(|| (s, ((e.0 - s.0) / len, (e.1 - s.1) / len), len))
|
||||
};
|
||||
let (s, u, len) = frame(host)?;
|
||||
let c = (s.0 + u.0 * (num_of(field(o, "position")) + width / 2.0), s.1 + u.1 * (num_of(field(o, "position")) + width / 2.0));
|
||||
let axis = Axis::of(host)?;
|
||||
let pos0 = num_of(field(o, "position"));
|
||||
let c = axis.point(pos0 + width / 2.0, 0.0);
|
||||
let target = (c.0 + d.0, c.1 + d.1);
|
||||
if !(target.0.is_finite() && target.1.is_finite() && width.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
// Abstand des Ziels zur Wandachse (Strecke) und Lage entlang der Achse.
|
||||
let reach = |w: &Value| -> Option<(f64, f64, f64)> {
|
||||
let (s, u, len) = frame(w)?;
|
||||
let t = (target.0 - s.0) * u.0 + (target.1 - s.1) * u.1;
|
||||
let tc = jsnum::max(0.0, jsnum::min(len, t));
|
||||
let dist = hypot2(target.0 - (s.0 + u.0 * tc), target.1 - (s.1 + u.1 * tc));
|
||||
Some((dist, t, len))
|
||||
};
|
||||
let tol = |w: &Value| wall_thickness(p, w) / 2.0 + 0.05;
|
||||
let in_host = reach(host).is_some_and(|(dist, _, _)| dist <= tol(host));
|
||||
let (t_host, dist_host) = axis.local(target);
|
||||
let in_host = dist_host <= tol(host);
|
||||
let floor = field(host, "floorId");
|
||||
let other = (!in_host)
|
||||
.then(|| {
|
||||
walls
|
||||
.iter()
|
||||
.filter(|w| id_of(w) != id_of(host) && field(w, "floorId") == floor)
|
||||
.filter_map(|w| reach(w).filter(|(dist, _, _)| *dist <= tol(w)).map(|r| (w, r)))
|
||||
.min_by(|a, b| a.1 .0.total_cmp(&b.1 .0))
|
||||
.filter_map(|w| {
|
||||
let ax = Axis::of(w)?;
|
||||
let (t, dist) = ax.local(target);
|
||||
(dist <= tol(w)).then_some((w, ax, t, dist))
|
||||
})
|
||||
.min_by(|a, b| a.3.total_cmp(&b.3))
|
||||
})
|
||||
.flatten();
|
||||
// Neue Lage des ersten Pfostens; in der eigenen Wand direkt `position + d·u` (ohne Rundung über die Mitte).
|
||||
let (wall, start, wlen) = match other {
|
||||
Some((w, (_, t, l))) => (w, t - width / 2.0, l),
|
||||
None => (host, num_of(field(o, "position")) + d.0 * u.0 + d.1 * u.1, len),
|
||||
let me = id_of(o).unwrap_or("");
|
||||
// Kopie: Originale bleiben stehen und sind Nachbarn wie jede andere (Kopie rückt an die nächste freie Stelle).
|
||||
let skip_me = |id: &str| !copy && (id == me || skip(id));
|
||||
let from = (!copy && pos0.is_finite()).then_some(pos0);
|
||||
// Neue Lage des ersten Pfostens; gerade eigene Wand direkt `position + d·u` (ohne Rundung über die Mitte).
|
||||
let (wall, placed) = match other {
|
||||
Some((w, ax, t, _)) => (w, place(root, id_of(w)?, ax.len(), width, None, t - width / 2.0, &skip_me)?),
|
||||
None => {
|
||||
let want = match &axis {
|
||||
Axis::Line { u, .. } => pos0 + d.0 * u.0 + d.1 * u.1,
|
||||
Axis::Arc(_) => t_host - width / 2.0,
|
||||
};
|
||||
(host, place(root, id_of(host)?, axis.len(), width, from, want, &skip_me)?)
|
||||
}
|
||||
};
|
||||
if width > wlen + 1e-9 {
|
||||
return None;
|
||||
}
|
||||
let pos = jsnum::max(0.0, jsnum::min(wlen - width, start));
|
||||
let mut v = with(o, "position", js_num(pos));
|
||||
let mut v = with(o, "position", js_num(placed.position));
|
||||
if id_of(wall) != id_of(host) {
|
||||
v = with(&v, "hostWallId", Value::String(id_of(wall)?.to_owned()));
|
||||
}
|
||||
Some(v)
|
||||
Some((v, placed.clamped))
|
||||
}
|
||||
|
||||
/// Frei gewählte Dach-/Deckenöffnungen ([144]): gewählt, nicht gesperrt, Wirt nicht mitbewegt; nur
|
||||
/// beim Verschieben. Sie gleiten in der Wirtsfläche (Mitte im Umriss gehalten).
|
||||
fn free_surface_openings<'a>(root: &'a Map<String, Value>, sel: &Sel, op: &str, hosts: &std::collections::HashSet<&str>, ignore_lock: bool) -> Vec<&'a Value> {
|
||||
let ids = Ids::opt(&sel.opening_ids);
|
||||
if op != "move" || ids.is_empty() {
|
||||
return vec![];
|
||||
}
|
||||
list(root, "openings")
|
||||
.iter()
|
||||
.filter(|o| ids.has(o) && (ignore_lock || !locked(o)))
|
||||
.filter(|o| surface_host(o).is_some_and(|(_, h)| !hosts.contains(h)))
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Dach-/Deckenöffnung um `d` verschieben: `hostPoint + d`, im Umriss des Wirts gehalten
|
||||
/// (`opening_slide::clamp_inside`). `None`: Wirt fehlt.
|
||||
fn slide_surface_opening(root: &Map<String, Value>, o: &Value, d: (f64, f64)) -> Option<Value> {
|
||||
let (key, h) = surface_host(o)?;
|
||||
let coll = if key == "hostRoofId" { "roofs" } else { "ceilings" };
|
||||
let host = list(root, coll).iter().find(|e| id_of(e) == Some(h))?;
|
||||
let ring = pts_of(field(host, "outline"));
|
||||
let (bx, by) = xy(field(o, "hostPoint").unwrap_or(&Value::Null));
|
||||
let q = crate::opening_slide::clamp_inside((bx + d.0, by + d.1), &ring);
|
||||
(q.0.is_finite() && q.1.is_finite()).then(|| with(o, "hostPoint", pt(q.0, q.1)))
|
||||
}
|
||||
|
||||
/// Verschiebung der Klickpunkte zum Anteil `t` (Bewegen).
|
||||
@@ -665,14 +693,47 @@ fn add(collection: &str, items: Vec<Value>) -> Option<Op> {
|
||||
/// Die Transformation als Ops: `replace` je bewegtem Original (Modus „move“), dann `add` der Kopien je
|
||||
/// Liste (Wände, 2D, Körper, Stützen, Decken, Dächer, Treppen, Räume).
|
||||
pub fn transform_ops(root: &Map<String, Value>, p: &Project, req: &TransformReq) -> Vec<Op> {
|
||||
transform_result(root, p, req).ops
|
||||
}
|
||||
|
||||
/// Gemeinsame Mengen von Ops und Vorschau: (bewegte Wände, Wirte von Dach-/Deckenöffnungen) → frei
|
||||
/// gewählte Wand- und Flächenöffnungen ([144]).
|
||||
fn free_sets<'a>(root: &'a Map<String, Value>, sel: &Sel, op: &str, items: &[(Kind, &'a Value)], ignore_lock: bool) -> (Vec<&'a Value>, Vec<&'a Value>) {
|
||||
let ids_of = |f: &dyn Fn(&Kind) -> bool| -> std::collections::HashSet<&'a str> { items.iter().filter(|(k, _)| f(k)).filter_map(|(_, e)| id_of(e)).collect() };
|
||||
let walls = ids_of(&|k| matches!(k, Kind::Wall));
|
||||
let hosts = ids_of(&|k| matches!(k, Kind::Roof | Kind::Ceiling));
|
||||
(free_openings(root, sel, op, &walls, ignore_lock), free_surface_openings(root, sel, op, &hosts, ignore_lock))
|
||||
}
|
||||
|
||||
/// Wie [`transform_ops`], mit Hinweis ([144]: eine Öffnung hielt an der Nachbaröffnung an bzw. fand in
|
||||
/// der Zielwand keinen Platz).
|
||||
pub fn transform_result(root: &Map<String, Value>, p: &Project, req: &TransformReq) -> crate::grips::GripResult {
|
||||
let (sel, op) = (&req.sel, req.op.as_str());
|
||||
let items = gather(root, sel, op, false);
|
||||
let moved_walls: std::collections::HashSet<&str> =
|
||||
items.iter().filter(|(k, _)| matches!(k, Kind::Wall)).filter_map(|(_, e)| id_of(e)).collect();
|
||||
let free = free_openings(root, sel, op, &moved_walls, false);
|
||||
if items.is_empty() && free.is_empty() {
|
||||
return vec![];
|
||||
let (free, free_surf) = free_sets(root, sel, op, &items, false);
|
||||
if items.is_empty() && free.is_empty() && free_surf.is_empty() {
|
||||
return Default::default();
|
||||
}
|
||||
let notice: std::cell::Cell<Option<&'static str>> = Default::default();
|
||||
let free_ids: std::collections::HashSet<&str> = free.iter().filter_map(|o| id_of(o)).collect();
|
||||
let skip = |id: &str| free_ids.contains(id);
|
||||
// Gleiten mit Hinweis: Anschlag an der Nachbaröffnung bzw. kein Platz.
|
||||
let slide = |o: &Value, d: (f64, f64), copy: bool| -> Option<Value> {
|
||||
match slide_opening(root, p, o, d, copy, &skip) {
|
||||
Some((v, clamped)) => {
|
||||
if clamped {
|
||||
notice.set(Some(crate::opening_slide::NOTICE_OVERLAP));
|
||||
}
|
||||
Some(v)
|
||||
}
|
||||
None => {
|
||||
if d != (0.0, 0.0) && wall_host(o).is_some() {
|
||||
notice.set(notice.get().or(Some(crate::opening_slide::NOTICE_NO_ROOM)));
|
||||
}
|
||||
None
|
||||
}
|
||||
}
|
||||
};
|
||||
let pts = req.points();
|
||||
let scaling = op == "scale";
|
||||
let k_at = |t: f64| if scaling { scale_factor(&pts, t) } else { 1.0 };
|
||||
@@ -741,7 +802,9 @@ pub fn transform_ops(root: &Map<String, Value>, p: &Project, req: &TransformReq)
|
||||
}
|
||||
// Frei gewählte Wandöffnungen ([144]) gleiten entlang ihrer Wand (bzw. wechseln die Wand).
|
||||
let d = move_delta(&pts, 1.0);
|
||||
ops.extend(free.iter().filter_map(|o| slide_opening(root, p, o, d).filter(|v| v != *o)).map(|v| replace("openings", v)));
|
||||
ops.extend(free.iter().filter_map(|o| slide(o, d, false).filter(|v| v != *o)).map(|v| replace("openings", v)));
|
||||
// Frei gewählte Dach-/Deckenöffnungen ([144]) gleiten in ihrer Fläche.
|
||||
ops.extend(free_surf.iter().filter_map(|o| slide_surface_opening(root, o, d).filter(|v| v != *o)).map(|v| replace("openings", v)));
|
||||
}
|
||||
|
||||
// Kopien (Kopie/Reihe/Verteilen bzw. gespiegelte Kopie).
|
||||
@@ -796,7 +859,12 @@ pub fn transform_ops(root: &Map<String, Value>, p: &Project, req: &TransformReq)
|
||||
}
|
||||
// Kopien frei gewählter Wandöffnungen ([144]) in der Wand versetzt.
|
||||
for o in &free {
|
||||
if let Some(v) = slide_opening(root, p, o, move_delta(&pts, t)) {
|
||||
if let Some(v) = slide(o, move_delta(&pts, t), true) {
|
||||
new_openings.push(with(&v, "id", Value::String(ids.next("O"))));
|
||||
}
|
||||
}
|
||||
for o in &free_surf {
|
||||
if let Some(v) = slide_surface_opening(root, o, move_delta(&pts, t)) {
|
||||
new_openings.push(with(&v, "id", Value::String(ids.next("O"))));
|
||||
}
|
||||
}
|
||||
@@ -806,7 +874,7 @@ pub fn transform_ops(root: &Map<String, Value>, p: &Project, req: &TransformReq)
|
||||
ops.extend(add(key, items));
|
||||
}
|
||||
ops.extend(add("openings", new_openings));
|
||||
ops
|
||||
crate::grips::GripResult { ops, notice: notice.get() }
|
||||
}
|
||||
|
||||
// ── Ausrichten/Verteilen, Block definieren ───────────────────────────────────
|
||||
@@ -1155,9 +1223,9 @@ pub fn preview_pending(root: &Map<String, Value>, p: &Project, req: &TransformRe
|
||||
if req.mode == "move" {
|
||||
ts.push(1.0);
|
||||
}
|
||||
let moved_walls: std::collections::HashSet<&str> =
|
||||
items.iter().filter(|(k, _)| matches!(k, Kind::Wall)).filter_map(|(_, e)| id_of(e)).collect();
|
||||
let free = free_openings(root, &req.sel, op, &moved_walls, req.ignore_lock);
|
||||
let (free, free_surf) = free_sets(root, &req.sel, op, &items, req.ignore_lock);
|
||||
let free_ids: std::collections::HashSet<&str> = free.iter().filter_map(|o| id_of(o)).collect();
|
||||
let skip = |id: &str| free_ids.contains(id);
|
||||
let mut out = Pending::default();
|
||||
for t in ts {
|
||||
let xf = Xf::of(op, &pts, t);
|
||||
@@ -1165,7 +1233,12 @@ pub fn preview_pending(root: &Map<String, Value>, p: &Project, req: &TransformRe
|
||||
item_preview(p, *kind, e, &xf, &mut out);
|
||||
}
|
||||
for o in &free {
|
||||
if let Some(q) = slide_opening(root, p, o, move_delta(&pts, t)).and_then(|v| opening_quad(root, p, &v)) {
|
||||
if let Some(q) = slide_opening(root, p, o, move_delta(&pts, t), req.mode != "move", &skip).and_then(|(v, _)| opening_quad(root, p, &v)) {
|
||||
out.shapes.poly(&q);
|
||||
}
|
||||
}
|
||||
for o in &free_surf {
|
||||
if let Some(q) = slide_surface_opening(root, o, move_delta(&pts, t)).map(|v| surface_quad(&v)) {
|
||||
out.shapes.poly(&q);
|
||||
}
|
||||
}
|
||||
@@ -1173,10 +1246,30 @@ pub fn preview_pending(root: &Map<String, Value>, p: &Project, req: &TransformRe
|
||||
out
|
||||
}
|
||||
|
||||
/// Lücke einer Wandöffnung (Vorschau, [144]): Rechteck über die volle Wanddicke um die Achse.
|
||||
/// Dach-/Deckenöffnung als Rechteck um `hostPoint` (Vorschau, [144]; Breite quer, Höhe im Grundriss
|
||||
/// ungekürzt, gedreht um `hostAngle`).
|
||||
fn surface_quad(o: &Value) -> Vec<(f64, f64)> {
|
||||
let (cx, cy) = xy(field(o, "hostPoint").unwrap_or(&Value::Null));
|
||||
let (w, h) = (num_or(field(o, "width"), 1.0) / 2.0, num_or(field(o, "height"), 1.0) / 2.0);
|
||||
let a = field(o, "hostAngle").and_then(Value::as_f64).unwrap_or(0.0);
|
||||
let (c, s) = (jsnum::cos(a), jsnum::sin(a));
|
||||
[(-w, -h), (w, -h), (w, h), (-w, h)].iter().map(|(x, y)| (cx + x * c - y * s, cy + x * s + y * c)).collect()
|
||||
}
|
||||
|
||||
/// Lücke einer Wandöffnung (Vorschau, [144]): Rechteck über die volle Wanddicke um die Achse; in einer
|
||||
/// Bogenwand der Ringsektor-Abschnitt (Sehnen).
|
||||
fn opening_quad(root: &Map<String, Value>, p: &Project, o: &Value) -> Option<Vec<(f64, f64)>> {
|
||||
use crate::opening_geom::{opening_gap_quad, v, WallRef};
|
||||
let w = list(root, "walls").iter().find(|w| id_of(w) == wall_host(o))?;
|
||||
if let Some(ax @ crate::opening_slide::Axis::Arc(_)) = crate::opening_slide::Axis::of(w) {
|
||||
let (a, b) = (num_of(field(o, "position")), num_of(field(o, "width")));
|
||||
let half = wall_thickness(p, w) / 2.0;
|
||||
let n = 8;
|
||||
let ts: Vec<f64> = (0..=n).map(|i| a + b * i as f64 / n as f64).collect();
|
||||
let mut q: Vec<(f64, f64)> = ts.iter().map(|t| ax.point(*t, half)).collect();
|
||||
q.extend(ts.iter().rev().map(|t| ax.point(*t, -half)));
|
||||
return q.iter().all(|c| c.0.is_finite() && c.1.is_finite()).then_some(q);
|
||||
}
|
||||
let (s, e) = straight_wall(w)?;
|
||||
let wr = WallRef { start: v(s.0, s.1), end: v(e.0, e.1), total: wall_thickness(p, w), ref_off: 0.0 };
|
||||
let q = opening_gap_quad(&wr, num_of(field(o, "position")), num_of(field(o, "width")))?;
|
||||
@@ -1396,8 +1489,17 @@ mod tests {
|
||||
assert_eq!((&o["hostWallId"], &o["position"]), (&json!("v"), &json!(1.55)));
|
||||
// Wand im anderen Geschoss zählt nicht: ausserhalb jeder Wand → nur Gleiten (projiziert).
|
||||
assert_eq!(one(&run(json!([[1.45, 0], [2.45, 3]]), "move", sel.clone()))["hostWallId"], json!("w"));
|
||||
// Gesperrte Öffnung und Öffnung in Bogenwand bleiben.
|
||||
assert!(run(json!([[0, 0], [1, 0]]), "move", json!({"wallIds":[],"openingIds":["z","a"]})).is_empty());
|
||||
// Gesperrte Öffnung bleibt.
|
||||
assert!(run(json!([[0, 0], [1, 0]]), "move", json!({"wallIds":[],"openingIds":["z"]})).is_empty());
|
||||
// Bogenwand ([T2]): Ziel = Lotfuss auf dem Bogen, `position` = Bogenlänge; geklemmt an den Bogenenden.
|
||||
let arc = crate::opening_slide::Axis::of(&r["walls"][3]).unwrap();
|
||||
let (c, tg) = (arc.point(1.5, 0.0), arc.tangent(1.5));
|
||||
let mv = |k: f64| json!([[c.0, c.1], [c.0 + tg.0 * k, c.1 + tg.1 * k]]);
|
||||
let pos = one(&run(mv(0.3), "move", json!({"wallIds":[],"openingIds":["a"]})))["position"].as_f64().unwrap();
|
||||
assert!((pos - 1.3).abs() < 0.01, "{pos}");
|
||||
let o = one(&run(mv(20.0), "move", json!({"wallIds":[],"openingIds":["a"]})));
|
||||
assert!((o["position"].as_f64().unwrap() - (arc.len() - 1.0)).abs() < 1e-9 && o["hostWallId"] == "b");
|
||||
assert_eq!(one(&run(mv(-20.0), "move", json!({"wallIds":[],"openingIds":["a"]})))["position"], json!(0));
|
||||
// Drehen einer Öffnung allein: nichts.
|
||||
let req: TransformReq = serde_json::from_value(json!({"sel":sel,"op":"rotate","pts":[[0,0],[1,0],[0,1]],"mode":"move","count":1,"stamp":"s"})).unwrap();
|
||||
assert!(transform_ops(&r, &Project::default(), &req).is_empty());
|
||||
@@ -1415,6 +1517,115 @@ mod tests {
|
||||
assert!(!preview_pending(&r, &Project::default(), &req).shapes.buf.is_empty());
|
||||
}
|
||||
|
||||
/// [144] Überlappung: gleitend hält die Öffnung 5 cm vor der Nachbaröffnung an (mit Hinweis), Kopie
|
||||
/// rückt an die nächste freie Stelle; Bestand bleibt; mitbewegte Öffnungen zählen nicht.
|
||||
#[test]
|
||||
fn oeffnung_haelt_vor_der_nachbaroeffnung() {
|
||||
let r = root(json!({
|
||||
"walls":[{"id":"w","floorId":"eg","start":{"x":0,"y":0},"end":{"x":10,"y":0}}],
|
||||
"openings":[
|
||||
{"id":"d","hostWallId":"w","kind":"door","position":1,"width":1},
|
||||
{"id":"f","hostWallId":"w","kind":"window","position":4,"width":1}
|
||||
]}));
|
||||
let run = |pts: Value, mode: &str, ids: Value| {
|
||||
let req: TransformReq = serde_json::from_value(json!({"sel":{"wallIds":[],"openingIds":ids},"op":"move","pts":pts,"mode":mode,"count":1,"stamp":"s"})).unwrap();
|
||||
transform_result(&r, &Project::default(), &req)
|
||||
};
|
||||
let res = run(json!([[0, 0], [5, 0]]), "move", json!(["d"]));
|
||||
assert_eq!(res.notice, Some(crate::opening_slide::NOTICE_OVERLAP));
|
||||
assert_eq!(res.ops[0].to_json()["entity"]["position"], json!(2.95));
|
||||
// Frei: kein Hinweis.
|
||||
let res = run(json!([[0, 0], [1, 0]]), "move", json!(["d"]));
|
||||
assert_eq!((res.notice, res.ops[0].to_json()["entity"]["position"].clone()), (None, json!(2)));
|
||||
// Beide gewählt: gleiten zusammen, ohne Anschlag aneinander.
|
||||
let res = run(json!([[0, 0], [2.5, 0]]), "move", json!(["d", "f"]));
|
||||
assert_eq!(res.notice, None);
|
||||
let pos: Vec<Value> = res.ops.iter().map(|o| o.to_json()["entity"]["position"].clone()).collect();
|
||||
assert_eq!(pos, vec![json!(3.5), json!(6.5)]);
|
||||
// Kopie um 0.5 überlappte das Original: rückt an die nächste freie Stelle (2.05).
|
||||
let res = run(json!([[0, 0], [0.5, 0]]), "copy", json!(["d"]));
|
||||
let items = res.ops[0].to_json()["items"].clone();
|
||||
assert_eq!(items[0]["position"], json!(2.05));
|
||||
assert_eq!(res.notice, Some(crate::opening_slide::NOTICE_OVERLAP));
|
||||
}
|
||||
|
||||
/// [144] Bemassungs-Bezüge auf eine gleitende Öffnung (Leibung, gerade und Bogenwand) folgen über das
|
||||
/// Nachführen im Dokument — beim Verschieben-Befehl, beim Griff-Zug und bei der Objekt-Info-Position.
|
||||
#[test]
|
||||
fn bemassung_folgt_der_gleitenden_oeffnung() {
|
||||
use crate::document::Document;
|
||||
let r = json!({
|
||||
"walls":[{"id":"w","floorId":"eg","start":{"x":0,"y":0},"end":{"x":10,"y":0}},
|
||||
{"id":"b","floorId":"eg","start":{"x":0,"y":5},"end":{"x":4,"y":5},"bulge":1}],
|
||||
"openings":[{"id":"d","hostWallId":"w","kind":"door","position":1,"width":1},
|
||||
{"id":"a","hostWallId":"b","kind":"window","position":1,"width":1}],
|
||||
"drawings2d":[
|
||||
{"id":"m","levelId":"eg","geom":{"shape":"dimension","pts":[{"x":0,"y":-1},{"x":1,"y":-1},{"x":2,"y":-1}],"offset":0,
|
||||
"refs":[{"id":"w","feature":"wall","t":0,"d":1},{"id":"d","feature":"opening","index":0,"d":1},{"id":"d","feature":"opening","index":1,"d":1}]}},
|
||||
{"id":"k","levelId":"eg","geom":{"shape":"dimension","pts":[{"x":0,"y":5},{"x":1,"y":6}],"offset":0,
|
||||
"refs":[{"id":"a","feature":"opening","index":0},{"id":"a","feature":"opening","index":1}]}}
|
||||
]});
|
||||
let mut doc = Document::from_json(&r.to_string()).unwrap();
|
||||
let pts = |doc: &Document, id: &str| -> Vec<(f64, f64)> {
|
||||
let d = doc.root()["drawings2d"].as_array().unwrap().iter().find(|d| d["id"] == id).unwrap().clone();
|
||||
d["geom"]["pts"].as_array().unwrap().iter().map(|p| (p["x"].as_f64().unwrap(), p["y"].as_f64().unwrap())).collect()
|
||||
};
|
||||
let close = |a: (f64, f64), b: (f64, f64)| assert!((a.0 - b.0).abs() < 1e-9 && (a.1 - b.1).abs() < 1e-9, "{a:?} != {b:?}");
|
||||
// Bogen-Leibungen: erst einmal nachführen (Bogenpunkte statt Sehne).
|
||||
let arc = crate::opening_slide::Axis::of(&r["walls"][1]).unwrap();
|
||||
doc.commit(crate::dim_assoc::sync_ops(&doc.lookup()), None, 0.0, false).unwrap();
|
||||
close(pts(&doc, "k")[0], arc.point(1.0, 0.0));
|
||||
close(pts(&doc, "k")[1], arc.point(2.0, 0.0));
|
||||
// Verschieben-Befehl: Tür um 2 m → Kette folgt (Wandende bleibt).
|
||||
let req = json!({"cmd":"transform","sel":{"wallIds":[],"drawingId":null,"openingIds":["d"]},"op":"move","pts":[[0,0],[2,0]],"mode":"move","count":1,"stamp":"s"});
|
||||
let res = { let (p, lk) = doc.project_lookup().unwrap(); crate::commands::result(lk.root, p, &req.to_string()).unwrap() };
|
||||
doc.commit(res.ops, None, 1.0, false).unwrap();
|
||||
let q = pts(&doc, "m");
|
||||
close(q[0], (0.0, -1.0));
|
||||
close(q[1], (3.0, -1.0));
|
||||
close(q[2], (4.0, -1.0));
|
||||
// Griff-Zug und Objekt-Info-Position (grips.rs): gleicher Weg.
|
||||
let grip = |doc: &mut Document, req: Value| {
|
||||
let req: crate::grips::Request = serde_json::from_value(req).unwrap();
|
||||
let res = crate::grips::run(&doc.lookup(), &req).unwrap();
|
||||
doc.commit(res.ops, None, 2.0, false).unwrap();
|
||||
};
|
||||
grip(&mut doc, json!({"op":"openingSlide","id":"d","pt":[6.5,0.3]}));
|
||||
close(pts(&doc, "m")[1], (6.0, -1.0));
|
||||
grip(&mut doc, json!({"op":"openingPosition","id":"d","a":5}));
|
||||
close(pts(&doc, "m")[2], (6.0, -1.0));
|
||||
// Bogenwand: Fenster entlang des Bogens → Leibungen auf dem Bogen.
|
||||
grip(&mut doc, json!({"op":"openingPosition","id":"a","a":2.5}));
|
||||
close(pts(&doc, "k")[0], arc.point(2.5, 0.0));
|
||||
close(pts(&doc, "k")[1], arc.point(3.5, 0.0));
|
||||
// Rückgängig: Kette wieder bei der alten Lage.
|
||||
doc.undo();
|
||||
close(pts(&doc, "k")[0], arc.point(1.0, 0.0));
|
||||
}
|
||||
|
||||
/// [144] Dach-/Deckenöffnung allein verschieben: `hostPoint` wandert, im Umriss des Wirts gehalten.
|
||||
#[test]
|
||||
fn dachoeffnung_allein_verschieben() {
|
||||
let r = root(json!({
|
||||
"roofs":[{"id":"rf","outline":[{"x":0,"y":0},{"x":6,"y":0},{"x":6,"y":4},{"x":0,"y":4}]}],
|
||||
"openings":[{"id":"o","hostWallId":"","hostRoofId":"rf","hostPoint":{"x":1,"y":1},"width":0.8,"height":1.2}]}));
|
||||
let run = |pts: Value, mode: &str| {
|
||||
let req: TransformReq = serde_json::from_value(json!({"sel":{"wallIds":[],"openingIds":["o"]},"op":"move","pts":pts,"mode":mode,"count":1,"stamp":"s"})).unwrap();
|
||||
transform_ops(&r, &Project::default(), &req).iter().map(|o| o.to_json()).collect::<Vec<_>>()
|
||||
};
|
||||
let ops = run(json!([[0, 0], [2, 1]]), "move");
|
||||
assert_eq!(ops[0]["entity"]["hostPoint"], json!({"x":3,"y":2}));
|
||||
// Ausserhalb: an den Rand, 5 cm nach innen.
|
||||
let hp = run(json!([[0, 0], [20, 0]]), "move")[0]["entity"]["hostPoint"].clone();
|
||||
assert!((hp["x"].as_f64().unwrap() - 5.95).abs() < 0.02 && (hp["y"].as_f64().unwrap() - 1.0).abs() < 0.05, "{hp}");
|
||||
// Kopie: neue Öffnung im selben Dach.
|
||||
let ops = run(json!([[0, 0], [2, 0]]), "copy");
|
||||
assert_eq!((&ops[0]["items"][0]["hostRoofId"], &ops[0]["items"][0]["hostPoint"]), (&json!("rf"), &json!({"x":3,"y":1})));
|
||||
// Vorschau zeigt sie.
|
||||
let req: TransformReq = serde_json::from_value(json!({"sel":{"wallIds":[],"openingIds":["o"]},"op":"move","pts":[[0,0],[1,0]],"mode":"move","count":1,"stamp":"s"})).unwrap();
|
||||
assert!(!preview_pending(&r, &Project::default(), &req).shapes.buf.is_empty());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn verschieben_und_kopieren() {
|
||||
let r = root(json!({"walls":[{"id":"a","start":{"x":0,"y":0},"end":{"x":1,"y":0},"locked":false},{"id":"b","start":{"x":0,"y":0},"end":{"x":1,"y":0},"locked":true}]}));
|
||||
|
||||
@@ -47,9 +47,19 @@ pub fn ops(root: &Map<String, Value>, p: &Project, text: &str) -> Result<Vec<Op>
|
||||
})
|
||||
}
|
||||
|
||||
/// Wie [`ops`], als Antwort-JSON `{"ops": […]}` (Zahlen mit Nicht-endlich-Marken).
|
||||
/// Wie [`ops`], mit Hinweis-Schlüssel (i18n) für die Hülle; bisher nur Verschieben ([144]: Öffnung an
|
||||
/// der Nachbaröffnung angehalten).
|
||||
pub fn result(root: &Map<String, Value>, p: &Project, text: &str) -> Result<GripResult, String> {
|
||||
let v: Value = serde_json::from_str(text).map_err(|e| format!("cmdOps: {e}"))?;
|
||||
if v.get("group").is_none() && v.get("cmd").and_then(Value::as_str) == Some("transform") {
|
||||
return Ok(crate::cmd_transform::transform_result(root, p, &parse(&v, "transform")?));
|
||||
}
|
||||
Ok(GripResult { ops: ops(root, p, text)?, notice: None })
|
||||
}
|
||||
|
||||
/// Wie [`result`], als Antwort-JSON `{"ops": […], "notice": …}` (Zahlen mit Nicht-endlich-Marken).
|
||||
pub fn ops_json(root: &Map<String, Value>, p: &Project, text: &str) -> Result<String, String> {
|
||||
Ok(result_json(&GripResult { ops: ops(root, p, text)?, notice: None }))
|
||||
Ok(result_json(&result(root, p, text)?))
|
||||
}
|
||||
|
||||
/// Schneller Hasher für id-Mengen der Befehle (FNV-1a; je Mausschritt werden Tausende ids geprüft,
|
||||
|
||||
@@ -154,12 +154,13 @@ impl WallGeo {
|
||||
}
|
||||
}
|
||||
|
||||
/// Leibungs-/Mittelpunkt einer Öffnung auf der Linie `layer` der Wirtswand (wie `autodim`).
|
||||
/// Leibungs-/Mittelpunkt einer Öffnung auf der Linie `layer` der Wirtswand (wie `autodim`). Bogenwand
|
||||
/// ([T2], [144]): `position` ist Bogenlänge auf der Achse, der Punkt liegt auf dem Versatzbogen.
|
||||
fn opening_point(lk: &Lookup, o: &Value, side: u32, layer: Option<u32>) -> Option<P> {
|
||||
let w = lk.find("walls", str_of(o, "hostWallId")?)?;
|
||||
let g = wall_geo(lk, w)?;
|
||||
let (a, b) = g.line(layer)?;
|
||||
let axis = dist(g.a, g.b);
|
||||
let axis = g.warc.as_ref().map_or_else(|| dist(g.a, g.b), |w| w.length());
|
||||
let (pos, width) = (num(o.get("position"))?, num(o.get("width"))?);
|
||||
let from = pos.min(axis).max(0.0);
|
||||
let to = (pos + width).min(axis).max(from);
|
||||
@@ -169,6 +170,10 @@ fn opening_point(lk: &Lookup, o: &Value, side: u32, layer: Option<u32>) -> Optio
|
||||
2 => (from + to) / 2.0,
|
||||
_ => return None,
|
||||
};
|
||||
if let Some(w) = &g.warc {
|
||||
let q = w.point(s, g.offset(layer)?);
|
||||
return Some((q.x, q.y));
|
||||
}
|
||||
let u = unit(a, b)?;
|
||||
Some(add(a, u, s))
|
||||
}
|
||||
|
||||
@@ -9,7 +9,7 @@
|
||||
//! - Kanten-Griff: geführte Kante (nur entlang der Aussennormale, Raster/Geometrie-Snap) bzw. freie Kante
|
||||
//! (Ortho, Raster), mit oder ohne gelockte Felder ([`edge_target`]);
|
||||
//! - Höhen-Griffe im Schnitt (Wand-Oberkante, Fenster Ober-/Unterkante, [`sheet_height`]);
|
||||
//! - Öffnung entlang der Wirtswand ([`opening_slide`], [`opening_slide_sheet`]), Griff-Lagen von
|
||||
//! - Öffnung entlang der Wirtswand ([`opening_slide_sheet`]; der Griff-Zug selbst: `crate::opening_slide`), Griff-Lagen von
|
||||
//! Öffnung, Treppe, Bogenwand und Baugrube;
|
||||
//! - koinzidente Ecken anderer gewählter Elemente beim Körper-Verschieben ([`coincident`]).
|
||||
//!
|
||||
@@ -211,21 +211,13 @@ pub fn sheet_height(kind: HeightGrip, base: f64, top: f64, bottom: f64, y: f64,
|
||||
}
|
||||
|
||||
/// Mittelpunkt-Griff einer Öffnung (Breite `width`, `position` = Abstand des ersten Pfostens) auf der Wandachse.
|
||||
pub fn opening_wall_grip(ws: P, we: P, position: f64, width: f64) -> P {
|
||||
add(ws, scale(normalize(sub(we, ws)), position + width / 2.0))
|
||||
}
|
||||
|
||||
/// Neue `position` einer Öffnung, deren Mittelpunkt-Griff nach `pt` gezogen wird: auf die Wandachse
|
||||
/// projiziert und auf [0, Wandlänge − Breite] geklemmt. `None` bei einer Wand ohne Länge.
|
||||
pub fn opening_slide(ws: P, we: P, width: f64, pt: P) -> Option<f64> {
|
||||
let d = sub(we, ws);
|
||||
let len = hypot2(d.0, d.1);
|
||||
if !(len > 1e-9) {
|
||||
return None;
|
||||
pub fn opening_wall_grip(ws: P, we: P, bulge: f64, position: f64, width: f64) -> P {
|
||||
// Bogenwand ([T2], [144]): Punkt auf dem Bogen bei der Bogenlänge der Öffnungsmitte.
|
||||
if let Some(a) = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(ws.0, ws.1), kernel2d::Vec2::new(we.0, we.1), Some(bulge)) {
|
||||
let q = a.point(position + width / 2.0, 0.0);
|
||||
return (q.x, q.y);
|
||||
}
|
||||
let axis = scale(d, 1.0 / len);
|
||||
let t = dot(sub(pt, ws), axis);
|
||||
Some(jsnum::max(0.0, jsnum::min(len - width, t - width / 2.0)))
|
||||
add(ws, scale(normalize(sub(we, ws)), position + width / 2.0))
|
||||
}
|
||||
|
||||
/// Öffnung im Schnitt-Blatt waagrecht ziehen: Blatt-Delta `du` (gesamt, entlang der Schnitt-Achse `u_axis`)
|
||||
@@ -398,12 +390,10 @@ mod tests {
|
||||
#[test]
|
||||
fn oeffnung_entlang_der_wand() {
|
||||
let (s, e) = ((0.0, 0.0), (5.0, 0.0));
|
||||
assert!(close(opening_wall_grip(s, e, 1.0, 1.2), (1.6, 0.0)));
|
||||
assert_eq!(opening_slide(s, e, 1.2, (2.6, 3.0)), Some(2.0));
|
||||
// Geklemmt an beide Enden.
|
||||
assert_eq!(opening_slide(s, e, 1.2, (-3.0, 0.0)), Some(0.0));
|
||||
assert_eq!(opening_slide(s, e, 1.2, (9.0, 0.0)), Some(3.8));
|
||||
assert_eq!(opening_slide(s, s, 1.2, (1.0, 0.0)), None);
|
||||
assert!(close(opening_wall_grip(s, e, 0.0, 1.0, 1.2), (1.6, 0.0)));
|
||||
// Bogenwand (Halbkreis, Radius 2.5): Mitte bei Bogenlänge 2.5·π/2 = Scheitel.
|
||||
let q = opening_wall_grip(s, e, 1.0, 2.5 * std::f64::consts::FRAC_PI_2 - 0.6, 1.2);
|
||||
assert!(close((q.0, q.1.abs()), (2.5, 2.5)), "{q:?}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -358,6 +358,18 @@ pub fn run(lk: &Lookup, req: &Request) -> Result<GripResult, String> {
|
||||
}
|
||||
"wallThickness" => wall_thickness(root, r.s("id").unwrap_or(""), r.n("thickness"), r.s("newId").unwrap_or(""), req.new_name.clone()).into(),
|
||||
"ceilingThickness" => ceiling_thickness(root, r.s("id").unwrap_or(""), r.n("thickness"), r.s("newId").unwrap_or(""), req.new_name.clone()).into(),
|
||||
// [144] Wandöffnung gleiten lassen: Griff-Zug nach `pt` bzw. Objekt-Info-Position `a` (ab
|
||||
// Wandanfang; Bogenwand: Bogenlänge). Geklemmt auf die Wand und vor der Nachbaröffnung.
|
||||
"openingSlide" | "openingPosition" => {
|
||||
let Some(o) = r.s("id").and_then(|id| lk.find("openings", id)).filter(|o| !crate::json_util::truthy(field(o, "locked"))) else {
|
||||
return Ok(GripResult::default());
|
||||
};
|
||||
let want = if op == "openingSlide" { crate::opening_slide::grip_want(root, o, r.p("pt")) } else { Some(r.n("a")).filter(|v| v.is_finite()) };
|
||||
let Some(placed) = want.and_then(|w| crate::opening_slide::slide_to(root, o, w)) else { return Ok(GripResult::default()) };
|
||||
let v = with(o, "position", js_num(placed.position));
|
||||
let ops = if v == *o { vec![] } else { vec![replace("openings", v)] };
|
||||
GripResult { ops, notice: placed.clamped.then_some(crate::opening_slide::NOTICE_OVERLAP) }
|
||||
}
|
||||
other => return Err(format!("Unbekannte Griff-Änderung: {other}")),
|
||||
})
|
||||
}
|
||||
|
||||
@@ -120,6 +120,7 @@ pub mod surface_pattern;
|
||||
pub mod surface_pattern3d;
|
||||
pub mod standards;
|
||||
pub mod dim_assoc;
|
||||
pub mod opening_slide;
|
||||
|
||||
#[cfg(feature = "web")]
|
||||
mod web;
|
||||
|
||||
@@ -0,0 +1,281 @@
|
||||
//! Wandöffnungen in ihrer Wand verschieben ([144]): gemeinsamer Weg für den Verschieben-Befehl
|
||||
//! (`cmd_transform`), den Griff-Zug und das Objekt-Info-Feld „Position" (`grips.rs`).
|
||||
//!
|
||||
//! - **Wandachse** gerade oder als Bogen ([T2]): `position` ist bei Bogenwänden die Bogenlänge auf der
|
||||
//! Achse ab `start` (wie die abgewickelte Wand im Grundriss), die Wandlänge die Bogenlänge.
|
||||
//! - **Überlappung**: eine gleitende Öffnung hält vor der Nachbaröffnung derselben Wand an und lässt
|
||||
//! einen Steg von [`MIN_WEB`]; schon überlappende Daten (Bestand) bleiben, wie sie sind.
|
||||
//! - **Dach-/Deckenöffnungen**: Mittelpunkt im Umriss des Wirts halten ([`clamp_inside`]).
|
||||
|
||||
use crate::json_util::{field, num_of};
|
||||
use crate::ops::id_of;
|
||||
use crate::wall_arc::WallArc;
|
||||
use serde_json::{Map, Value};
|
||||
|
||||
type P = (f64, f64);
|
||||
|
||||
/// Kleinster Steg zwischen zwei Öffnungen derselben Wand (Meter).
|
||||
pub const MIN_WEB: f64 = 0.05;
|
||||
/// Hinweis-Schlüssel (i18n), wenn eine Öffnung an der Nachbaröffnung anhält.
|
||||
pub const NOTICE_OVERLAP: &str = "opening.overlapClamped";
|
||||
/// Hinweis-Schlüssel, wenn in der Zielwand kein Platz ist.
|
||||
pub const NOTICE_NO_ROOM: &str = "opening.noRoom";
|
||||
|
||||
const EPS: f64 = 1e-9;
|
||||
|
||||
/// Wandachse: Strecke oder Bogen.
|
||||
pub enum Axis {
|
||||
Line { s: P, u: P, len: f64 },
|
||||
Arc(WallArc),
|
||||
}
|
||||
|
||||
impl Axis {
|
||||
/// Achse der Wand `w` (`start`, `end`, `bulge`); `None` bei entarteter Wand.
|
||||
pub fn of(w: &Value) -> Option<Axis> {
|
||||
let pt = |k: &str| -> Option<P> {
|
||||
let v = field(w, k)?;
|
||||
let (x, y) = (field(v, "x")?.as_f64()?, field(v, "y")?.as_f64()?);
|
||||
(x.is_finite() && y.is_finite()).then_some((x, y))
|
||||
};
|
||||
let (s, e) = (pt("start")?, pt("end")?);
|
||||
let bulge = field(w, "bulge").and_then(Value::as_f64);
|
||||
if crate::wall_arc::is_arc_bulge(bulge) {
|
||||
let a = WallArc::of(kernel2d::Vec2::new(s.0, s.1), kernel2d::Vec2::new(e.0, e.1), bulge)?;
|
||||
return Some(Axis::Arc(a));
|
||||
}
|
||||
let len = crate::jsmath::hypot2(e.0 - s.0, e.1 - s.1);
|
||||
(len > EPS && len.is_finite()).then(|| Axis::Line { s, u: ((e.0 - s.0) / len, (e.1 - s.1) / len), len })
|
||||
}
|
||||
|
||||
/// Länge der Achse (Bogen: Bogenlänge).
|
||||
pub fn len(&self) -> f64 {
|
||||
match self {
|
||||
Axis::Line { len, .. } => *len,
|
||||
Axis::Arc(a) => a.length(),
|
||||
}
|
||||
}
|
||||
|
||||
/// Punkt auf der Achse bei Lauflänge `t`, quer um `n` (linke Normale) versetzt.
|
||||
pub fn point(&self, t: f64, n: f64) -> P {
|
||||
match self {
|
||||
Axis::Line { s, u, .. } => (s.0 + u.0 * t - u.1 * n, s.1 + u.1 * t + u.0 * n),
|
||||
Axis::Arc(a) => {
|
||||
let q = a.point(t, n);
|
||||
(q.x, q.y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Einheits-Tangente (Laufrichtung) bei `t`.
|
||||
pub fn tangent(&self, t: f64) -> P {
|
||||
match self {
|
||||
Axis::Line { u, .. } => *u,
|
||||
Axis::Arc(a) => {
|
||||
let v = a.tangent(t);
|
||||
(v.x, v.y)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/// Lauflänge des Lotfusspunkts von `p` (ungeklemmt) und Abstand von `p` zur Achse (Lotfuss auf die
|
||||
/// Achse geklemmt).
|
||||
pub fn local(&self, p: P) -> (f64, f64) {
|
||||
let t = match self {
|
||||
Axis::Line { s, u, .. } => (p.0 - s.0) * u.0 + (p.1 - s.1) * u.1,
|
||||
Axis::Arc(a) => a.local(kernel2d::Vec2::new(p.0, p.1)).0,
|
||||
};
|
||||
let q = self.point(t.clamp(0.0, self.len()), 0.0);
|
||||
(t, crate::jsmath::hypot2(p.0 - q.0, p.1 - q.1))
|
||||
}
|
||||
}
|
||||
|
||||
/// Belegte Abschnitte `[Anfang, Ende]` der übrigen Öffnungen in Wand `host` (ohne `skip`).
|
||||
fn neighbours(root: &Map<String, Value>, host: &str, skip: &dyn Fn(&str) -> bool) -> Vec<(f64, f64)> {
|
||||
root.get("openings")
|
||||
.and_then(Value::as_array)
|
||||
.map(Vec::as_slice)
|
||||
.unwrap_or(&[])
|
||||
.iter()
|
||||
.filter(|o| field(o, "hostWallId").and_then(Value::as_str) == Some(host))
|
||||
.filter(|o| !id_of(o).is_some_and(skip))
|
||||
.filter_map(|o| {
|
||||
let (a, w) = (num_of(field(o, "position")), num_of(field(o, "width")));
|
||||
(a.is_finite() && w.is_finite() && w > 0.0).then_some((a, a + w))
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// Ergebnis der Überlappungs-Regel: neue `position` und ob eine Nachbaröffnung sie begrenzt hat.
|
||||
#[derive(Debug, Clone, Copy, PartialEq)]
|
||||
pub struct Placed {
|
||||
pub position: f64,
|
||||
pub clamped: bool,
|
||||
}
|
||||
|
||||
/// `want` (Anfang einer Öffnung der Breite `width` in Wand `host` mit Länge `len`) gegen die Nachbarn
|
||||
/// prüfen. Gleitet die Öffnung von `from` aus (gleiche Wand), hält sie vor dem ersten Nachbarn in
|
||||
/// Laufrichtung mit Steg [`MIN_WEB`] an; Nachbarn, mit denen sie schon bei `from` überlappt (Bestand),
|
||||
/// zählen nicht. Ohne `from` (neue Wand, Kopie) rückt sie an die nächste freie Stelle; `None`, wenn
|
||||
/// keine passt. `skip`: Öffnungen, die nicht zählen (die Öffnung selbst, mitbewegte).
|
||||
pub fn place(root: &Map<String, Value>, host: &str, len: f64, width: f64, from: Option<f64>, want: f64, skip: &dyn Fn(&str) -> bool) -> Option<Placed> {
|
||||
let max = len - width;
|
||||
if !(max > -EPS && want.is_finite()) {
|
||||
return None;
|
||||
}
|
||||
let max = max.max(0.0);
|
||||
let want = want.clamp(0.0, max);
|
||||
// Gesperrte Anfangslagen je Nachbar: offenes Intervall (lo, hi).
|
||||
let blocked: Vec<(f64, f64)> = neighbours(root, host, skip).into_iter().map(|(a, b)| (a - width - MIN_WEB, b + MIN_WEB)).collect();
|
||||
let inside = |x: f64, (lo, hi): (f64, f64)| x > lo + EPS && x < hi - EPS;
|
||||
if let Some(from) = from.filter(|f| f.is_finite()) {
|
||||
let ahead = blocked.iter().filter(|b| !inside(from, **b));
|
||||
let pos = if want > from {
|
||||
ahead.filter(|(lo, _)| *lo >= from - EPS).map(|(lo, _)| *lo).fold(want, f64::min)
|
||||
} else {
|
||||
ahead.filter(|(_, hi)| *hi <= from + EPS).map(|(_, hi)| *hi).fold(want, f64::max)
|
||||
};
|
||||
return Some(Placed { position: pos, clamped: (pos - want).abs() > EPS });
|
||||
}
|
||||
let free = |x: f64| x >= -EPS && x <= max + EPS && !blocked.iter().any(|b| inside(x, *b));
|
||||
std::iter::once(want)
|
||||
.chain(blocked.iter().flat_map(|(lo, hi)| [*lo, *hi]))
|
||||
.filter(|x| free(*x))
|
||||
.min_by(|a, b| (a - want).abs().total_cmp(&(b - want).abs()))
|
||||
.map(|x| Placed { position: x.clamp(0.0, max), clamped: (x - want).abs() > EPS })
|
||||
}
|
||||
|
||||
/// Öffnung `o` in ihrer Wand auf den Anfang `want` setzen (gleitend ab ihrer jetzigen Lage; geklemmt auf
|
||||
/// die Wand und vor den Nachbarn). `None`: Wirt fehlt oder die Öffnung passt nicht in die Wand.
|
||||
pub fn slide_to(root: &Map<String, Value>, o: &Value, want: f64) -> Option<Placed> {
|
||||
let host = field(o, "hostWallId").and_then(Value::as_str).filter(|h| !h.is_empty())?;
|
||||
let w = root.get("walls")?.as_array()?.iter().find(|w| id_of(w) == Some(host))?;
|
||||
let axis = Axis::of(w)?;
|
||||
let width = num_of(field(o, "width"));
|
||||
let from = num_of(field(o, "position"));
|
||||
let me = id_of(o).unwrap_or("");
|
||||
place(root, host, axis.len(), width, from.is_finite().then_some(from), want, &|id| id == me)
|
||||
}
|
||||
|
||||
/// Neuer Anfang, wenn der Mittelpunkt-Griff von `o` nach `pt` gezogen wird (Lotfuss auf die Achse,
|
||||
/// Bogenwand: nächster Punkt auf dem Bogen).
|
||||
pub fn grip_want(root: &Map<String, Value>, o: &Value, pt: P) -> Option<f64> {
|
||||
let host = field(o, "hostWallId").and_then(Value::as_str)?;
|
||||
let w = root.get("walls")?.as_array()?.iter().find(|w| id_of(w) == Some(host))?;
|
||||
let axis = Axis::of(w)?;
|
||||
let t = axis.local(pt).0 - num_of(field(o, "width")) / 2.0;
|
||||
t.is_finite().then_some(t)
|
||||
}
|
||||
|
||||
/// Punkt im Umriss lassen: ausserhalb → nächster Randpunkt, 5 cm nach innen gerückt (zum Schwerpunkt der
|
||||
/// Ecken). Wie `clampInside` (`src/plan/surfaceOpening.ts`, Griff-Zug der Dach-/Deckenöffnung).
|
||||
pub fn clamp_inside(p: P, ring: &[P]) -> P {
|
||||
if ring.len() < 3 {
|
||||
return p;
|
||||
}
|
||||
let mut inside = false;
|
||||
let mut j = ring.len() - 1;
|
||||
for i in 0..ring.len() {
|
||||
let (a, b) = (ring[i], ring[j]);
|
||||
if (a.1 > p.1) != (b.1 > p.1) && p.0 < (b.0 - a.0) * (p.1 - a.1) / (b.1 - a.1) + a.0 {
|
||||
inside = !inside;
|
||||
}
|
||||
j = i;
|
||||
}
|
||||
if inside {
|
||||
return p;
|
||||
}
|
||||
let mut best = ring[0];
|
||||
let mut best_d = f64::INFINITY;
|
||||
for i in 0..ring.len() {
|
||||
let (a, b) = (ring[i], ring[(i + 1) % ring.len()]);
|
||||
let (dx, dy) = (b.0 - a.0, b.1 - a.1);
|
||||
let l2 = dx * dx + dy * dy;
|
||||
let t = if l2 > 0.0 { (((p.0 - a.0) * dx + (p.1 - a.1) * dy) / l2).clamp(0.0, 1.0) } else { 0.0 };
|
||||
let q = (a.0 + dx * t, a.1 + dy * t);
|
||||
let dd = (q.0 - p.0).powi(2) + (q.1 - p.1).powi(2);
|
||||
if dd < best_d {
|
||||
best_d = dd;
|
||||
best = q;
|
||||
}
|
||||
}
|
||||
let n = ring.len() as f64;
|
||||
let (cx, cy) = (ring.iter().map(|q| q.0).sum::<f64>() / n, ring.iter().map(|q| q.1).sum::<f64>() / n);
|
||||
let l = crate::jsmath::hypot2(cx - best.0, cy - best.1);
|
||||
if l > 0.05 {
|
||||
(best.0 + (cx - best.0) / l * 0.05, best.1 + (cy - best.1) / l * 0.05)
|
||||
} else {
|
||||
best
|
||||
}
|
||||
}
|
||||
|
||||
#[cfg(test)]
|
||||
mod tests {
|
||||
use super::*;
|
||||
use serde_json::json;
|
||||
|
||||
fn root(v: Value) -> Map<String, Value> {
|
||||
v.as_object().unwrap().clone()
|
||||
}
|
||||
|
||||
fn near(a: f64, b: f64) {
|
||||
assert!((a - b).abs() < 1e-9, "{a} != {b}");
|
||||
}
|
||||
|
||||
/// Nachbar bei 2..3 in einer 10-m-Wand, Breite 1: gleitend hält die Öffnung mit 5 cm Steg an.
|
||||
#[test]
|
||||
fn haelt_vor_dem_nachbarn() {
|
||||
let r = root(json!({"walls":[{"id":"w","start":{"x":0,"y":0},"end":{"x":10,"y":0}}],
|
||||
"openings":[{"id":"a","hostWallId":"w","position":0,"width":1},{"id":"n","hostWallId":"w","position":2,"width":1},
|
||||
{"id":"x","hostWallId":"w","position":2.5,"width":1}]}));
|
||||
let skip_a = |id: &str| id == "a" || id == "x";
|
||||
let p = place(&r, "w", 10.0, 1.0, Some(0.0), 5.0, &skip_a).unwrap();
|
||||
near(p.position, 0.95);
|
||||
assert!(p.clamped);
|
||||
// Frei davor: kein Anschlag.
|
||||
let p = place(&r, "w", 10.0, 1.0, Some(0.0), 0.5, &skip_a).unwrap();
|
||||
assert_eq!(p, Placed { position: 0.5, clamped: false });
|
||||
// Von rechts kommend: hält bei 3.05.
|
||||
let p = place(&r, "w", 10.0, 1.0, Some(6.0), 0.0, &skip_a).unwrap();
|
||||
near(p.position, 3.05);
|
||||
// Bestand: „x" überlappt „n" schon — beim Wegziehen kein Anschlag an „n".
|
||||
let p = place(&r, "w", 10.0, 1.0, Some(2.5), 6.0, &|id| id == "x").unwrap();
|
||||
assert_eq!(p, Placed { position: 6.0, clamped: false });
|
||||
// Ohne Ausgang (Wandwechsel): nächste freie Stelle.
|
||||
let p = place(&r, "w", 10.0, 1.0, None, 2.2, &skip_a).unwrap();
|
||||
near(p.position, 3.05);
|
||||
let p = place(&r, "w", 10.0, 1.0, None, 1.5, &skip_a).unwrap();
|
||||
near(p.position, 0.95);
|
||||
// Kein Platz: 3.2-m-Wand, Breite 2.5, Nachbar bei 2..3.
|
||||
assert!(place(&r, "w", 3.2, 2.5, None, 0.0, &skip_a).is_none());
|
||||
}
|
||||
|
||||
/// Bogenwand: Lauflänge = Bogenlänge, Griff-Punkt auf dem Bogen, Klemmen am Bogenende.
|
||||
#[test]
|
||||
fn bogenwand_bogenlaenge() {
|
||||
// Halbkreis von (0,0) nach (4,0), bulge 1 → Radius 2, Länge 2π.
|
||||
let r = root(json!({"walls":[{"id":"b","start":{"x":0,"y":0},"end":{"x":4,"y":0},"bulge":1}],
|
||||
"openings":[{"id":"o","hostWallId":"b","position":1,"width":1}]}));
|
||||
let w = &r["walls"][0];
|
||||
let ax = Axis::of(w).unwrap();
|
||||
near(ax.len(), 2.0 * std::f64::consts::PI);
|
||||
let o = &r["openings"][0];
|
||||
// Scheitel (2, 2), Griff ausserhalb gezogen: Lotfuss auf dem Bogen.
|
||||
let m = ax.point(std::f64::consts::PI, 0.0);
|
||||
near(m.0, 2.0);
|
||||
near(m.1.abs(), 2.0);
|
||||
let want = grip_want(&r, o, (m.0, m.1 * 1.15)).unwrap();
|
||||
near(want, std::f64::consts::PI - 0.5);
|
||||
let p = slide_to(&r, o, 99.0).unwrap();
|
||||
near(p.position, 2.0 * std::f64::consts::PI - 1.0);
|
||||
assert_eq!(slide_to(&r, o, -3.0).unwrap().position, 0.0);
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn im_umriss_halten() {
|
||||
let ring = [(0.0, 0.0), (4.0, 0.0), (4.0, 4.0), (0.0, 4.0)];
|
||||
assert_eq!(clamp_inside((1.0, 1.0), &ring), (1.0, 1.0));
|
||||
let q = clamp_inside((6.0, 2.0), &ring);
|
||||
near(q.0, 3.95);
|
||||
near(q.1, 2.0);
|
||||
}
|
||||
}
|
||||
@@ -840,7 +840,7 @@ fn opening_selection(lk: &Lookup, o: &Value) -> Result<J, String> {
|
||||
.o("hostWallName", floor.map_or_else(|| field(o, "hostWallId").cloned(), |f| Some(Value::from(field(f, "name").map_or("undefined".into(), js_text)))))
|
||||
.raw("position", o, "position")
|
||||
// Länge der (geraden) Wirtswand ([144]): Objekt-Info rechnet „Abstand ab Wandende“ und klemmt.
|
||||
.o("wallLength", wall.and_then(straight_len).map(js_num))
|
||||
.o("wallLength", wall.and_then(axis_len).map(js_num))
|
||||
.raw("width", o, "width")
|
||||
.raw("height", o, "height")
|
||||
.raw("sillHeight", o, "sillHeight")
|
||||
@@ -873,13 +873,8 @@ fn opening_selection(lk: &Lookup, o: &Value) -> Result<J, String> {
|
||||
}
|
||||
|
||||
/// Achslänge einer geraden Wand; `None` bei Bogenwänden (dort ist `position` keine Sehnenlänge).
|
||||
fn straight_len(w: &Value) -> Option<f64> {
|
||||
if field(w, "bulge").and_then(Value::as_f64).is_some_and(|b| b.abs() > 1e-12) {
|
||||
return None;
|
||||
}
|
||||
let (s, e) = (xy(field(w, "start")?), xy(field(w, "end")?));
|
||||
let len = crate::jsmath::hypot2(e.0 - s.0, e.1 - s.1);
|
||||
len.is_finite().then_some(len)
|
||||
fn axis_len(w: &Value) -> Option<f64> {
|
||||
crate::opening_slide::Axis::of(w).map(|a| a.len()).filter(|l| l.is_finite())
|
||||
}
|
||||
|
||||
/// Achsversatz der Schichtstapelung (`wallReferenceOffset`): freier Versatz (auf die Dicke geklemmt),
|
||||
@@ -1380,12 +1375,14 @@ mod tests {
|
||||
// Unbekannter Wandtyp: dieselbe Meldung wie TS.
|
||||
let mut bad = r.clone();
|
||||
bad["walls"][0]["wallTypeId"] = json!("x");
|
||||
assert_eq!(sel(&bad, json!({"wallIds": ["w"]})).unwrap_err(), "Unbekannter Wandtyp: x"); // [144] Öffnung: Länge der Wirtswand für „Abstand ab Wandende“ (Bogenwand: keine).
|
||||
assert_eq!(sel(&bad, json!({"wallIds": ["w"]})).unwrap_err(), "Unbekannter Wandtyp: x"); // [144] Öffnung: Länge der Wirtswand für „Abstand ab Wandende“ (Bogenwand: Bogenlänge).
|
||||
let o = sel(&r, json!({"openingId": "o"})).unwrap();
|
||||
assert_eq!(o["opening"]["wallLength"], json!(5));
|
||||
let mut arc = r.clone();
|
||||
arc["walls"][0]["bulge"] = json!(0.4);
|
||||
assert!(sel(&arc, json!({"openingId": "o"})).unwrap()["opening"].get("wallLength").is_none());
|
||||
let len = sel(&arc, json!({"openingId": "o"})).unwrap()["opening"]["wallLength"].as_f64().unwrap();
|
||||
let a = crate::wall_arc::WallArc::of(kernel2d::Vec2::new(0.0, 0.0), kernel2d::Vec2::new(4.0, 3.0), Some(0.4)).unwrap();
|
||||
assert!(len > 5.0 && (len - a.length()).abs() < 1e-9, "{len}");
|
||||
}
|
||||
|
||||
#[test]
|
||||
|
||||
@@ -13,11 +13,10 @@ pub fn doc_cmd_commit(h: u32, req_json: &str, key: &str, now_ms: f64) -> String
|
||||
let key = (!key.is_empty()).then_some(key);
|
||||
let now = if now_ms.is_finite() { now_ms } else { 0.0 };
|
||||
let out = with_doc(h, |d| -> Result<String, String> {
|
||||
let ops = {
|
||||
let res = {
|
||||
let (p, lk) = d.project_lookup()?;
|
||||
crate::commands::ops(lk.root, p, req_json)?
|
||||
crate::commands::result(lk.root, p, req_json)?
|
||||
};
|
||||
let res = crate::grips::GripResult { ops, notice: None };
|
||||
let text = crate::grips::result_json(&res);
|
||||
if res.ops.is_empty() {
|
||||
return Ok(text);
|
||||
|
||||
@@ -89,17 +89,12 @@ pub fn grip_sheet_height(kind: u32, base: f64, top: f64, bottom: f64, y: f64, fr
|
||||
|
||||
/// Mittelpunkt-Griff einer Öffnung auf der Wandachse `s → e`: `[x, y]`.
|
||||
#[wasm_bindgen]
|
||||
pub fn grip_opening_point(sx: f64, sy: f64, ex: f64, ey: f64, position: f64, width: f64) -> Vec<f64> {
|
||||
let p = gd::opening_wall_grip((sx, sy), (ex, ey), position, width);
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub fn grip_opening_point(sx: f64, sy: f64, ex: f64, ey: f64, bulge: f64, position: f64, width: f64) -> Vec<f64> {
|
||||
let p = gd::opening_wall_grip((sx, sy), (ex, ey), bulge, position, width);
|
||||
vec![p.0, p.1]
|
||||
}
|
||||
|
||||
/// Neue Öffnungs-`position` beim Ziehen des Mittelpunkt-Griffs nach `(px, py)`: `[position]`, `[]` = Wand ohne Länge.
|
||||
#[wasm_bindgen]
|
||||
pub fn grip_opening_slide(sx: f64, sy: f64, ex: f64, ey: f64, width: f64, px: f64, py: f64) -> Vec<f64> {
|
||||
gd::opening_slide((sx, sy), (ex, ey), width, (px, py)).map(|p| vec![p]).unwrap_or_default()
|
||||
}
|
||||
|
||||
/// Öffnung im Schnitt-Blatt (`grip_drag::opening_slide_sheet`): `[position, wirksames du]`, `[]` = keine Bewegung.
|
||||
#[wasm_bindgen]
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
|
||||
@@ -1028,6 +1028,7 @@ export default function App() {
|
||||
updateWall,
|
||||
setWallThickness,
|
||||
updateOpening,
|
||||
slideOpening,
|
||||
moveCeilingGrip,
|
||||
moveExcavationGrip,
|
||||
moveExcavationEdge,
|
||||
@@ -1132,6 +1133,7 @@ export default function App() {
|
||||
engineRef,
|
||||
commandLineRef,
|
||||
updateOpening,
|
||||
slideOpening,
|
||||
updateWall,
|
||||
moveStairBy,
|
||||
moveRoomGrip,
|
||||
@@ -1973,6 +1975,7 @@ export default function App() {
|
||||
updateWall,
|
||||
setWallThickness,
|
||||
updateOpening,
|
||||
slideOpening,
|
||||
updateCeiling,
|
||||
setCeilingThickness,
|
||||
updateStair,
|
||||
|
||||
@@ -157,11 +157,16 @@ describe("Transformations-Befehle", () => {
|
||||
expect(engine.isActive()).toBe(false);
|
||||
expect(door().position).toBeCloseTo(1.3, 9);
|
||||
expect(door().hostWallId).toBe("W1");
|
||||
// Relative Koordinate quer zur Wand: nur der Anteil längs zählt; am Wandende geklemmt.
|
||||
// Relative Koordinate quer zur Wand: nur der Anteil längs zählt; 5 cm vor dem Fenster O1 (3.0–4.0)
|
||||
// angehalten ([144] Überlappung), zurück am Wandanfang geklemmt.
|
||||
engine.start("move");
|
||||
engine.pick({ x: 0, y: 0 });
|
||||
engine.submitText("@9,0.05");
|
||||
expect(door().position).toBeCloseTo(5 - 0.9, 9);
|
||||
expect(door().position).toBeCloseTo(3 - 0.05 - 0.9, 9);
|
||||
engine.start("move");
|
||||
engine.pick({ x: 0, y: 0 });
|
||||
engine.submitText("@-9,0");
|
||||
expect(door().position).toBe(0);
|
||||
for (const op of ["rotate", "mirror"]) {
|
||||
expect(engine.start(op)).toBe(false);
|
||||
}
|
||||
|
||||
@@ -458,20 +458,21 @@ export class ProjectDocument {
|
||||
/**
|
||||
* Befehl rechnen und anwenden ([K4] S3, `doc_cmd_commit`): wie {@link commitGrip} — ein Kern-Aufruf
|
||||
* statt Ops hin (Rechnung) und zurück (Commit). Ergebnis: neues Projekt und die angewendeten Ops (leer
|
||||
* = nichts zu tun, dann `project === base`) oder die Meldungen der Prüfung.
|
||||
* = nichts zu tun, dann `project === base`), ein Hinweis-Schlüssel (i18n, z. B. [144] Öffnung an der
|
||||
* Nachbaröffnung angehalten) oder die Meldungen der Prüfung.
|
||||
*/
|
||||
commitCmd(base: Project, req: object, coalesceKey: string | undefined, now: number): { project: Project; ops: CoreOp[] } | { problems: string[] } {
|
||||
commitCmd(base: Project, req: object, coalesceKey: string | undefined, now: number): { project: Project; ops: CoreOp[]; notice?: string } | { problems: string[] } {
|
||||
this.ensure(base);
|
||||
if (!this.handle) return { problems: ["Projekt-Dokument im Kern nicht offen."] };
|
||||
const out = core().doc_cmd_commit(this.handle, toMarkedJson(req), coalesceKey ?? "", now);
|
||||
if (out.startsWith("\u0001")) throw new Error(out.slice(1));
|
||||
const r = fromMarkedJson<{ ops: CoreOp[] } | { problems: string[] }>(out);
|
||||
const r = fromMarkedJson<{ ops: CoreOp[]; notice?: string } | { problems: string[] }>(out);
|
||||
if ("problems" in r) return r;
|
||||
if (r.ops.length === 0) return { project: base, ops: r.ops };
|
||||
if (r.ops.length === 0) return { project: base, ops: r.ops, notice: r.notice };
|
||||
const extra = this.lastExtra();
|
||||
const project = this.withExtra(applyOps(base, r.ops), extra);
|
||||
this.setMirror(project);
|
||||
return { project, ops: extra.length ? [...r.ops, ...extra] : r.ops };
|
||||
return { project, ops: extra.length ? [...r.ops, ...extra] : r.ops, notice: r.notice };
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
+1
-1
@@ -72,7 +72,7 @@ export { drawingVertices, gripPt, openEdges, polylineEdgeGrips, ringEdges } from
|
||||
export { verticalExtents } from "../geometry/grips";
|
||||
export type { VerticalExtent } from "../geometry/grips";
|
||||
export type { GripRequest } from "../geometry/grips";
|
||||
export { coincidentGripPoints, excavationGripPoints, gripAxisLock, gripEdgeTarget, gripPolar, gripPolarPoint, openingGripPoint, openingSheetSlide, openingSlidePosition, sheetHeightDrag, stairMoveHandle, wallGripPoints } from "../geometry/gripDrag";
|
||||
export { coincidentGripPoints, excavationGripPoints, gripAxisLock, gripEdgeTarget, gripPolar, gripPolarPoint, openingGripPoint, openingSheetSlide, sheetHeightDrag, stairMoveHandle, wallGripPoints } from "../geometry/gripDrag";
|
||||
export type { EdgeDrive, GripLocks, SheetHeightKind } from "../geometry/gripDrag";
|
||||
export { openingPreviewProject, openingPreviewSvgs } from "../plan/openingPreview";
|
||||
export type { OpeningPreviewSvgs } from "../plan/openingPreview";
|
||||
|
||||
@@ -9,7 +9,6 @@ import {
|
||||
gripPolarPoint,
|
||||
openingGripPoint,
|
||||
openingSheetSlide,
|
||||
openingSlidePosition,
|
||||
sheetHeightDrag,
|
||||
wallGripPoints,
|
||||
} from "./gripDrag";
|
||||
@@ -49,8 +48,10 @@ describe("Griff-Zug (Kern)", () => {
|
||||
|
||||
it("Öffnung entlang der Wand und im Schnitt", () => {
|
||||
expect(openingGripPoint(wall, { position: 1, width: 1.2 })).toEqual({ x: 1.6, y: 0 });
|
||||
expect(openingSlidePosition(wall, { width: 1.2 }, { x: 2.6, y: 3 })).toBe(2);
|
||||
expect(openingSlidePosition({ start: wall.start, end: wall.start }, { width: 1.2 }, { x: 1, y: 0 })).toBeNull();
|
||||
// Bogenwand (Halbkreis, Radius 2.5): Mitte bei der Bogenlänge 2.5·π/2 liegt im Scheitel.
|
||||
const g = openingGripPoint({ ...wall, bulge: 1 }, { position: 2.5 * Math.PI / 2 - 0.6, width: 1.2 });
|
||||
expect(g.x).toBeCloseTo(2.5, 9);
|
||||
expect(Math.abs(g.y)).toBeCloseTo(2.5, 9);
|
||||
expect(openingSheetSlide(wall, { position: 1, width: 1.2 }, { x: -1, y: 0 }, 0.5)).toEqual({ position: 0.5, du: 0.5 });
|
||||
expect(openingSheetSlide(wall, { position: 1, width: 1.2 }, { x: 0.1, y: 0.995 }, 1)).toBeNull();
|
||||
});
|
||||
|
||||
@@ -96,15 +96,12 @@ export function sheetHeightDrag(
|
||||
return { top: f[0], bottom: f[1], patch };
|
||||
}
|
||||
|
||||
/** Mittelpunkt-Griff einer Öffnung auf der Achse ihrer Wirtswand. */
|
||||
export function openingGripPoint(w: Pick<Wall, "start" | "end">, op: Pick<Opening, "position" | "width">): Vec2 {
|
||||
return v(core().grip_opening_point(w.start.x, w.start.y, w.end.x, w.end.y, op.position, op.width));
|
||||
}
|
||||
|
||||
/** Neue `position` beim Ziehen des Öffnungs-Griffs nach `pt` (auf die Wand geklemmt); null = Wand ohne Länge. */
|
||||
export function openingSlidePosition(w: Pick<Wall, "start" | "end">, op: Pick<Opening, "width">, pt: Vec2): number | null {
|
||||
const f = core().grip_opening_slide(w.start.x, w.start.y, w.end.x, w.end.y, op.width, pt.x, pt.y);
|
||||
return f.length ? f[0] : null;
|
||||
/**
|
||||
* Mittelpunkt-Griff einer Öffnung auf der Achse ihrer Wirtswand (Bogenwand [T2]: auf dem Bogen, `position`
|
||||
* = Bogenlänge). Den Zug selbst rechnet der Kern (`slideOpening`, Griff-Anfrage `openingSlide`).
|
||||
*/
|
||||
export function openingGripPoint(w: Pick<Wall, "start" | "end" | "bulge">, op: Pick<Opening, "position" | "width">): Vec2 {
|
||||
return v(core().grip_opening_point(w.start.x, w.start.y, w.end.x, w.end.y, w.bulge ?? 0, op.position, op.width));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -31,7 +31,10 @@ export type GripRequest =
|
||||
| { op: "insertPoint"; id: string; seg: number; pt: P }
|
||||
| { op: "deletePoint"; id: string; index: number }
|
||||
| { op: "vertexType"; id: string; index: number; vertexType: "corner" | "arc" | "spline" }
|
||||
| { op: "wallThickness" | "ceilingThickness"; id: string; thickness: number; newId: string; newName: string };
|
||||
| { op: "wallThickness" | "ceilingThickness"; id: string; thickness: number; newId: string; newName: string }
|
||||
// [144] Wandöffnung gleiten lassen (Kern `opening_slide`): Griff-Zug nach `pt` bzw. Position `a` ab Wandanfang.
|
||||
| { op: "openingSlide"; id: string; pt: P }
|
||||
| { op: "openingPosition"; id: string; a: number };
|
||||
|
||||
/** Punkt als Anfrage-Paar. */
|
||||
export const gripPt = (p: Vec2): P => [p.x, p.y];
|
||||
|
||||
@@ -801,6 +801,8 @@ export const de = {
|
||||
"objinfo.opening.slope": "Neigung der Fläche",
|
||||
"objinfo.opening.position": "Position (ab Wandanfang)",
|
||||
"objinfo.opening.positionEnd": "Abstand ab Wandende",
|
||||
"opening.overlapClamped": "Öffnung hält vor der Nachbaröffnung an (Steg 5 cm).",
|
||||
"opening.noRoom": "In der Zielwand ist kein Platz für die Öffnung.",
|
||||
"objinfo.opening.width": "Breite",
|
||||
"objinfo.opening.height": "Höhe",
|
||||
"objinfo.opening.sill": "Brüstung",
|
||||
|
||||
@@ -800,6 +800,8 @@ export const en: Record<TranslationKey, string> = {
|
||||
"objinfo.opening.slope": "Surface slope",
|
||||
"objinfo.opening.position": "Position (from wall start)",
|
||||
"objinfo.opening.positionEnd": "Distance from wall end",
|
||||
"opening.overlapClamped": "Opening stops at the neighbouring opening (5 cm web).",
|
||||
"opening.noRoom": "No room for the opening in the target wall.",
|
||||
"objinfo.opening.width": "Width",
|
||||
"objinfo.opening.height": "Height",
|
||||
"objinfo.opening.sill": "Sill height",
|
||||
|
||||
@@ -403,6 +403,12 @@ export interface ProjectSlice {
|
||||
id: string,
|
||||
patch: Partial<import("../model/types").Opening>,
|
||||
) => void;
|
||||
/**
|
||||
* [144] Wandöffnung in ihrer Wand verschieben (Kern `opening_slide`): auf `position` (ab Wandanfang,
|
||||
* Bogenwand: Bogenlänge) bzw. zum Griff-Punkt `pt`; geklemmt auf die Wand und 5 cm vor der Nachbar-
|
||||
* öffnung (mit Hinweis). `coalesceKey` fasst einen Griff-Zug zu einem Undo-Schritt.
|
||||
*/
|
||||
slideOpening: (id: string, to: { position: number } | { pt: Vec2 }, coalesceKey?: string) => void;
|
||||
|
||||
/**
|
||||
* Immutable Änderung eines Dachs (Form/Neigung/Überstand/Firstrichtung/
|
||||
@@ -522,7 +528,8 @@ export function createProjectSlice(
|
||||
|
||||
// Befehl ([K4] S3, `commands.rs`): der Kern rechnet ihn auf dem Dokument und wendet ihn im selben
|
||||
// Aufruf an (`cmdMutation`); Prüfung, Verlauf und Meldungen wie `commitOps`.
|
||||
const applyCmd = (req: object, coalesceKey?: string) =>
|
||||
const applyCmd = (req: object, coalesceKey?: string) => {
|
||||
let notice: string | undefined;
|
||||
set((s) => {
|
||||
const doc = storeDocument(s.project);
|
||||
const cmd = (req as { cmd?: unknown }).cmd;
|
||||
@@ -535,11 +542,14 @@ export function createProjectSlice(
|
||||
queueMicrotask(() => get().notify(`${t("project.change.rejected")} ${problems[0]}`, "error"));
|
||||
return {};
|
||||
}
|
||||
notice = res.notice;
|
||||
if (res.ops.length === 0) return {};
|
||||
opLog.push(res.ops);
|
||||
if (opLog.length > OP_LOG_LIMIT) opLog.shift();
|
||||
return { project: res.project, ...historyPatch(doc) };
|
||||
});
|
||||
noticeOnce(notice);
|
||||
};
|
||||
|
||||
// Änderung direkt als Ops (ohne Differenz), s. `ProjectSlice.applyChange`.
|
||||
const applyChange = (
|
||||
@@ -547,6 +557,16 @@ export function createProjectSlice(
|
||||
coalesceKey?: string,
|
||||
) => set((s) => commitOps(s, typeof ops === "function" ? ops(s.project) : ops, coalesceKey));
|
||||
|
||||
// Hinweis aus dem Kern (i18n-Schlüssel) melden — derselbe höchstens alle 2 s (Griff-Zug: je Mausschritt).
|
||||
let lastNotice = { key: "", at: 0 };
|
||||
const noticeOnce = (notice: string | undefined) => {
|
||||
if (!notice) return;
|
||||
const now = Date.now();
|
||||
if (notice === lastNotice.key && now - lastNotice.at < 2000) return;
|
||||
lastNotice = { key: notice, at: now };
|
||||
get().notify(t(notice as Parameters<typeof t>[0]), "warning");
|
||||
};
|
||||
|
||||
// Griff-Änderung ([K4] S3): der Kern rechnet sie auf dem Dokument und wendet sie im selben Aufruf an
|
||||
// (`grips.rs`, ein WASM-Aufruf je Mausschritt); Prüfung, Verlauf und Meldungen wie `commitOps`.
|
||||
const applyGrip = (req: GripRequest, coalesceKey?: string) => {
|
||||
@@ -566,7 +586,7 @@ export function createProjectSlice(
|
||||
if (opLog.length > OP_LOG_LIMIT) opLog.shift();
|
||||
return { project: res.project, ...historyPatch(doc) };
|
||||
});
|
||||
if (notice) get().notify(t(notice as Parameters<typeof t>[0]), "warning");
|
||||
noticeOnce(notice);
|
||||
};
|
||||
|
||||
return {
|
||||
@@ -1239,6 +1259,8 @@ export function createProjectSlice(
|
||||
|
||||
// ── Öffnungs-Editieren ────────────────────────────────────────────────
|
||||
updateOpening: (id, patch) => applyChange((p) => patchItem(p, "openings", id, patch)),
|
||||
slideOpening: (id, to, coalesceKey) =>
|
||||
applyGrip("pt" in to ? { op: "openingSlide", id, pt: gripPt(to.pt) } : { op: "openingPosition", id, a: to.position }, coalesceKey),
|
||||
|
||||
// ── Dach-Editieren ─────────────────────────────────────────────────────
|
||||
updateRoof: (id, patch, coalesceKey) => applyChange((p) => patchItem(p, "roofs", id, patch), coalesceKey),
|
||||
|
||||
@@ -26,6 +26,10 @@ declare global {
|
||||
openings: () => { id: string; hostWallId: string; position: number }[];
|
||||
/** [144] Auswahl setzen (wie ein Klick), z. B. `{ openings: ["D1"] }`. */
|
||||
select: (patch: Record<string, string[]>) => void;
|
||||
/** [144] Punkte einer Bemassung (Kette) — folgt sie der Öffnung? */
|
||||
dimPts: (id: string) => { x: number; y: number }[];
|
||||
/** [144] Texte der Hinweise (Benachrichtigungen). */
|
||||
notices: () => string[];
|
||||
};
|
||||
}
|
||||
}
|
||||
@@ -52,6 +56,11 @@ export function installTestHooks(): void {
|
||||
getState().project.drawings2d.flatMap((d) => (d.id.startsWith(prefix) && d.geom.shape === "polyline" ? [{ id: d.id, pts: d.geom.pts }] : [])),
|
||||
openings: () => (getState().project.openings ?? []).map((o) => ({ id: o.id, hostWallId: o.hostWallId, position: o.position })),
|
||||
select: (patch) => getState().setSelection(patch),
|
||||
dimPts: (id) => {
|
||||
const g = getState().project.drawings2d.find((d) => d.id === id)?.geom;
|
||||
return g?.shape === "dimension" ? g.pts.map((p) => ({ x: p.x, y: p.y })) : [];
|
||||
},
|
||||
notices: () => getState().notifications.map((n) => n.message),
|
||||
selected: () => ({ drawings: [...getState().selection.drawings], groups: [...getState().selection.groups], all: JSON.stringify(getState().selection) }),
|
||||
};
|
||||
}
|
||||
@@ -22,7 +22,6 @@ import {
|
||||
gripPolarPoint,
|
||||
openingGripPoint,
|
||||
openingSheetSlide,
|
||||
openingSlidePosition,
|
||||
sheetHeightDrag,
|
||||
stairMoveHandle,
|
||||
wallGripPoints,
|
||||
@@ -93,6 +92,8 @@ export function useGripEditing(opts: {
|
||||
engineRef: RefObject<CommandEngine | null>;
|
||||
commandLineRef: RefObject<CommandLineHandle | null>;
|
||||
updateOpening: (id: string, patch: Record<string, unknown>) => void;
|
||||
/** [144] Wandöffnung gleiten lassen (Kern: Wand, Bogenwand, Nachbaröffnungen). */
|
||||
slideOpening: (id: string, to: { position: number } | { pt: Vec2 }, coalesceKey?: string) => void;
|
||||
/** Wand ändern (Höhen-Griff im Schnitt); `coalesceKey` fasst einen Zug zu EINEM Undo-Schritt. */
|
||||
updateWall: (id: string, patch: Partial<import("../model/types").Wall>, coalesceKey?: string) => void;
|
||||
moveStairBy: (id: string, delta: Vec2) => void;
|
||||
@@ -143,6 +144,7 @@ export function useGripEditing(opts: {
|
||||
engineRef,
|
||||
commandLineRef,
|
||||
updateOpening,
|
||||
slideOpening,
|
||||
updateWall,
|
||||
moveStairBy,
|
||||
moveRoomGrip,
|
||||
@@ -385,9 +387,12 @@ export function useGripEditing(opts: {
|
||||
if (!selectedOpeningId) return null;
|
||||
const op = (project.openings ?? []).find((o) => o.id === selectedOpeningId);
|
||||
const w = op && !op.hostRoofId && !op.hostCeilingId ? project.walls.find((x) => x.id === op.hostWallId) : undefined;
|
||||
if (!w) return null;
|
||||
const dx = w.end.x - w.start.x;
|
||||
const dy = w.end.y - w.start.y;
|
||||
if (!w || !op) return null;
|
||||
// Sehne über die Öffnung (gerade Wand: Wandrichtung; Bogenwand: ≈ Tangente in der Öffnungsmitte).
|
||||
const a = openingGripPoint(w, { position: op.position - op.width / 2, width: op.width });
|
||||
const b = openingGripPoint(w, { position: op.position + op.width / 2, width: op.width });
|
||||
const dx = b.x - a.x;
|
||||
const dy = b.y - a.y;
|
||||
const len = Math.hypot(dx, dy);
|
||||
return len > 1e-9 ? { x: dx / len, y: dy / len } : null;
|
||||
};
|
||||
@@ -796,9 +801,9 @@ export function useGripEditing(opts: {
|
||||
if (patch) updateOpening(op.id, patch);
|
||||
return;
|
||||
}
|
||||
const w = op && project.walls.find((x) => x.id === op.hostWallId);
|
||||
const pos = op && w ? openingSlidePosition(w, op, pt) : null;
|
||||
if (op && pos != null) updateOpening(op.id, { position: pos });
|
||||
// Wandöffnung ([144]): der Kern projiziert auf die Achse (Bogenwand: auf den Bogen), klemmt auf
|
||||
// die Wand und hält vor der Nachbaröffnung an.
|
||||
if (op && !op.locked) slideOpening(op.id, { pt }, `slideOpening:${op.id}`);
|
||||
return;
|
||||
}
|
||||
// Treppe: den Bewegpunkt verfolgen → ganze Treppe um das Delta (Ziel −
|
||||
@@ -959,7 +964,7 @@ export function useGripEditing(opts: {
|
||||
}
|
||||
const pom = pendingOpeningMoveRef.current;
|
||||
pendingOpeningMoveRef.current = null;
|
||||
if (pom) updateOpening(pom.id, { position: pom.position });
|
||||
if (pom) slideOpening(pom.id, { position: pom.position });
|
||||
const pa = pendingAreaMoveRef.current;
|
||||
pendingAreaMoveRef.current = null;
|
||||
if (pa && (pa.total.x !== 0 || pa.total.y !== 0)) {
|
||||
|
||||
@@ -209,6 +209,7 @@ export function usePanelHostBase(opts: {
|
||||
| "updateWall"
|
||||
| "setWallThickness"
|
||||
| "updateOpening"
|
||||
| "slideOpening"
|
||||
| "updateCeiling"
|
||||
| "setCeilingThickness"
|
||||
| "updateStair"
|
||||
@@ -324,6 +325,7 @@ export function usePanelHostBase(opts: {
|
||||
updateWall,
|
||||
setWallThickness,
|
||||
updateOpening,
|
||||
slideOpening,
|
||||
updateCeiling,
|
||||
setCeilingThickness,
|
||||
updateStair,
|
||||
@@ -952,10 +954,10 @@ export function usePanelHostBase(opts: {
|
||||
},
|
||||
onSetOpeningPosition: (position) => {
|
||||
if (selection?.kind !== "opening" || !Number.isFinite(position)) return;
|
||||
// [144] In der Wand halten: auf [0, Wandlänge − Breite] klemmen (Bogenwand: nur ≥ 0).
|
||||
const o = selection.opening;
|
||||
const max = o?.wallLength != null ? Math.max(0, o.wallLength - o.width) : Infinity;
|
||||
updateOpening(selection.id, { position: Math.min(max, Math.max(0, position)) });
|
||||
// [144] Dach-/Deckenöffnung: Feld frei; Wandöffnung: der Kern klemmt auf [0, Wandlänge − Breite]
|
||||
// (Bogenwand: Bogenlänge) und hält 5 cm vor der Nachbaröffnung an (mit Hinweis).
|
||||
if (selection.opening?.wallLength == null) updateOpening(selection.id, { position: Math.max(0, position) });
|
||||
else slideOpening(selection.id, { position });
|
||||
},
|
||||
onSetOpeningSwingAngle: (swingAngle) => {
|
||||
if (selection?.kind === "opening" && swingAngle > 0)
|
||||
|
||||
@@ -372,6 +372,7 @@ export function useProjectActions(
|
||||
const updateWall = useStore((s) => s.updateWall);
|
||||
const setWallThickness = useStore((s) => s.setWallThickness);
|
||||
const updateOpening = useStore((s) => s.updateOpening);
|
||||
const slideOpening = useStore((s) => s.slideOpening);
|
||||
const moveCeilingGrip = useStore((s) => s.moveCeilingGrip);
|
||||
const moveExcavationGrip = useStore((s) => s.moveExcavationGrip);
|
||||
const moveExcavationEdge = useStore((s) => s.moveExcavationEdge);
|
||||
@@ -490,6 +491,7 @@ export function useProjectActions(
|
||||
updateWall,
|
||||
setWallThickness,
|
||||
updateOpening,
|
||||
slideOpening,
|
||||
moveCeilingGrip,
|
||||
moveExcavationGrip,
|
||||
moveExcavationEdge,
|
||||
|
||||
@@ -3,6 +3,7 @@
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { buildComplexSampleProject } from "../model/sampleProjectComplex";
|
||||
import { transformMutation } from "./transform";
|
||||
import { getState } from "../state/appStore";
|
||||
|
||||
describe("Öffnungen verschieben (Musterhaus komplex)", () => {
|
||||
it("jede Wandöffnung gleitet entlang ihrer Wand", () => {
|
||||
@@ -26,3 +27,55 @@ describe("Öffnungen verschieben (Musterhaus komplex)", () => {
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
// [144] Store-Fluss: Befehl (cmdMutation), Objekt-Info/Griff (`slideOpening`) — Bemassung folgt, Bogenwand,
|
||||
// Nachbaröffnung mit Hinweis, Dachöffnung allein.
|
||||
describe("Öffnungen verschieben (Store, Musterhaus komplex)", () => {
|
||||
const load = () => getState().loadProject(buildComplexSampleProject());
|
||||
const opening = (id: string) => getState().project.openings!.find((o) => o.id === id)!;
|
||||
const dimPts = () => (getState().project.drawings2d.find((d) => d.id === "mass-fenster-eg")!.geom as { pts: { x: number }[] }).pts;
|
||||
|
||||
it("Bemassung auf die Leibungen folgt Befehl und Objekt-Info", () => {
|
||||
load();
|
||||
const x0 = dimPts()[0].x;
|
||||
getState().setProject(transformMutation({ wallIds: [], drawingId: null, openingIds: ["eg-f1"] }, "move", [{ x: 0, y: 0 }, { x: 0.5, y: 0 }], "move", 1));
|
||||
expect(opening("eg-f1").position).toBeCloseTo(2.1, 9);
|
||||
expect(dimPts()[0].x).toBeCloseTo(x0 + 0.5, 9);
|
||||
expect(dimPts()[1].x).toBeCloseTo(x0 + 0.5 + opening("eg-f1").width, 9);
|
||||
getState().slideOpening("eg-f1", { position: 1 });
|
||||
expect(dimPts()[0].x).toBeCloseTo(x0 - 0.6, 9);
|
||||
getState().undo();
|
||||
expect(dimPts()[0].x).toBeCloseTo(x0 + 0.5, 9);
|
||||
});
|
||||
|
||||
it("Bogenwand: Lage = Bogenlänge, Anschlag an der Nachbaröffnung mit Hinweis", () => {
|
||||
load();
|
||||
const before = getState().notifications.length;
|
||||
// Erker EG (Halbkreis r = 2): f5 bei 1.2 (1 m breit), f6 bei 3.6 — f5 hält bei 3.6 − 0.05 − 1 = 2.55.
|
||||
getState().slideOpening("eg-f5", { position: 3 });
|
||||
expect(opening("eg-f5").position).toBeCloseTo(2.55, 9);
|
||||
expect(getState().notifications.length).toBe(before + 1);
|
||||
expect(getState().notifications.at(-1)?.kind).toBe("warning");
|
||||
getState().undo();
|
||||
expect(opening("eg-f5").position).toBe(1.2);
|
||||
// Griff-Zug ausserhalb des Scheitels (17, 5): Mitte auf der halben Bogenlänge π.
|
||||
getState().slideOpening("eg-f6", { pt: { x: 17.4, y: 5 } });
|
||||
expect(opening("eg-f6").position).toBeCloseTo(Math.PI - 0.5, 9);
|
||||
// Weiter zum Anfang: f5 endet bei 2.2 → Anschlag bei 2.25.
|
||||
getState().slideOpening("eg-f6", { pt: { x: 15, y: 3 } });
|
||||
expect(opening("eg-f6").position).toBeCloseTo(2.25, 9);
|
||||
// Befehl: f6 übers Bogenende hinaus → Bogenlänge 2π − Breite, gleiche Wand.
|
||||
getState().setProject(transformMutation({ wallIds: [], drawingId: null, openingIds: ["eg-f6"] }, "move", [{ x: 17, y: 5 }, { x: 13, y: 9 }], "move", 1));
|
||||
expect(opening("eg-f6").position).toBeCloseTo(2 * Math.PI - 1, 9);
|
||||
expect(opening("eg-f6").hostWallId).toBe("eg-aw-erker");
|
||||
});
|
||||
|
||||
it("Dach-/Deckenöffnung allein verschieben", () => {
|
||||
load();
|
||||
const o = (getState().project.openings ?? []).find((x) => (x.hostRoofId || x.hostCeilingId) && !x.locked);
|
||||
expect(o).toBeDefined();
|
||||
const hp = o!.hostPoint!;
|
||||
getState().setProject(transformMutation({ wallIds: [], drawingId: null, openingIds: [o!.id] }, "move", [{ x: 0, y: 0 }, { x: 0.3, y: 0 }], "move", 1));
|
||||
expect(opening(o!.id).hostPoint!.x).toBeCloseTo(hp.x + 0.3, 9);
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user