[176] Geknickter Schnitt: Abwicklung je Segment, Knicklinien, Werkzeug und Griffe für Knickpunkte
Kern plan/section/unfold.rs: jedes Segment schneidet mit eigener Ebene, Schnittflächen auf den u-Bereich, Projektion an den Winkelhalbierenden zugeschnitten, Teilbilder lückenlos (u = abgewickelte Länge), dünne Knicklinie je Knick; Öffnungen/Achsen/Bäume je Segment. Ohne bendPoints unverändert. Schnittlinien-Befehl: weitere Klicks = Knicke, Enter/Doppelklick beendet (Ansicht weiter zwei Klicks). Griffe: Anfang, Knicke, Ende (grips.rs sectionLineGrip).
This commit is contained in:
18 files changed
+748
-39
No files matched your search
@@ -132,8 +132,13 @@ Wer zu einer ID mehr wissen will (Entscheide, Tests, Bilder), sucht dort nach `*
|
||||
Rest (10.11.): Ansichtsmarker als eigenes Symbol (Kreis Ø 8 mm, 0.25 mm, gefülltes Dreieck in Blickrichtung, Bezeichnung
|
||||
im Kreis, `misc.rs` `view_marker_sized`, keine Linie mehr); Modell `DrawingLevel.bendPoints` (optional, Knickpunkte zwischen
|
||||
`linePoints[0]`/`[1]`, altes 2-Punkt-Format liest weiter, verschiebt mit Georeferenz) und Darstellung im Grundriss
|
||||
(`section_polyline_sized`: kräftige 6-mm-Stücke an jedem Knick). Offen: Schnitt-Abwicklung geknickter Schnitte (Ableitung
|
||||
folgt noch der Endpunkt-Verbindung), Werkzeug/Griffe für Knickpunkte, optionale dünne Ansichtsebene, Mac-/Tauri-Ansicht. · M
|
||||
(`section_polyline_sized`: kräftige 6-mm-Stücke an jedem Knick). Geknickter Schnitt fertig (10.11.): Abwicklung im Kern
|
||||
(`plan/section/unfold.rs`): je Segment eigene Ebene, Schnittflächen auf den u-Bereich, Projektion an den Winkelhalbierenden
|
||||
der Knicke zugeschnitten, Teilbilder aneinander (u = abgewickelte Länge), dünne Knicklinie (0.13 mm) je Knick; Öffnungen,
|
||||
Achsen je Segment geschnitten, Bäume nach Mitte zugeordnet. Werkzeug: Schnitt nimmt weitere Klicks als Knicke, Enter/Doppelklick
|
||||
beendet (Ansicht weiter zwei Klicks); Griffe an Anfang, Knicken, Ende (`grips.rs` `sectionLineGrip`). Offen: Grundriss-Unterlage
|
||||
im Schnitt (`underlay.rs`) und 3D-Live-Schnitt folgen der Endpunkt-Verbindung; Knick einfügen/löschen am bestehenden Schnitt
|
||||
(nur Ziehen); optionale dünne Ansichtsebene; Mac-/Tauri-Ansicht nicht geprüft. · M
|
||||
- ◐ **[171]** Plan-Review Runde 2 (10.11., beide Musterhäuser, CLI-SVG `--hatch` in Chromium, nur Linux). Behoben (Kern,
|
||||
Test je Fix): Sonnenschatten auf Flächen unter dem Ansichtsbereich (grauer Fleck über dem Carport im OG/DG,
|
||||
`sun::shadow_polygons_plan_in`); Flächenzeile nach Rundungsschritt („16.0 m²“ statt „16 m²“); Schnitt genau am Rand
|
||||
|
||||
@@ -830,6 +830,13 @@ fn sectionline_ops(root: &Map<String, Value>, v: &Value, ids: &mut IdGen) -> Vec
|
||||
}
|
||||
let kind = s_of(v, "kind");
|
||||
let line = Value::Array(vec![pv(a), pv(b)]);
|
||||
// [176] Knickpunkte zwischen a und b (geknickter Schnitt, nur Schnitt); ohne = gerade Linie wie bisher.
|
||||
let bends: Vec<Value> = if kind == "section" {
|
||||
v.get("bends").and_then(Value::as_array).into_iter().flatten().filter_map(|q| Some((q.get("x")?.as_f64()?, q.get("y")?.as_f64()?))).filter(|q| q.0.is_finite() && q.1.is_finite()).map(pv).collect()
|
||||
} else {
|
||||
Vec::new()
|
||||
};
|
||||
let bend_points = (!bends.is_empty()).then_some(Value::Array(bends));
|
||||
let levels = arr(root.get("drawingLevels"));
|
||||
let of_kind: Vec<&Value> = levels.iter().filter(|z| field(z, "kind").and_then(Value::as_str) == Some(kind)).collect();
|
||||
let orphans: Vec<&&Value> = of_kind.iter().filter(|z| !truthy(field(z, "linePoints"))).collect();
|
||||
@@ -839,21 +846,26 @@ fn sectionline_ops(root: &Map<String, Value>, v: &Value, ids: &mut IdGen) -> Vec
|
||||
None | Some(Value::Null) => js_num(1.0),
|
||||
Some(x) => x.clone(),
|
||||
};
|
||||
return vec![Op::Replace { collection: "drawingLevels".into(), entity: crate::json_util::with_all(z, vec![("linePoints", line), ("directionSign", sign)]) }];
|
||||
let entity = match bend_points {
|
||||
Some(bp) => crate::json_util::with_all(z, vec![("linePoints", line), ("directionSign", sign), ("bendPoints", bp)]),
|
||||
None => crate::json_util::with_all(z, vec![("linePoints", line), ("directionSign", sign)]),
|
||||
};
|
||||
return vec![Op::Replace { collection: "drawingLevels".into(), entity }];
|
||||
}
|
||||
let name = s_of(v, "name").replace('\u{1}', &level_letters(of_kind.len()));
|
||||
add_op(
|
||||
"drawingLevels",
|
||||
vec![obj(vec![
|
||||
("id", s(&ids.next(kind))),
|
||||
("name", s(&name)),
|
||||
("kind", s(kind)),
|
||||
("visible", Value::Bool(true)),
|
||||
("locked", Value::Bool(false)),
|
||||
("linePoints", line),
|
||||
("directionSign", js_num(1.0)),
|
||||
])],
|
||||
)
|
||||
let mut fields = vec![
|
||||
("id", s(&ids.next(kind))),
|
||||
("name", s(&name)),
|
||||
("kind", s(kind)),
|
||||
("visible", Value::Bool(true)),
|
||||
("locked", Value::Bool(false)),
|
||||
("linePoints", line),
|
||||
("directionSign", js_num(1.0)),
|
||||
];
|
||||
if let Some(bp) = bend_points {
|
||||
fields.push(("bendPoints", bp));
|
||||
}
|
||||
add_op("drawingLevels", vec![obj(fields)])
|
||||
}
|
||||
|
||||
/// Richtungspfeil der Schnittlinie (Mitte → Blickrichtung, zwei Flügel).
|
||||
@@ -913,9 +925,10 @@ pub fn preview(root: &Map<String, Value>, v: &Value, pts: &[V], p: &mut Preview)
|
||||
}
|
||||
}
|
||||
"sectionline" => {
|
||||
if let [a, c] = pts {
|
||||
p.shapes.line(*a, *c);
|
||||
direction_arrow(*a, *c, 1.0, &mut p.shapes);
|
||||
// [176] Geknickt: Linienzug, Richtungspfeil je Segment.
|
||||
for w in pts.windows(2) {
|
||||
p.shapes.line(w[0], w[1]);
|
||||
direction_arrow(w[0], w[1], 1.0, &mut p.shapes);
|
||||
}
|
||||
}
|
||||
_ => return false,
|
||||
@@ -940,6 +953,25 @@ pub fn query(root: &Map<String, Value>, p: &Project, v: &Value) -> Option<Value>
|
||||
mod tests {
|
||||
use super::*;
|
||||
|
||||
/// [176] Geknickter Schnitt: Knickpunkte landen als `bendPoints` auf der Ebene (nur Schnitt).
|
||||
#[test]
|
||||
fn schnittlinie_mit_knicken() {
|
||||
let root = json!({"drawingLevels": []});
|
||||
let root = root.as_object().unwrap();
|
||||
let run = |kind: &str, bends: Value| {
|
||||
let mut ids = IdGen::new("s");
|
||||
let v = json!({"cmd": "sectionline", "a": {"x": 0, "y": 0}, "b": {"x": 6, "y": 10}, "bends": bends, "kind": kind, "name": "Schnitt \u{1}"});
|
||||
let o = sectionline_ops(root, &v, &mut ids);
|
||||
let Op::Add { items, .. } = &o[0] else { panic!() };
|
||||
items[0].clone()
|
||||
};
|
||||
let l = run("section", json!([{"x": 6, "y": 0}]));
|
||||
assert_eq!(l["bendPoints"], json!([{"x": 6, "y": 0}]));
|
||||
assert_eq!(l["linePoints"], json!([{"x": 0, "y": 0}, {"x": 6, "y": 10}]));
|
||||
assert!(run("section", json!([])).get("bendPoints").is_none());
|
||||
assert!(run("elevation", json!([{"x": 6, "y": 0}])).get("bendPoints").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn buchstaben_der_ebenen() {
|
||||
assert_eq!(level_letters(0), "A");
|
||||
|
||||
@@ -259,6 +259,11 @@ pub fn run(lk: &Lookup, req: &Request) -> Result<GripResult, String> {
|
||||
}
|
||||
// [68] Baugrube: Umriss-Ecke ziehen; der Index hinter der letzten Ecke ist der Sohlen-Griff
|
||||
// (Lage = Schwerpunkt, y um die Sohlenhöhe versetzt: Ziehen setzt `bottom` = y − Schwerpunkt-y).
|
||||
// [176] Schnittlinie: Griff 0 = Anfang, letzter = Ende, dazwischen die Knickpunkte (`bendPoints`).
|
||||
"sectionLineGrip" => {
|
||||
let (index, (x, y)) = (r.n("index"), r.p("pt"));
|
||||
patch("drawingLevels", r.s("id"), &|e| section_line_grip(e, index, x, y)).into()
|
||||
}
|
||||
"excavationGrip" => {
|
||||
let (index, (x, y)) = (r.n("index"), r.p("pt"));
|
||||
patch("context", r.s("id"), &|e| {
|
||||
@@ -434,6 +439,23 @@ fn wall_grip(w: &Value, index: f64, x: f64, y: f64, fixed_center: bool, arc_leng
|
||||
with(w, if index == 0.0 { "start" } else { "end" }, pt(x, y))
|
||||
}
|
||||
|
||||
/// [176] Griff einer Schnitt-/Ansichtslinie ziehen: Index 0 = `linePoints[0]`, 1…n = `bendPoints`,
|
||||
/// n + 1 = `linePoints[1]` (Reihenfolge entlang der Linie).
|
||||
fn section_line_grip(e: &Value, index: f64, x: f64, y: f64) -> Option<Value> {
|
||||
let line = field(e, "linePoints")?.as_array()?;
|
||||
if line.len() < 2 {
|
||||
return None;
|
||||
}
|
||||
let bends: &[Value] = field(e, "bendPoints").and_then(Value::as_array).map_or(&[], Vec::as_slice);
|
||||
let n = bends.len();
|
||||
let i = index_in(index, n + 2)?;
|
||||
if i == 0 || i == n + 1 {
|
||||
let k = if i == 0 { 0.0 } else { 1.0 };
|
||||
return Some(with(e, "linePoints", replace_at(line, k, &pt(x, y))));
|
||||
}
|
||||
Some(with(e, "bendPoints", replace_at(bends, (i - 1) as f64, &pt(x, y))))
|
||||
}
|
||||
|
||||
fn wall_moved(w: &Value, dx: f64, dy: f64) -> Value {
|
||||
let s = moved(field(w, "start").unwrap_or(&Value::Null), dx, dy);
|
||||
let e = moved(field(w, "end").unwrap_or(&Value::Null), dx, dy);
|
||||
@@ -1546,6 +1568,27 @@ mod tests {
|
||||
assert_eq!(e["outline"][2], json!({"x": 4, "y": 4}));
|
||||
}
|
||||
|
||||
/// [176] Schnittlinie: Endpunkte und Knickpunkte als Griffe.
|
||||
#[test]
|
||||
fn schnittlinie_griffe() {
|
||||
let lv = json!({"id": "s", "kind": "section", "linePoints": [{"x": 0, "y": 0}, {"x": 6, "y": 10}], "bendPoints": [{"x": 6, "y": 0}], "directionSign": 1});
|
||||
let r = root(json!({"drawingLevels": [lv]}));
|
||||
let ent = |v: Value| run(&Lookup::plain(&r), &rq(v)).unwrap().ops.first().map(|o| o.to_json()["entity"].clone());
|
||||
let e = ent(json!({"op": "sectionLineGrip", "id": "s", "index": 1, "pt": [7, -1]})).unwrap();
|
||||
assert_eq!(e["bendPoints"], json!([{"x": 7, "y": -1}]));
|
||||
assert_eq!(e["linePoints"][1], json!({"x": 6, "y": 10}));
|
||||
let e = ent(json!({"op": "sectionLineGrip", "id": "s", "index": 2, "pt": [5, 9]})).unwrap();
|
||||
assert_eq!(e["linePoints"][1], json!({"x": 5, "y": 9}));
|
||||
let e = ent(json!({"op": "sectionLineGrip", "id": "s", "index": 0, "pt": [1, 1]})).unwrap();
|
||||
assert_eq!(e["linePoints"][0], json!({"x": 1, "y": 1}));
|
||||
assert!(ent(json!({"op": "sectionLineGrip", "id": "s", "index": 3, "pt": [1, 1]})).is_none());
|
||||
// Gerade Linie (ohne Knicke): Index 1 = Ende.
|
||||
let r2 = root(json!({"drawingLevels": [{"id": "g", "kind": "section", "linePoints": [{"x": 0, "y": 0}, {"x": 5, "y": 0}]}]}));
|
||||
let res = run(&Lookup::plain(&r2), &rq(json!({"op": "sectionLineGrip", "id": "g", "index": 1, "pt": [4, 2]}))).unwrap();
|
||||
assert_eq!(entity(&res)["linePoints"][1], json!({"x": 4, "y": 2}));
|
||||
assert!(entity(&res).get("bendPoints").is_none());
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn wand_griff_und_sperre() {
|
||||
let r = root(json!({"walls": [{"id": "w", "start": {"x": 0, "y": 0}, "end": {"x": 1, "y": 0}, "extra": 1}]}));
|
||||
|
||||
@@ -154,7 +154,7 @@ fn upper_edge(ring: &[[f64; 2]]) -> Vec<Vec<[f64; 2]>> {
|
||||
}
|
||||
|
||||
/// `clipLineToU`.
|
||||
fn clip_line_to_u(pts: &[[f64; 2]], lo: f64, hi: f64) -> Vec<Vec<[f64; 2]>> {
|
||||
pub(super) fn clip_line_to_u(pts: &[[f64; 2]], lo: f64, hi: f64) -> Vec<Vec<[f64; 2]>> {
|
||||
let mut out = Vec::new();
|
||||
let mut cur: Vec<[f64; 2]> = Vec::new();
|
||||
fn flush(cur: &mut Vec<[f64; 2]>, out: &mut Vec<Vec<[f64; 2]>>) {
|
||||
|
||||
@@ -27,6 +27,7 @@ mod projection;
|
||||
mod primitives;
|
||||
mod openings;
|
||||
mod query;
|
||||
pub mod unfold;
|
||||
|
||||
use input::*;
|
||||
pub use bands::*;
|
||||
@@ -52,6 +53,8 @@ mod abzug_faelle;
|
||||
mod wand_an_dach;
|
||||
#[cfg(test)]
|
||||
mod mesh_tests;
|
||||
#[cfg(test)]
|
||||
mod unfold_tests;
|
||||
|
||||
/// Tinte der Schnitt-Poché-Umrisslinie (dunkles Grau).
|
||||
const SECTION_INK: &str = "#1f242c";
|
||||
@@ -113,6 +116,8 @@ impl Plane {
|
||||
pub struct LevelSpec {
|
||||
pub kind: String,
|
||||
pub line: Option<[Vec2; 2]>,
|
||||
/// [176] Knickpunkte zwischen `line[0]` und `line[1]` (geknickter Schnitt, s. `unfold.rs`); leer = gerade.
|
||||
pub bends: Vec<Vec2>,
|
||||
pub direction_sign: Option<f64>,
|
||||
pub depth: Option<f64>,
|
||||
pub shadows: bool,
|
||||
@@ -134,6 +139,7 @@ impl LevelSpec {
|
||||
LevelSpec {
|
||||
kind: v.get("kind").and_then(|k| k.as_str()).unwrap_or_default().to_string(),
|
||||
line,
|
||||
bends: v.get("bendPoints").and_then(|b| b.as_array()).map(|a| a.iter().filter_map(pt).collect()).unwrap_or_default(),
|
||||
direction_sign: num("directionSign"),
|
||||
depth: num("depth"),
|
||||
shadows: v.get("shadows").and_then(|b| b.as_bool()).unwrap_or(false),
|
||||
@@ -526,6 +532,15 @@ pub fn read_bodies(buf: &[f64]) -> Option<Vec<BodyMesh>> {
|
||||
|
||||
/// `computeSection` (ohne den asynchronen Teil: die Körper-Netze kommen fertig aus TS).
|
||||
pub fn compute_section(p: &Project, level: &LevelSpec, bodies: &[BodyMesh]) -> Result<Option<Output>, String> {
|
||||
// [176] Geknickter Schnitt: je Segment, aneinander abgewickelt.
|
||||
match unfold::segments(level) {
|
||||
Some(segs) => unfold::compute_unfolded(p, &segs, bodies),
|
||||
None => compute_plane(p, level, bodies, None),
|
||||
}
|
||||
}
|
||||
|
||||
/// Schnitt an einer geraden Ebene; mit `strip` ([176]) auf den Streifen eines Segments begrenzt (lokale u).
|
||||
fn compute_plane(p: &Project, level: &LevelSpec, bodies: &[BodyMesh], strip: Option<&unfold::Strip>) -> Result<Option<Output>, String> {
|
||||
let Some(plane) = level.plane() else { return Ok(None) };
|
||||
let walls_r = model3d::emit_walls_with(p, false, false)?;
|
||||
let mut slabs_r = model3d::emit_slabs(p);
|
||||
@@ -578,11 +593,20 @@ pub fn compute_section(p: &Project, level: &LevelSpec, bodies: &[BodyMesh]) -> R
|
||||
let (terrain_meshes, meshes): (Vec<_>, Vec<_>) = crate::mesh_view::meshes(p).into_iter().partition(|m| crate::mesh_view::is_terrain(m.mesh));
|
||||
let mut mesh_lines = Vec::new();
|
||||
append_mesh_sections(&mut cuts, &mut mesh_lines, &meshes, base, u);
|
||||
// [176] Segment eines geknickten Schnitts: Schnittflächen auf den Streifen (sie verdecken nur dort).
|
||||
if let Some(s) = strip {
|
||||
let mut part = Output { cuts, mesh_lines, ..Output::default() };
|
||||
unfold::clip_output(&mut part, s);
|
||||
(cuts, mesh_lines) = (part.cuts, part.mesh_lines);
|
||||
}
|
||||
// Projektion hinter der Ebene exakt ([G4]); die Schnittflächen verdecken, was hinter ihnen liegt.
|
||||
let (mut visible, hidden) = projection_edges(p, &plane, &walls_r, &wi, &slabs_r, &bodies, &meshes, &cuts, level.hidden_lines, level.depth);
|
||||
let (mut visible, hidden) = projection_edges(p, &plane, &walls_r, &wi, &slabs_r, &bodies, &meshes, &cuts, level.hidden_lines, level.depth, strip.map_or(&[][..], |s| &s.half[..]));
|
||||
shaped_projection(&mut visible, p, &walls_r, &plane);
|
||||
let meshes = meshes.iter().map(|m| MeshMeta { id: m.mesh.id.clone(), name: m.mesh.name.clone(), category: m.mesh.category_code.clone() }).collect();
|
||||
let mut out = Output { cuts, visible, hidden, profiles: Vec::new(), earth: Vec::new(), terrain_id: None, meshes, mesh_lines };
|
||||
append_terrain_profiles(&mut out, p, base, u, &terrain_meshes);
|
||||
if let Some(s) = strip {
|
||||
unfold::clip_output(&mut out, s);
|
||||
}
|
||||
Ok(Some(out))
|
||||
}
|
||||
@@ -50,7 +50,7 @@ fn quad_of(t: &[[f64; 3]; 3], n: [f64; 3], next: &[u32], vert: &dyn Fn(u32) -> (
|
||||
/// auf die Seite hinter der Ebene zugeschnitten; die Schnittflächen verdecken in Tiefe 0. Bogenwände,
|
||||
/// verschnittene Dächer und Körper glätten ihre Facetten (keine Fugen, nur Knicke und Silhouetten).
|
||||
#[allow(clippy::too_many_arguments)]
|
||||
pub(super) fn projection_edges(p: &Project, plane: &Plane, walls_r: &[RWall], wi: &[render3d::WallInput], slabs_r: &[RSlab], bodies: &[&BodyMesh], meshes: &[crate::mesh_view::MeshRef], cuts: &[Cut], hidden: bool, max_depth: Option<f64>) -> (Vec<Edge>, Vec<Edge>) {
|
||||
pub(super) fn projection_edges(p: &Project, plane: &Plane, walls_r: &[RWall], wi: &[render3d::WallInput], slabs_r: &[RSlab], bodies: &[&BodyMesh], meshes: &[crate::mesh_view::MeshRef], cuts: &[Cut], hidden: bool, max_depth: Option<f64>, strip: &[[f64; 3]]) -> (Vec<Edge>, Vec<Edge>) {
|
||||
use crate::hlr;
|
||||
let nl = crate::jsmath::hypot(&plane.normal);
|
||||
if !(nl > 1e-12) {
|
||||
@@ -231,6 +231,10 @@ pub(super) fn projection_edges(p: &Project, plane: &Plane, walls_r: &[RWall], wi
|
||||
crate::mesh_view::hlr_faces(m, &|q| view([q[0], q[2], q[1]]), owner, group, true, &mut faces);
|
||||
group += 1;
|
||||
}
|
||||
// [176] Segment eines geknickten Schnitts: nur, was in seinem Streifen liegt (Winkelhalbierende).
|
||||
if !strip.is_empty() {
|
||||
faces = faces.into_iter().filter_map(|f| super::unfold::clip_face(f, strip)).collect();
|
||||
}
|
||||
// Ansichtsbereich ([36]): Bauteile, deren nächster Punkt weiter als `max_depth` hinter der Ebene
|
||||
// liegt, entfallen ganz (auch als Verdecker — sie liegen ohnehin hinter allem Gezeigten).
|
||||
if let Some(d) = max_depth.filter(|d| *d > 0.0) {
|
||||
|
||||
@@ -93,18 +93,34 @@ pub fn section_plan_buf(p: &Project, args: &[f64], text: &str) -> Result<Vec<u8>
|
||||
// Strichstärken nach Massstab ([32]) wie im Grundriss.
|
||||
crate::plan::extras::scale_line_weights(p, scale, &mut prims);
|
||||
// [149] Bäume hinter der Schnittebene: transparente Silhouette unter dem Schnitt (Bauteile verdecken sie).
|
||||
let mut trees: Vec<Primitive> = crate::plan::trees::view_trees(p, &level, &vis, None).into_iter().flat_map(|(_, t)| t).collect();
|
||||
// [176] Geknickter Schnitt: Bäume, Öffnungen und Achsen je Segment, auf den Streifen geschnitten und abgewickelt.
|
||||
let parts = unfold::parts(&level);
|
||||
let mut trees: Vec<Primitive> = parts.iter().flat_map(|(l, s)| crate::plan::trees::view_trees(p, l, &vis, None).into_iter().flat_map(move |(_, t)| unfold::keep_group(t, s.as_ref()))).collect();
|
||||
let bounds = crate::plan::trees::union_bounds(bounds, &trees);
|
||||
crate::plan::extras::scale_line_weights(p, scale, &mut trees);
|
||||
trees.extend(prims);
|
||||
// [176] Knicklinien (nur geknickter Schnitt).
|
||||
trees.extend(unfold::bend_lines(&level, bounds));
|
||||
let prims = trees;
|
||||
w.group(&prims);
|
||||
let (door_detail, window_detail) = mvo.as_ref().map_or((true, true), |o| (o.door.section_detail, o.window.section_detail));
|
||||
let mut ops = if openings { section_opening_primitives_mv(p, &level, &vis, door_detail, window_detail)? } else { Vec::new() };
|
||||
let mut ops = Vec::new();
|
||||
if openings {
|
||||
for (l, s) in &parts {
|
||||
ops.extend(unfold::clip_prims(section_opening_primitives_mv(p, l, &vis, door_detail, window_detail)?, s.as_ref()));
|
||||
}
|
||||
}
|
||||
crate::plan::extras::scale_line_weights(p, scale, &mut ops);
|
||||
w.group(&ops);
|
||||
// Achsraster ([112]): Achsen quer zur Schnittebene.
|
||||
let grid = crate::plan::grid_view::grid_prims(p, &level, bounds, scale);
|
||||
let grid: Vec<Primitive> = parts
|
||||
.iter()
|
||||
.flat_map(|(l, s)| {
|
||||
let off = s.as_ref().map_or(0.0, |s| s.offset);
|
||||
let b = if off == 0.0 { bounds } else { [bounds[0] - off, bounds[1], bounds[2] - off, bounds[3]] };
|
||||
unfold::clip_prims(crate::plan::grid_view::grid_prims(p, l, b, scale), s.as_ref())
|
||||
})
|
||||
.collect();
|
||||
if !grid.is_empty() {
|
||||
w.group(&grid);
|
||||
}
|
||||
|
||||
@@ -168,7 +168,7 @@ fn tiefe_blendet_ferne_bauteile_aus() {
|
||||
let mut p = Project::default();
|
||||
// quer: von der Ebene geschnitten und weit nach hinten; nah: 3 m, fern: 10 m hinter der Ebene (höher).
|
||||
p.walls = vec![wall("quer", (0.0, -1.0), (0.0, 12.0), 2.5), wall("nah", (2.0, 3.0), (6.0, 3.0), 2.5), wall("fern", (2.0, 10.0), (6.0, 10.0), 4.0)];
|
||||
let lv = |depth: Option<f64>| LevelSpec { model_view: None, sketch: false, cut_hatch: false, kind: "section".into(), line: Some([Vec2 { x: -1.0, y: 0.0 }, Vec2 { x: 8.0, y: 0.0 }]), direction_sign: Some(1.0), depth, shadows: false, hidden_lines: false };
|
||||
let lv = |depth: Option<f64>| LevelSpec { model_view: None, bends: Vec::new(), sketch: false, cut_hatch: false, kind: "section".into(), line: Some([Vec2 { x: -1.0, y: 0.0 }, Vec2 { x: 8.0, y: 0.0 }]), direction_sign: Some(1.0), depth, shadows: false, hidden_lines: false };
|
||||
let top = |o: &Output| o.visible.iter().map(|e| e.a[1].max(e.b[1])).fold(f64::NEG_INFINITY, f64::max);
|
||||
let all = compute_section(&p, &lv(None), &[]).unwrap().unwrap();
|
||||
assert!(top(&all) > 3.9, "ohne Tiefe ist die ferne Wand sichtbar: {}", top(&all));
|
||||
|
||||
@@ -0,0 +1,368 @@
|
||||
//! [176] Geknickter Schnitt (`DrawingLevel.bendPoints`): Abwicklung. Jedes Segment der Schnittlinie schneidet
|
||||
//! mit seiner eigenen Ebene (Blickrichtung = Normale des Segments, Seite über `directionSign`). Was ein
|
||||
//! Segment zeigt, ist auf seinen Streifen begrenzt: an den Knicken auf die Winkelhalbierende (Schnittflächen
|
||||
//! und Projektion, nichts doppelt, nichts fehlt), aussen offen wie beim geraden Schnitt. Die Teilbilder
|
||||
//! liegen entlang der Abwicklung lückenlos aneinander (u = abgewickelte Länge, gleiche Richtung wie der
|
||||
//! gerade Schnitt vom ersten zum letzten Punkt). Ohne Knickpunkte läuft alles wie bisher.
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Streifen eines Segments in dessen eigenen Ansichtskoordinaten (u entlang der Ebene, Tiefe hinter ihr).
|
||||
#[derive(Clone, Debug)]
|
||||
pub struct Strip {
|
||||
/// u-Bereich auf der Ebene (Tiefe 0); aussen am ersten/letzten Segment unendlich.
|
||||
pub lo: f64,
|
||||
pub hi: f64,
|
||||
/// Halbebenen `a·u + b·Tiefe <= c` (Winkelhalbierende an den Knicken).
|
||||
pub half: Vec<[f64; 3]>,
|
||||
/// Verschiebung in die Abwicklung (u global = u lokal + offset).
|
||||
pub offset: f64,
|
||||
}
|
||||
|
||||
/// Teil-Ebenen eines Schnitts: ohne Knicke die Ebene selbst (ohne Streifen), sonst je Segment
|
||||
/// (gerade Ebene, Streifen).
|
||||
pub fn parts(level: &LevelSpec) -> Vec<(LevelSpec, Option<Strip>)> {
|
||||
segments(level).unwrap_or_else(|| vec![(level.clone(), None)])
|
||||
}
|
||||
|
||||
/// Linienzug Anfang, Knicke, Ende; doppelte und gerade durchlaufende Knicke entfallen, ebenso
|
||||
/// Umkehrungen (Winkelhalbierende unbestimmt).
|
||||
fn path(level: &LevelSpec) -> Option<Vec<Vec2>> {
|
||||
let [p0, p1] = level.line?;
|
||||
if level.bends.is_empty() {
|
||||
return None;
|
||||
}
|
||||
let mut pts: Vec<Vec2> = vec![p0];
|
||||
for q in level.bends.iter().copied().chain([p1]) {
|
||||
if !(q.x.is_finite() && q.y.is_finite()) {
|
||||
continue;
|
||||
}
|
||||
let last = *pts.last()?;
|
||||
if hypot2(q.x - last.x, q.y - last.y) < 1e-6 {
|
||||
continue;
|
||||
}
|
||||
pts.push(q);
|
||||
}
|
||||
// Gerade durchlaufende oder umkehrende Knicke weglassen (wiederholt, bis stabil).
|
||||
loop {
|
||||
let n = pts.len();
|
||||
let bad = (1..n.saturating_sub(1)).find(|&i| {
|
||||
let (a, b, c) = (pts[i - 1], pts[i], pts[i + 1]);
|
||||
let (d0, d1) = ((b.x - a.x, b.y - a.y), (c.x - b.x, c.y - b.y));
|
||||
let (l0, l1) = (hypot2(d0.0, d0.1), hypot2(d1.0, d1.1));
|
||||
let cross = (d0.0 * d1.1 - d0.1 * d1.0) / (l0 * l1);
|
||||
let dot = (d0.0 * d1.0 + d0.1 * d1.1) / (l0 * l1);
|
||||
(cross.abs() < 1e-9 && dot > 0.0) || dot < -0.995
|
||||
});
|
||||
match bad {
|
||||
Some(i) => {
|
||||
pts.remove(i);
|
||||
}
|
||||
None => break,
|
||||
}
|
||||
}
|
||||
(pts.len() >= 3).then_some(pts)
|
||||
}
|
||||
|
||||
/// Segmente eines geknickten Schnitts; `None` ohne (wirksame) Knicke.
|
||||
pub fn segments(level: &LevelSpec) -> Option<Vec<(LevelSpec, Option<Strip>)>> {
|
||||
let pts = path(level)?;
|
||||
let sign = level.direction_sign.unwrap_or(1.0);
|
||||
let n = pts.len() - 1;
|
||||
let dir = |i: usize| {
|
||||
let (a, b) = (pts[i], pts[i + 1]);
|
||||
let l = hypot2(b.x - a.x, b.y - a.y);
|
||||
((b.x - a.x) / l, (b.y - a.y) / l, l)
|
||||
};
|
||||
let mut out = Vec::with_capacity(n);
|
||||
let mut cum = 0.0;
|
||||
for i in 0..n {
|
||||
let (dx, dy, len) = dir(i);
|
||||
let perp = (-dy, dx);
|
||||
let mut half = Vec::new();
|
||||
// Lokal: P − S = sign·(u·d + Tiefe·perp).
|
||||
if i > 0 {
|
||||
let (px, py, _) = dir(i - 1);
|
||||
let w = (px + dx, py + dy);
|
||||
let (dw, pw) = (dx * w.0 + dy * w.1, perp.0 * w.0 + perp.1 * w.1);
|
||||
half.push([-sign * dw, -sign * pw, 0.0]);
|
||||
}
|
||||
if i + 1 < n {
|
||||
let (nx, ny, _) = dir(i + 1);
|
||||
let w = (dx + nx, dy + ny);
|
||||
let (dw, pw) = (dx * w.0 + dy * w.1, perp.0 * w.0 + perp.1 * w.1);
|
||||
half.push([sign * dw, sign * pw, len * dw]);
|
||||
}
|
||||
// u-Bereich auf der Ebene: Anfang bei 0, Ende bei sign·len.
|
||||
let start_open = i == 0;
|
||||
let end_open = i + 1 == n;
|
||||
let (s_u, e_u) = (0.0, sign * len);
|
||||
let (start_b, end_b) = (if start_open { -sign * f64::INFINITY } else { s_u }, if end_open { sign * f64::INFINITY } else { e_u });
|
||||
let (lo, hi) = (start_b.min(end_b), start_b.max(end_b));
|
||||
let seg = LevelSpec { line: Some([pts[i], pts[i + 1]]), bends: Vec::new(), ..level.clone() };
|
||||
out.push((seg, Some(Strip { lo, hi, half, offset: sign * cum })));
|
||||
cum += len;
|
||||
}
|
||||
Some(out)
|
||||
}
|
||||
|
||||
/// Knicke in der Abwicklung (u global), für die Knicklinien im Schnitt.
|
||||
pub fn bend_us(level: &LevelSpec) -> Vec<f64> {
|
||||
segments(level).map(|s| s.iter().skip(1).filter_map(|(_, st)| st.as_ref().map(|st| st.offset)).collect()).unwrap_or_default()
|
||||
}
|
||||
|
||||
// ── Zuschneiden ───────────────────────────────────────────────────────────────
|
||||
|
||||
/// Sutherland-Hodgman an einer Halbebene `f(p) <= 0` mit Kanten-Merkmal (`flag[i]` gilt für Kante i → i+1):
|
||||
/// Kanten entlang der Schnittgeraden bekommen `cut_flag`.
|
||||
fn clip_ring<T: Copy>(pts: &[T], flags: &[bool], f: &dyn Fn(&T) -> f64, lerp: &dyn Fn(&T, &T, f64) -> T, cut_flag: bool) -> (Vec<T>, Vec<bool>) {
|
||||
let n = pts.len();
|
||||
let (mut out, mut of) = (Vec::with_capacity(n + 2), Vec::with_capacity(n + 2));
|
||||
for i in 0..n {
|
||||
let (p, q) = (&pts[i], &pts[(i + 1) % n]);
|
||||
let fl = flags.get(i).copied().unwrap_or(false);
|
||||
let (fp, fq) = (f(p), f(q));
|
||||
let (pin, qin) = (fp <= 0.0, fq <= 0.0);
|
||||
// Merkmal gilt für die vom Punkt ausgehende Kante: Teil der Originalkante oder (nach einem Austritt)
|
||||
// entlang der Schnittgeraden bis zum nächsten Eintritt.
|
||||
if pin {
|
||||
out.push(*p);
|
||||
of.push(fl);
|
||||
}
|
||||
if pin != qin {
|
||||
out.push(lerp(p, q, fp / (fp - fq)));
|
||||
of.push(if pin { cut_flag } else { fl });
|
||||
}
|
||||
}
|
||||
(out, of)
|
||||
}
|
||||
|
||||
fn lerp2(a: &[f64; 2], b: &[f64; 2], t: f64) -> [f64; 2] {
|
||||
[a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t]
|
||||
}
|
||||
|
||||
/// Polygon (u, v) auf `lo <= u <= hi`, mit „ohne Strich“-Kanten (`nse`, Indizes); neue Kanten auf den
|
||||
/// Grenzen ohne Strich. `None`, wenn nichts bleibt.
|
||||
pub(super) fn clip_poly_u(pts: &[[f64; 2]], nse: Option<&[f64]>, lo: f64, hi: f64) -> Option<(Vec<[f64; 2]>, Option<Vec<f64>>)> {
|
||||
if pts.iter().all(|q| q[0] >= lo && q[0] <= hi) {
|
||||
return Some((pts.to_vec(), nse.map(|n| n.to_vec())));
|
||||
}
|
||||
let mut flags = vec![false; pts.len()];
|
||||
for &k in nse.unwrap_or(&[]) {
|
||||
if let Some(f) = flags.get_mut(k as usize) {
|
||||
*f = true;
|
||||
}
|
||||
}
|
||||
let mut cur = pts.to_vec();
|
||||
if lo.is_finite() {
|
||||
(cur, flags) = clip_ring(&cur, &flags, &|q| lo - q[0], &|a, b, t| { let mut x = lerp2(a, b, t); x[0] = lo; x }, true);
|
||||
}
|
||||
if hi.is_finite() && cur.len() >= 3 {
|
||||
(cur, flags) = clip_ring(&cur, &flags, &|q| q[0] - hi, &|a, b, t| { let mut x = lerp2(a, b, t); x[0] = hi; x }, true);
|
||||
}
|
||||
if cur.len() < 3 {
|
||||
return None;
|
||||
}
|
||||
let nse: Vec<f64> = flags.iter().enumerate().filter(|(_, f)| **f).map(|(i, _)| i as f64).collect();
|
||||
Some((cur, (!nse.is_empty()).then_some(nse)))
|
||||
}
|
||||
|
||||
/// Fläche der Projektion (u, Höhe, Tiefe) auf die Halbebenen des Streifens; neue Kanten ungezeichnet.
|
||||
pub(super) fn clip_face(mut f: crate::hlr::Face, half: &[[f64; 3]]) -> Option<crate::hlr::Face> {
|
||||
for h in half {
|
||||
let g = |q: &[f64; 3]| h[0] * q[0] + h[1] * q[2] - h[2];
|
||||
if f.pts.iter().all(|q| g(q) <= 0.0) {
|
||||
continue;
|
||||
}
|
||||
let flags = if f.no_edge.is_empty() { vec![false; f.pts.len()] } else { f.no_edge.clone() };
|
||||
let (pts, ne) = clip_ring(&f.pts, &flags, &g, &|a, b, t| [a[0] + (b[0] - a[0]) * t, a[1] + (b[1] - a[1]) * t, a[2] + (b[2] - a[2]) * t], true);
|
||||
if pts.len() < 3 {
|
||||
return None;
|
||||
}
|
||||
f.pts = pts;
|
||||
f.no_edge = ne;
|
||||
}
|
||||
Some(f)
|
||||
}
|
||||
|
||||
/// Ergebnis eines Segments auf seinen Streifen begrenzen (Ebenen-Teile: Schnittflächen, Gelände, Erdreich,
|
||||
/// offene Netz-Schnittlinien; die Projektion ist schon in `projection_edges` zugeschnitten).
|
||||
pub(super) fn clip_output(out: &mut Output, s: &Strip) {
|
||||
let (lo, hi) = (s.lo, s.hi);
|
||||
out.cuts = std::mem::take(&mut out.cuts)
|
||||
.into_iter()
|
||||
.filter_map(|mut c| {
|
||||
let (pts, nse) = clip_poly_u(&c.pts, c.nse.as_deref(), lo, hi)?;
|
||||
c.pts = pts;
|
||||
c.nse = nse;
|
||||
Some(c)
|
||||
})
|
||||
.collect();
|
||||
out.profiles = std::mem::take(&mut out.profiles).into_iter().flat_map(|pr| clip_line_to_u(&pr.pts, lo, hi).into_iter().map(move |pts| Profile { pts, ..pr.clone() })).collect();
|
||||
out.earth = std::mem::take(&mut out.earth).into_iter().filter_map(|(pts, h)| clip_poly_u(&pts, None, lo, hi).map(|(p, _)| (p, h))).collect();
|
||||
out.mesh_lines = std::mem::take(&mut out.mesh_lines).into_iter().flat_map(|(k, pts)| clip_line_to_u(&pts, lo, hi).into_iter().map(move |p| (k, p))).collect();
|
||||
}
|
||||
|
||||
/// Ergebnis um `du` entlang u verschieben (in die Abwicklung).
|
||||
pub(super) fn shift_output(out: &mut Output, du: f64) {
|
||||
if du == 0.0 {
|
||||
return;
|
||||
}
|
||||
let sh = |q: &mut [f64; 2]| q[0] += du;
|
||||
out.cuts.iter_mut().flat_map(|c| c.pts.iter_mut()).for_each(sh);
|
||||
for e in out.visible.iter_mut().chain(out.hidden.iter_mut()) {
|
||||
e.a[0] += du;
|
||||
e.b[0] += du;
|
||||
}
|
||||
out.profiles.iter_mut().flat_map(|p| p.pts.iter_mut()).for_each(sh);
|
||||
out.earth.iter_mut().flat_map(|p| p.0.iter_mut()).for_each(sh);
|
||||
out.mesh_lines.iter_mut().flat_map(|p| p.1.iter_mut()).for_each(sh);
|
||||
}
|
||||
|
||||
/// Teilergebnis anhängen (Netze und Gelände-Id sind in allen Segmenten dieselben).
|
||||
pub(super) fn merge_output(acc: &mut Option<Output>, o: Output) {
|
||||
let Some(a) = acc else {
|
||||
*acc = Some(o);
|
||||
return;
|
||||
};
|
||||
a.cuts.extend(o.cuts);
|
||||
a.visible.extend(o.visible);
|
||||
a.hidden.extend(o.hidden);
|
||||
a.profiles.extend(o.profiles);
|
||||
a.earth.extend(o.earth);
|
||||
a.mesh_lines.extend(o.mesh_lines);
|
||||
if a.terrain_id.is_none() {
|
||||
a.terrain_id = o.terrain_id;
|
||||
}
|
||||
if a.meshes.is_empty() {
|
||||
a.meshes = o.meshes;
|
||||
}
|
||||
}
|
||||
|
||||
// ── Primitive (Öffnungen, Achsen, Bäume) ─────────────────────────────────────
|
||||
|
||||
/// Bezugs-u eines Primitivs (Mitte bzw. Anker).
|
||||
fn anchor_u(q: &Primitive) -> f64 {
|
||||
match q {
|
||||
Primitive::Polygon { pts, .. } => pts.iter().map(|p| p.x).sum::<f64>() / pts.len().max(1) as f64,
|
||||
Primitive::Line { a, b, .. } => 0.5 * (a.x + b.x),
|
||||
Primitive::Arc { center, .. } | Primitive::DrawingCircle { center, .. } | Primitive::DrawingArc { center, .. } => center.x,
|
||||
Primitive::Text { at, .. } | Primitive::DrawingText { at, .. } => at.x,
|
||||
Primitive::DrawingTextPath { path_pts, .. } => path_pts.first().map_or(0.0, |p| p.x),
|
||||
Primitive::DrawingImage { min, max, .. } => 0.5 * (min.x + max.x),
|
||||
}
|
||||
}
|
||||
|
||||
fn shift_prim(q: &mut Primitive, du: f64) {
|
||||
match q {
|
||||
Primitive::Polygon { pts, .. } => pts.iter_mut().for_each(|p| p.x += du),
|
||||
Primitive::Line { a, b, .. } => {
|
||||
a.x += du;
|
||||
b.x += du;
|
||||
}
|
||||
Primitive::Arc { center, from, to, .. } => {
|
||||
center.x += du;
|
||||
from.x += du;
|
||||
to.x += du;
|
||||
}
|
||||
Primitive::Text { at, .. } | Primitive::DrawingText { at, .. } => at.x += du,
|
||||
Primitive::DrawingTextPath { path_pts, .. } => path_pts.iter_mut().for_each(|p| p.x += du),
|
||||
Primitive::DrawingImage { min, max, .. } => {
|
||||
min.x += du;
|
||||
max.x += du;
|
||||
}
|
||||
Primitive::DrawingCircle { center, .. } | Primitive::DrawingArc { center, .. } => center.x += du,
|
||||
}
|
||||
}
|
||||
|
||||
/// Primitive auf den u-Bereich des Streifens schneiden (Linien und Flächen geometrisch, sonst nach Anker)
|
||||
/// und in die Abwicklung schieben. Ohne Streifen unverändert.
|
||||
pub fn clip_prims(prims: Vec<Primitive>, s: Option<&Strip>) -> Vec<Primitive> {
|
||||
let Some(s) = s else { return prims };
|
||||
let (lo, hi) = (s.lo, s.hi);
|
||||
let mut out = Vec::with_capacity(prims.len());
|
||||
for mut q in prims {
|
||||
let keep = match &mut q {
|
||||
Primitive::Polygon { pts, no_stroke_edges, .. } => {
|
||||
let p2: Vec<[f64; 2]> = pts.iter().map(|p| [p.x, p.y]).collect();
|
||||
match clip_poly_u(&p2, no_stroke_edges.as_deref(), lo, hi) {
|
||||
Some((c, nse)) => {
|
||||
*pts = c.into_iter().map(|p| Vec2 { x: p[0], y: p[1] }).collect();
|
||||
*no_stroke_edges = nse;
|
||||
true
|
||||
}
|
||||
None => false,
|
||||
}
|
||||
}
|
||||
Primitive::Line { a, b, .. } => match clip_line_to_u(&[[a.x, a.y], [b.x, b.y]], lo, hi).first() {
|
||||
Some(l) if l.len() == 2 => {
|
||||
*a = Vec2 { x: l[0][0], y: l[0][1] };
|
||||
*b = Vec2 { x: l[1][0], y: l[1][1] };
|
||||
true
|
||||
}
|
||||
_ => false,
|
||||
},
|
||||
other => {
|
||||
let u = anchor_u(other);
|
||||
u >= lo - 1e-9 && u <= hi + 1e-9
|
||||
}
|
||||
};
|
||||
if keep {
|
||||
shift_prim(&mut q, s.offset);
|
||||
out.push(q);
|
||||
}
|
||||
}
|
||||
out
|
||||
}
|
||||
|
||||
/// Ganze Gruppe (z. B. ein Baum) behalten, wenn ihre Mitte im Streifen liegt; verschoben.
|
||||
pub fn keep_group(prims: Vec<Primitive>, s: Option<&Strip>) -> Vec<Primitive> {
|
||||
let Some(s) = s else { return prims };
|
||||
let polys: Vec<f64> = prims.iter().filter(|q| matches!(q, Primitive::Polygon { .. })).map(anchor_u).collect();
|
||||
let all: Vec<f64> = if polys.is_empty() { prims.iter().map(anchor_u).collect() } else { polys };
|
||||
let u = all.iter().sum::<f64>() / all.len().max(1) as f64;
|
||||
if !(u >= s.lo && u <= s.hi) {
|
||||
return Vec::new();
|
||||
}
|
||||
let mut prims = prims;
|
||||
prims.iter_mut().for_each(|q| shift_prim(q, s.offset));
|
||||
prims
|
||||
}
|
||||
|
||||
/// [176] Dünne senkrechte Knicklinien über die Höhe des Schnitts (CH-Praxis).
|
||||
pub fn bend_lines(level: &LevelSpec, bounds: [f64; 4]) -> Vec<Primitive> {
|
||||
bend_us(level)
|
||||
.into_iter()
|
||||
.map(|u| Primitive::Line {
|
||||
a: Vec2 { x: u, y: bounds[1] },
|
||||
b: Vec2 { x: u, y: bounds[3] },
|
||||
cls: "section-bend".into(),
|
||||
weight_mm: BEND_LINE_MM,
|
||||
dash: None,
|
||||
zigzag: None,
|
||||
motif: None,
|
||||
color: Some(SECTION_VISIBLE_INK.into()),
|
||||
drawing_id: None,
|
||||
opening_id: None,
|
||||
stair_id: None,
|
||||
greyed: None,
|
||||
opacity: None,
|
||||
})
|
||||
.collect()
|
||||
}
|
||||
|
||||
/// [176] Strichstärke der Knicklinie (Papier-mm).
|
||||
const BEND_LINE_MM: f64 = 0.13;
|
||||
|
||||
/// `compute_section` für einen geknickten Schnitt: je Segment rechnen, zuschneiden, verschieben, sammeln.
|
||||
pub(super) fn compute_unfolded(p: &Project, segs: &[(LevelSpec, Option<Strip>)], bodies: &[BodyMesh]) -> Result<Option<Output>, String> {
|
||||
let mut acc: Option<Output> = None;
|
||||
for (l, s) in segs {
|
||||
let Some(mut o) = compute_plane(p, l, bodies, s.as_ref())? else { continue };
|
||||
if let Some(s) = s {
|
||||
shift_output(&mut o, s.offset);
|
||||
}
|
||||
merge_output(&mut acc, o);
|
||||
}
|
||||
Ok(acc)
|
||||
}
|
||||
@@ -0,0 +1,133 @@
|
||||
//! [176] Geknickter Schnitt: Abwicklung (`unfold.rs`).
|
||||
|
||||
use super::*;
|
||||
|
||||
/// Zwei Wände: W1 quer zum ersten Segment (x = 2), W2 quer zum zweiten (y = 6, x 4…8).
|
||||
fn zwei_waende() -> Project {
|
||||
waende(4.0, 8.0)
|
||||
}
|
||||
|
||||
/// Wie [`zwei_waende`], W2 von x = `x0` bis `x1`.
|
||||
fn waende(x0: f64, x1: f64) -> Project {
|
||||
serde_json::from_value(serde_json::json!({
|
||||
"id": "p", "name": "t", "lineStyles": [], "hatches": [], "components": [], "wallTypes": [], "layers": [], "drawings2d": [],
|
||||
"drawingLevels": [{"id": "F", "name": "EG", "kind": "floor", "visible": true, "locked": false, "floorHeight": 3.0, "baseElevation": 0}],
|
||||
"walls": [
|
||||
{"id": "W1", "type": "wall", "floorId": "F", "categoryCode": "20", "start": {"x": 2, "y": -3}, "end": {"x": 2, "y": 3}, "height": 3.0},
|
||||
{"id": "W2", "type": "wall", "floorId": "F", "categoryCode": "20", "start": {"x": x0, "y": 6}, "end": {"x": x1, "y": 6}, "height": 3.0}
|
||||
]
|
||||
}))
|
||||
.unwrap()
|
||||
}
|
||||
|
||||
fn l_schnitt(sign: f64, bends: Vec<Vec2>) -> LevelSpec {
|
||||
LevelSpec { kind: "section".into(), line: Some([Vec2 { x: 0.0, y: 0.0 }, Vec2 { x: 6.0, y: 10.0 }]), bends, direction_sign: Some(sign), ..Default::default() }
|
||||
}
|
||||
|
||||
fn knick() -> Vec<Vec2> {
|
||||
vec![Vec2 { x: 6.0, y: 0.0 }]
|
||||
}
|
||||
|
||||
/// u-Bereich der Schnittflächen einer Wand.
|
||||
fn cut_ranges(out: &Output, id: &str) -> Vec<(f64, f64)> {
|
||||
out.cuts
|
||||
.iter()
|
||||
.filter(|c| c.kind == Kind::Wall && c.source_id.as_deref() == Some(id))
|
||||
.map(|c| c.pts.iter().fold((f64::INFINITY, f64::NEG_INFINITY), |(a, b), q| (a.min(q[0]), b.max(q[0]))))
|
||||
.collect()
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn l_schnitt_zeigt_beide_waende_je_einmal() {
|
||||
let p = zwei_waende();
|
||||
for sign in [1.0, -1.0] {
|
||||
let out = compute_section(&p, &l_schnitt(sign, knick()), &[]).unwrap().unwrap();
|
||||
let (w1, w2) = (cut_ranges(&out, "W1"), cut_ranges(&out, "W2"));
|
||||
assert_eq!(w1.len(), 1, "W1 genau einmal geschnitten ({sign}): {w1:?}");
|
||||
assert_eq!(w2.len(), 1, "W2 genau einmal geschnitten ({sign}): {w2:?}");
|
||||
// W1 bei 2 m, W2 bei 6 + 6 = 12 m der Abwicklung (Richtung wie der gerade Schnitt: sign).
|
||||
let mid = |r: (f64, f64)| 0.5 * (r.0 + r.1);
|
||||
assert!((mid(w1[0]) - sign * 2.0).abs() < 0.2, "{w1:?}");
|
||||
assert!((mid(w2[0]) - sign * 12.0).abs() < 0.2, "{w2:?}");
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn abwicklung_laenge_ist_summe_der_segmente() {
|
||||
let l = l_schnitt(1.0, knick());
|
||||
let segs = unfold::segments(&l).unwrap();
|
||||
assert_eq!(segs.len(), 2);
|
||||
assert_eq!(unfold::bend_us(&l), vec![6.0]);
|
||||
let last = segs[1].1.as_ref().unwrap();
|
||||
assert_eq!(last.offset, 6.0);
|
||||
assert_eq!(last.lo, 0.0);
|
||||
assert_eq!(last.hi, f64::INFINITY);
|
||||
// Ende der Abwicklung: 6 + 10 = 16 (Versatz + Länge des letzten Segments).
|
||||
let [a, b] = segs[1].0.line.unwrap();
|
||||
assert_eq!(last.offset + (b.x - a.x).hypot(b.y - a.y), 16.0);
|
||||
assert_eq!(unfold::bend_us(&l_schnitt(-1.0, knick())), vec![-6.0]);
|
||||
}
|
||||
|
||||
/// Projektion: W2 liegt hinter beiden Ebenen, gehört aber nur in den Streifen des zweiten Segments
|
||||
/// (Winkelhalbierende am Knick).
|
||||
#[test]
|
||||
fn projektion_nur_im_eigenen_streifen() {
|
||||
// W2 (x 3…5) ganz hinter dem zweiten Segment (Tiefe 1…3), Stirnseite sichtbar.
|
||||
let p = waende(3.0, 5.0);
|
||||
let out = compute_section(&p, &l_schnitt(1.0, knick()), &[]).unwrap().unwrap();
|
||||
let walls_r = model3d::emit_walls_with(&p, false, false).unwrap();
|
||||
let edges: Vec<&Edge> = out.visible.iter().filter(|e| e.kind == Kind::Wall).collect();
|
||||
assert!(edges.iter().any(|e| walls_r[e.index].wall_id == "W2"));
|
||||
for e in &edges {
|
||||
if walls_r[e.index].wall_id == "W2" {
|
||||
assert!(e.a[0].min(e.b[0]) >= 6.0 - 1e-6, "W2 nur rechts vom Knick: {e:?}");
|
||||
}
|
||||
}
|
||||
// Gerade Ebene entlang des ersten Segments (ohne Streifen) sähe W2 dagegen (u 3…5).
|
||||
let gerade = LevelSpec { line: Some([Vec2 { x: 0.0, y: 0.0 }, Vec2 { x: 6.0, y: 0.0 }]), ..l_schnitt(1.0, vec![]) };
|
||||
let o2 = compute_section(&p, &gerade, &[]).unwrap().unwrap();
|
||||
assert!(o2.visible.iter().any(|e| e.kind == Kind::Wall && walls_r[e.index].wall_id == "W2" && e.a[0].max(e.b[0]) < 6.0 + 1e-6));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn ohne_wirksame_knicke_wie_gerade() {
|
||||
let p = zwei_waende();
|
||||
let gerade = l_schnitt(1.0, vec![]);
|
||||
// Knick auf der Geraden (Mitte) und doppelte Punkte entfallen.
|
||||
let mitte = l_schnitt(1.0, vec![Vec2 { x: 3.0, y: 5.0 }, Vec2 { x: 3.0, y: 5.0 }]);
|
||||
assert!(unfold::segments(&gerade).is_none());
|
||||
assert!(unfold::segments(&mitte).is_none());
|
||||
let a = compute_section(&p, &gerade, &[]).unwrap().unwrap();
|
||||
let b = compute_section(&p, &mitte, &[]).unwrap().unwrap();
|
||||
assert_eq!(format!("{:?}", a.cuts), format!("{:?}", b.cuts));
|
||||
assert_eq!(format!("{:?}", a.visible), format!("{:?}", b.visible));
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn polygon_zuschnitt_markiert_neue_kanten() {
|
||||
let sq = [[0.0, 0.0], [4.0, 0.0], [4.0, 1.0], [0.0, 1.0]];
|
||||
let (pts, nse) = unfold::clip_poly_u(&sq, None, 1.0, 3.0).unwrap();
|
||||
assert_eq!(pts.len(), 4);
|
||||
assert!(pts.iter().all(|q| q[0] >= 1.0 && q[0] <= 3.0));
|
||||
// Zwei neue senkrechte Kanten (auf u = 1 und u = 3) ohne Strich.
|
||||
let nse = nse.unwrap();
|
||||
assert_eq!(nse.len(), 2);
|
||||
for k in nse {
|
||||
let (a, b) = (pts[k as usize], pts[(k as usize + 1) % 4]);
|
||||
assert_eq!(a[0], b[0]);
|
||||
}
|
||||
}
|
||||
|
||||
#[test]
|
||||
fn plan_puffer_mit_knicklinie() {
|
||||
let p = zwei_waende();
|
||||
let mut lv = serde_json::json!({ "kind": "section", "linePoints": [{"x": 0, "y": 0}, {"x": 6, "y": 10}], "directionSign": 1 });
|
||||
let text = |lv: &serde_json::Value| serde_json::json!({ "level": lv }).to_string();
|
||||
let gerade = section_plan_buf(&p, &[0.0, 1.0, 0.0], &text(&lv)).unwrap();
|
||||
lv["bendPoints"] = serde_json::json!([{"x": 6, "y": 0}]);
|
||||
let geknickt = section_plan_buf(&p, &[0.0, 1.0, 0.0], &text(&lv)).unwrap();
|
||||
let prims = |b: &[u8]| -> Vec<Primitive> { crate::plan::buf::View::parse(b).and_then(|v| v.prims()).unwrap() };
|
||||
let bends = |prims: &[Primitive]| -> Vec<(f64, f64)> { prims.iter().filter_map(|q| if let Primitive::Line { cls, a, b, .. } = q { (cls == "section-bend").then_some((a.x, b.x)) } else { None }).collect() };
|
||||
assert!(bends(&prims(&gerade)).is_empty());
|
||||
assert_eq!(bends(&prims(&geknickt)), vec![(6.0, 6.0)]);
|
||||
}
|
||||
@@ -13,7 +13,10 @@ function commitLine(p: Project, a: Vec2, b: Vec2, kind: "section" | "elevation")
|
||||
let s = sectionLineCommand.init();
|
||||
[s] = sectionLineCommand.onInput(s, { kind: "option", id: kind }, ctx);
|
||||
[s] = sectionLineCommand.onInput(s, { kind: "point", point: a }, ctx);
|
||||
const [, res] = sectionLineCommand.onInput(s, { kind: "point", point: b }, ctx);
|
||||
let res;
|
||||
[s, res] = sectionLineCommand.onInput(s, { kind: "point", point: b }, ctx);
|
||||
// [176] Schnitt: weitere Klicks wären Knicke, Enter beendet.
|
||||
if (!res.commit) [, res] = sectionLineCommand.onConfirm(s, ctx);
|
||||
const ops = res.commit!.toOps(p);
|
||||
return ops.length ? applyOps(p, ops) : p;
|
||||
}
|
||||
@@ -113,3 +116,30 @@ describe("sectionline — Name der neuen Ebene", () => {
|
||||
expect(nextLevelName(p1, "section")).toContain("B");
|
||||
});
|
||||
});
|
||||
|
||||
describe("sectionline — geknickter Schnitt [176]", () => {
|
||||
it("weitere Klicks werden Knickpunkte, Enter beendet; Doppelklick-Punkt zählt nicht doppelt", () => {
|
||||
const p = projectWith([{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false }]);
|
||||
const ctx = { project: p, level: { id: "eg", kind: "floor" }, defaultCategoryCode: "20", activeWallTypeId: "", selection: { wallIds: [], drawingId: null } } as unknown as CommandContext;
|
||||
let s = sectionLineCommand.init();
|
||||
[s] = sectionLineCommand.onInput(s, { kind: "point", point: { x: 0, y: 0 } }, ctx);
|
||||
let res;
|
||||
[s, res] = sectionLineCommand.onInput(s, { kind: "point", point: { x: 6, y: 0 } }, ctx);
|
||||
expect(res.commit).toBeUndefined();
|
||||
expect(sectionLineCommand.prompt(s)).toBe("cmd.sectionline.next");
|
||||
[s] = sectionLineCommand.onInput(s, { kind: "point", point: { x: 6, y: 10 } }, ctx);
|
||||
[s] = sectionLineCommand.onInput(s, { kind: "point", point: { x: 6, y: 10 } }, ctx);
|
||||
[, res] = sectionLineCommand.onConfirm(s, ctx);
|
||||
const out = applyOps(p, res.commit!.toOps(p));
|
||||
const lv = out.drawingLevels.at(-1)!;
|
||||
expect(lv.kind).toBe("section");
|
||||
expect(lv.linePoints).toEqual([{ x: 0, y: 0 }, { x: 6, y: 10 }]);
|
||||
expect(lv.bendPoints).toEqual([{ x: 6, y: 0 }]);
|
||||
});
|
||||
|
||||
it("Ansicht bleibt bei zwei Klicks", () => {
|
||||
const p = projectWith([{ id: "eg", name: "EG", kind: "floor", visible: true, locked: false }]);
|
||||
const out = commitLine(p, a, b, "elevation");
|
||||
expect(out.drawingLevels.at(-1)!.bendPoints).toBeUndefined();
|
||||
});
|
||||
});
|
||||
@@ -5,7 +5,9 @@
|
||||
//
|
||||
// Schritte:
|
||||
// 1) „Schnitt-Startpunkt:" → Punkt
|
||||
// 2) „Schnitt-Endpunkt:" → Live-Linie + Richtungspfeil; Klick committet.
|
||||
// 2) „Schnitt-Endpunkt:" → Live-Linie + Richtungspfeil; Klick committet (Ansicht).
|
||||
// Schnitt ([176]): jeder weitere Klick setzt einen Knickpunkt (geknickter Schnitt), Enter/Doppelklick
|
||||
// beendet mit dem letzten Punkt als Ende (`bendPoints` = die Punkte dazwischen).
|
||||
//
|
||||
// Ziel-Ebene (im Commit bestimmt): existiert GENAU EINE Ebene der gewählten Art
|
||||
// OHNE gesetzte Linie (frisch angelegter Platzhalter), wird deren Linie gesetzt;
|
||||
@@ -41,12 +43,13 @@ const KIND_IDS = new Set(KIND_OPTIONS.map((o) => o.id));
|
||||
* Vorschau: Schnittlinie + Richtungspfeil (Kern, `cmd_solid.rs`: vom Mittelpunkt entlang der
|
||||
* Blicknormalen, zwei Flügel) + Länge im HUD.
|
||||
*/
|
||||
function lineDraft(ctx: CommandContext, a: Vec2, cursor: Vec2 | null): ToolDraft {
|
||||
if (!cursor) return { preview: [{ kind: "poly", pts: [a] }], vertices: [a] };
|
||||
const draft: ToolDraft = { preview: createPreview(ctx, { cmd: "sectionline" }, [a, cursor]).shapes, vertices: [a] };
|
||||
function lineDraft(ctx: CommandContext, pts: Vec2[], cursor: Vec2 | null): ToolDraft {
|
||||
if (!cursor) return { preview: [{ kind: "poly", pts }], vertices: pts };
|
||||
const last = pts[pts.length - 1];
|
||||
const draft: ToolDraft = { preview: createPreview(ctx, { cmd: "sectionline" }, [...pts, cursor]).shapes, vertices: pts };
|
||||
draft.hud = {
|
||||
at: cursor,
|
||||
text: `${Math.hypot(cursor.x - a.x, cursor.y - a.y).toFixed(2)} m`,
|
||||
text: `${Math.hypot(cursor.x - last.x, cursor.y - last.y).toFixed(2)} m`,
|
||||
};
|
||||
return draft;
|
||||
}
|
||||
@@ -55,9 +58,9 @@ function lineDraft(ctx: CommandContext, a: Vec2, cursor: Vec2 | null): ToolDraft
|
||||
* Commit (Kern): Linie [a, b] auf die EINE Ebene der Art ohne Linie, sonst eine neue Ebene (Name aus der
|
||||
* Vorlage, Buchstaben A, B, … nach Anzahl der Ebenen dieser Art); zu kurze Linien (< 0.1 m) → nichts.
|
||||
*/
|
||||
function lineMutation(ctx: CommandContext, a: Vec2, b: Vec2, kind: LineKind) {
|
||||
function lineMutation(ctx: CommandContext, a: Vec2, b: Vec2, kind: LineKind, bends: Vec2[] = []) {
|
||||
const key = kind === "section" ? "cmd.sectionline.newSection" : "cmd.sectionline.newElevation";
|
||||
return createMutation(ctx, { cmd: "sectionline", a, b, kind, name: t(key, { letter: "\u0001" }) });
|
||||
return createMutation(ctx, { cmd: "sectionline", a, b, kind, name: t(key, { letter: "\u0001" }), ...(bends.length ? { bends } : {}) });
|
||||
}
|
||||
|
||||
interface LineIdle extends CommandState {
|
||||
@@ -67,6 +70,8 @@ interface LineIdle extends CommandState {
|
||||
interface LineEnd extends CommandState {
|
||||
phase: "end";
|
||||
a: Vec2;
|
||||
/** [176] Weitere Klicks (Schnitt): Knickpunkte, der letzte wird beim Beenden das Ende. */
|
||||
pts: Vec2[];
|
||||
cursor: Vec2 | null;
|
||||
kind: LineKind;
|
||||
}
|
||||
@@ -85,7 +90,11 @@ function makeCommand(name: string, startKind: LineKind): Command {
|
||||
// auf freien Zeichnungsebenen nutzbar bleiben; die Prüfung übernimmt der
|
||||
// Grundriss-Kontext (keine harte Sperre nötig).
|
||||
floorOnly: true,
|
||||
prompt: (s) => ((s as LineState).phase === "end" ? "cmd.sectionline.end" : "cmd.sectionline.start"),
|
||||
prompt: (s) => {
|
||||
const st = s as LineState;
|
||||
if (st.phase !== "end") return "cmd.sectionline.start";
|
||||
return st.kind === "section" && st.pts.length > 0 ? "cmd.sectionline.next" : "cmd.sectionline.end";
|
||||
},
|
||||
accepts: () => ["point", "option"],
|
||||
options: () => KIND_OPTIONS,
|
||||
init: (): LineIdle => ({ phase: "start", kind: startKind, lastPoint: null }),
|
||||
@@ -95,28 +104,36 @@ function makeCommand(name: string, startKind: LineKind): Command {
|
||||
if (input.kind === "option" && KIND_IDS.has(input.id)) {
|
||||
const ns = { ...s, kind: input.id as LineKind } as LineState;
|
||||
const draft =
|
||||
ns.phase === "end" ? lineDraft(ctx, ns.a, ns.cursor) : null;
|
||||
ns.phase === "end" ? lineDraft(ctx, [ns.a, ...ns.pts], ns.cursor) : null;
|
||||
return [ns, { draft }];
|
||||
}
|
||||
if (input.kind !== "point") {
|
||||
return [
|
||||
s,
|
||||
{ draft: s.phase === "end" ? lineDraft(ctx, s.a, s.cursor) : null },
|
||||
{ draft: s.phase === "end" ? lineDraft(ctx, [s.a, ...s.pts], s.cursor) : null },
|
||||
];
|
||||
}
|
||||
if (s.phase !== "end") {
|
||||
const ns: LineEnd = {
|
||||
phase: "end",
|
||||
a: input.point,
|
||||
pts: [],
|
||||
cursor: input.point,
|
||||
kind: s.kind,
|
||||
lastPoint: input.point,
|
||||
};
|
||||
return [ns, { draft: lineDraft(ctx, input.point, input.point) }];
|
||||
return [ns, { draft: lineDraft(ctx, [input.point], input.point) }];
|
||||
}
|
||||
const a = s.a;
|
||||
const b = input.point;
|
||||
const kind = s.kind;
|
||||
if (kind === "section") {
|
||||
// [176] Schnitt: Punkt anhängen (Knick); derselbe Punkt nochmals (Doppelklick) ändert nichts.
|
||||
const last = s.pts.length ? s.pts[s.pts.length - 1] : a;
|
||||
if (Math.hypot(b.x - last.x, b.y - last.y) < 1e-6) return [s, { draft: lineDraft(ctx, [a, ...s.pts], s.cursor) }];
|
||||
const ns: LineEnd = { ...s, pts: [...s.pts, b], cursor: b, lastPoint: b };
|
||||
return [ns, { draft: lineDraft(ctx, [a, ...ns.pts], b) }];
|
||||
}
|
||||
return [
|
||||
{ phase: "start", kind, lastPoint: null } as LineIdle,
|
||||
{ draft: null, done: true, commit: lineMutation(ctx, a, b, kind) },
|
||||
@@ -127,10 +144,21 @@ function makeCommand(name: string, startKind: LineKind): Command {
|
||||
const s = state as LineState;
|
||||
if (s.phase !== "end") return [s, { draft: null }];
|
||||
const ns: LineEnd = { ...s, cursor: point };
|
||||
return [ns, { draft: lineDraft(ctx, s.a, point) }];
|
||||
return [ns, { draft: lineDraft(ctx, [s.a, ...s.pts], point) }];
|
||||
},
|
||||
|
||||
onConfirm: (state): [CommandState, CommandResult] => idle((state as LineState).kind),
|
||||
// [176] Enter/Doppelklick: geknickten Schnitt mit dem letzten Punkt als Ende setzen.
|
||||
onConfirm: (state, ctx): [CommandState, CommandResult] => {
|
||||
const s = state as LineState;
|
||||
if (s.phase === "end" && s.pts.length > 0) {
|
||||
const b = s.pts[s.pts.length - 1];
|
||||
return [
|
||||
{ phase: "start", kind: s.kind, lastPoint: null } as LineIdle,
|
||||
{ draft: null, done: true, commit: lineMutation(ctx, s.a, b, s.kind, s.pts.slice(0, -1)) },
|
||||
];
|
||||
}
|
||||
return idle(s.kind);
|
||||
},
|
||||
onCancel: (state): [CommandState, CommandResult] => idle((state as LineState).kind),
|
||||
};
|
||||
}
|
||||
|
||||
@@ -29,6 +29,8 @@ export type GripRequest =
|
||||
| { op: "roomStamp"; id: string; delta: P; pt?: P }
|
||||
| { op: "ceilingEdge" | "roomEdge"; id: string; a: number; b: number; delta: P }
|
||||
| { op: "excavationGrip"; id: string; index: number; pt: P }
|
||||
// [176] Schnittlinie: 0 = Anfang, dann `bendPoints`, zuletzt das Ende.
|
||||
| { op: "sectionLineGrip"; id: string; index: number; pt: P }
|
||||
// [151] Parameter-Griff einer Podesttreppe (Kern `grip_drag::stair_param_drag`).
|
||||
| { op: "stairParam"; id: string; index: number; pt: P }
|
||||
| { op: "excavationEdge"; id: string; a: number; b: number; delta: P }
|
||||
|
||||
@@ -1907,6 +1907,7 @@ export const de = {
|
||||
"cmd.sectionline.label": "Schnittlinie",
|
||||
"cmd.sectionline.start": "Schnitt-Startpunkt:",
|
||||
"cmd.sectionline.end": "Schnitt-Endpunkt:",
|
||||
"cmd.sectionline.next": "Knickpunkt oder Endpunkt (Enter/Doppelklick beendet):",
|
||||
"cmd.sectionline.kind.section": "Schnitt",
|
||||
"cmd.sectionline.kind.elevation": "Ansicht",
|
||||
"cmd.sectionline.newSection": "Schnitt {letter}",
|
||||
|
||||
@@ -1896,6 +1896,7 @@ export const en: Record<TranslationKey, string> = {
|
||||
"cmd.sectionline.label": "Section line",
|
||||
"cmd.sectionline.start": "Section start point:",
|
||||
"cmd.sectionline.end": "Section end point:",
|
||||
"cmd.sectionline.next": "Bend point or end point (Enter/double-click finishes):",
|
||||
"cmd.sectionline.kind.section": "Section",
|
||||
"cmd.sectionline.kind.elevation": "Elevation",
|
||||
"cmd.sectionline.newSection": "Section {letter}",
|
||||
|
||||
@@ -108,6 +108,8 @@ export function levelArg(level: DrawingLevel) {
|
||||
return {
|
||||
kind: level.kind,
|
||||
linePoints: level.linePoints,
|
||||
// [176] Knickpunkte (geknickter Schnitt, Abwicklung im Kern `plan/section/unfold.rs`).
|
||||
bendPoints: level.bendPoints,
|
||||
directionSign: level.directionSign,
|
||||
depth: level.depth,
|
||||
shadows: level.shadows,
|
||||
|
||||
@@ -386,6 +386,8 @@ export interface ProjectSlice {
|
||||
moveCeilingGrip: (ceilingId: string, index: number, pt: Vec2) => void;
|
||||
/** [68] Baugrube: Umriss-Ecke ziehen (Index = Ecke; Index = Eckenzahl: Sohlenhöhe). */
|
||||
moveExcavationGrip: (id: string, index: number, pt: Vec2) => void;
|
||||
/** [176] Griff einer Schnittlinie: 0 = Anfang, dann die Knickpunkte, zuletzt das Ende. */
|
||||
moveSectionLineGrip: (id: string, index: number, pt: Vec2) => void;
|
||||
moveExcavationEdge: (id: string, aIndex: number, bIndex: number, delta: Vec2) => void;
|
||||
/** Verschiebt eine Decke (ganzer Umriss) um `delta`. */
|
||||
moveCeilingBy: (ceilingId: string, delta: Vec2) => void;
|
||||
@@ -1240,6 +1242,7 @@ export function createProjectSlice(
|
||||
applyGrip({ op: "ceilingGrip", id: ceilingId, index, pt: gripPt(pt) }, `moveCeilingGrip:${ceilingId}:${index}`),
|
||||
|
||||
moveExcavationGrip: (id, index, pt) => applyGrip({ op: "excavationGrip", id, index, pt: gripPt(pt) }, `moveExcavationGrip:${id}:${index}`),
|
||||
moveSectionLineGrip: (id, index, pt) => applyGrip({ op: "sectionLineGrip", id, index, pt: gripPt(pt) }, `moveSectionLineGrip:${id}:${index}`),
|
||||
|
||||
moveExcavationEdge: (id, aIndex, bIndex, delta) =>
|
||||
applyGrip({ op: "excavationEdge", id, a: aIndex, b: bIndex, delta: gripPt(delta) }, `moveExcavationEdge:${id}:${aIndex}:${bIndex}`),
|
||||
|
||||
@@ -176,6 +176,13 @@ export function useGripEditing(opts: {
|
||||
// [149] Baum: Griff in der Stammmitte (verschieben) und am Kronenrand (Kronendurchmesser).
|
||||
const selectedTreeId = single(selection, "trees");
|
||||
const selectedTree = selectedTreeId ? (project.trees ?? []).find((x) => x.id === selectedTreeId) : undefined;
|
||||
// [176] Schnitt-/Ansichtslinie im Grundriss: Griffe an Anfang, Knickpunkten (`bendPoints`) und Ende.
|
||||
const selectedSectionLineId = single(selection, "sectionLines");
|
||||
const selectedSectionLine = modelEditable && selectedSectionLineId
|
||||
? project.drawingLevels.find((l) => l.id === selectedSectionLineId && l.linePoints)
|
||||
: undefined;
|
||||
const sectionLineGrips = (l: NonNullable<typeof selectedSectionLine>): Vec2[] =>
|
||||
l.linePoints ? [l.linePoints[0], ...(l.bendPoints ?? []), l.linePoints[1]] : [];
|
||||
// Mit gezeigter Beschriftung dazu ihr Griff (`labelOffset`, s. `treeGrips.ts`).
|
||||
const treeGrips = (tr: NonNullable<typeof selectedTree>): Vec2[] => treeGripPoints(tr, scaleDenominator);
|
||||
const selectedRoomId = single(selection, "rooms");
|
||||
@@ -315,6 +322,11 @@ export function useGripEditing(opts: {
|
||||
pts.forEach((_, i) => { gripOwners.push({ localIndex: i }); gripOwnerRange.push([0, pts.length - 1]); });
|
||||
return pts;
|
||||
}
|
||||
if (selectedSectionLine && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) {
|
||||
const pts = sectionLineGrips(selectedSectionLine);
|
||||
pts.forEach((_, i) => { gripOwners.push({ localIndex: i }); gripOwnerRange.push([0, pts.length - 1]); });
|
||||
return pts;
|
||||
}
|
||||
// [68] Baugrube: Umriss-Ecken + Sohlen-Griff (Lage: Schwerpunkt, y um die Sohlenhöhe versetzt).
|
||||
if (modelEditable && selectedExcavation && !selectedCeiling && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) {
|
||||
const pts = excavationGripPoints(selectedExcavation);
|
||||
@@ -911,6 +923,11 @@ export function useGripEditing(opts: {
|
||||
storeState().applyChange((p) => patchItem(p, "trees", tr.id, patch), `treeGrip:${tr.id}:${index}`);
|
||||
return;
|
||||
}
|
||||
// [176] Schnittlinie: Endpunkt bzw. Knickpunkt live, ein Undo-Schritt je Zug (Kern `grips.rs`).
|
||||
if (selectedSectionLine && effectiveDrawingIds.length === 0 && selectedWallIds.length === 0) {
|
||||
storeState().moveSectionLineGrip(selectedSectionLine.id, index, pt);
|
||||
return;
|
||||
}
|
||||
// [68] Baugrube: Sohlen-Griff sofort (Höhe), Ecken als Vorschau bis zum Setzen.
|
||||
if (selectedExcavation && !selectedCeilingId && !selectedRoomId) {
|
||||
if (index >= selectedExcavation.outline.length) moveExcavationGrip(selectedExcavation.id, index, pt);
|
||||
|
||||
Reference in new issue
Block a user