[C1][C2] DXF/DWG-Import: Polylinien mit Bögen bleiben Polylinie mit bulge statt fein zerlegt
- import.rs: LWPOLYLINE/POLYLINE2D und Schraffur-Ränder aus genau einer Polylinie liefern zusätzlich die Stützpunkte mit Bulge (Contour::bulge_verts, Kodierung Flag 8), abgebildet und in Metern; gespiegelte Blöcke drehen das Vorzeichen, verzerrte (ungleich skaliert) behalten nur die Tessellierung. - dxfToDrawings: daraus Drawing2D-Polylinie mit bulge; Vorzeichen umgekehrt (Modell: Scheitel links der Sehne, DXF: Gegenuhrzeigersinn), geprüft gegen die Tessellierung des Imports. - Kataster: Strassenparzelle mit 120 Bögen hat 120 statt 600 Stützpunkte und Griffe an den Bogen-Mitten. Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
5 files changed
+331
-9
No files matched your search
@@ -0,0 +1,96 @@
|
||||
// Kataster-Fund 29.10.: LWPOLYLINE mit Bögen (Bulges) kommen als Polylinie MIT `bulge` in die
|
||||
// 2D-Zeichnung statt fein zerlegt — wenige Stützpunkte, Griffe an Ecken und Bogen-Mitten.
|
||||
|
||||
import { beforeAll, describe, expect, it } from "vitest";
|
||||
import { parseDxf } from "./dxfParser";
|
||||
import { loadFileioForTests } from "../engine/fileioWasm.testing";
|
||||
import { contoursToDrawings } from "./dxfToDrawings";
|
||||
import { bulgePolylinePoints } from "../geometry/bulge";
|
||||
import type { Vec2 } from "../model/types";
|
||||
|
||||
beforeAll(loadFileioForTests);
|
||||
|
||||
function dxf(...entities: string[][]): string {
|
||||
const lines = ["0", "SECTION", "2", "ENTITIES"];
|
||||
for (const pairs of entities) lines.push(...pairs);
|
||||
lines.push("0", "ENDSEC", "0", "EOF");
|
||||
return lines.join("\n");
|
||||
}
|
||||
|
||||
/** Parzelle in LV95 (30 × 30 m), Unterkante leicht nach aussen gewölbt, Oberkante nach innen. */
|
||||
const PARZELLE = [
|
||||
"0", "LWPOLYLINE", "8", "Liegenschaften", "90", "4", "70", "1",
|
||||
"10", "2600000", "20", "1200000", "42", "0.12",
|
||||
"10", "2600030", "20", "1200000",
|
||||
"10", "2600030", "20", "1200030", "42", "-0.25",
|
||||
"10", "2600000", "20", "1200030",
|
||||
];
|
||||
|
||||
const toDrawings = (src: string) => contoursToDrawings(parseDxf(src).contours, "L", "active", "01", () => "01");
|
||||
|
||||
describe("DXF-Import: Polylinien mit Bögen", () => {
|
||||
it("bleiben eine Polylinie mit den DXF-Stützpunkten und Bulges", () => {
|
||||
const [d] = toDrawings(dxf(PARZELLE));
|
||||
expect(d.geom.shape).toBe("polyline");
|
||||
if (d.geom.shape !== "polyline") return;
|
||||
expect(d.geom.pts).toEqual([
|
||||
{ x: 2600000, y: 1200000 },
|
||||
{ x: 2600030, y: 1200000 },
|
||||
{ x: 2600030, y: 1200030 },
|
||||
{ x: 2600000, y: 1200030 },
|
||||
]);
|
||||
// Vorzeichen umgekehrt: Modell-Bulge > 0 = Scheitel links der Sehne, DXF > 0 = Gegenuhrzeigersinn.
|
||||
expect(d.geom.bulge).toEqual([-0.12, 0, 0.25, 0]);
|
||||
expect(d.geom.closed).toBe(true);
|
||||
});
|
||||
|
||||
it("gleiche Bogen-Seite wie die Tessellierung des Imports (Vorzeichen DXF ↔ Modell)", () => {
|
||||
const contour = parseDxf(dxf(PARZELLE)).contours[0].contours[0];
|
||||
const [d] = toDrawings(dxf(PARZELLE));
|
||||
if (d.geom.shape !== "polyline") throw new Error("Polylinie erwartet");
|
||||
const ours = bulgePolylinePoints(d.geom.pts, d.geom.bulge, true);
|
||||
// Jeder Punkt der Import-Tessellierung liegt auf dem Linienzug der Modell-Polylinie (≤ 15 cm: Sehnenfehler der gröberen Modell-Tessellierung; die falsche Seite läge Meter daneben).
|
||||
const dist = (p: Vec2) => {
|
||||
let best = Infinity;
|
||||
for (let i = 0; i < ours.length; i++) {
|
||||
const a = ours[i];
|
||||
const b = ours[(i + 1) % ours.length];
|
||||
const dx = b.x - a.x;
|
||||
const dy = b.y - a.y;
|
||||
const t = Math.max(0, Math.min(1, ((p.x - a.x) * dx + (p.y - a.y) * dy) / (dx * dx + dy * dy || 1)));
|
||||
best = Math.min(best, Math.hypot(a.x + t * dx - p.x, a.y + t * dy - p.y));
|
||||
}
|
||||
return best;
|
||||
};
|
||||
for (const p of contour.pts) expect(dist(p)).toBeLessThan(0.15);
|
||||
// Die Unterkante wölbt sich nach aussen (DXF: Bulge > 0 von links nach rechts = Gegenuhrzeigersinn).
|
||||
expect(Math.min(...ours.map((p) => p.y))).toBeLessThan(1_200_000 - 1);
|
||||
});
|
||||
|
||||
it("offener Bogen aus zwei Punkten wird Polylinie (keine Linie)", () => {
|
||||
const [d] = toDrawings(
|
||||
dxf(["0", "LWPOLYLINE", "8", "0", "90", "2", "70", "0", "10", "0", "20", "0", "42", "1", "10", "2", "20", "0"]),
|
||||
);
|
||||
expect(d.geom).toEqual({ shape: "polyline", pts: [{ x: 0, y: 0 }, { x: 2, y: 0 }], closed: false, bulge: [-1, 0] });
|
||||
});
|
||||
|
||||
it("Schraffur mit Bogen-Rand: gefüllte Polylinie mit Bulges", () => {
|
||||
const [d] = toDrawings(
|
||||
dxf([
|
||||
"0", "HATCH", "8", "BB", "2", "SOLID", "70", "1", "91", "1", "92", "3", "72", "1", "73", "1", "93", "3",
|
||||
"10", "0", "20", "0", "42", "0.3", "10", "10", "20", "0", "42", "0", "10", "10", "20", "10", "42", "0", "97", "0",
|
||||
]),
|
||||
);
|
||||
expect(d.fillColor).toBeDefined();
|
||||
if (d.geom.shape !== "polyline") throw new Error("Polylinie erwartet");
|
||||
expect(d.geom.pts).toHaveLength(3);
|
||||
expect(d.geom.bulge).toEqual([-0.3, 0, 0]);
|
||||
});
|
||||
|
||||
it("ohne Bögen unverändert: Linienzug ohne `bulge`", () => {
|
||||
const [d] = toDrawings(
|
||||
dxf(["0", "LWPOLYLINE", "8", "0", "90", "3", "70", "0", "10", "0", "20", "0", "10", "1", "20", "0", "10", "1", "20", "1"]),
|
||||
);
|
||||
expect(d.geom).toEqual({ shape: "polyline", pts: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 1 }], closed: false });
|
||||
});
|
||||
});
|
||||
+22
-1
@@ -17,7 +17,7 @@
|
||||
// `parseDxf` ist synchron und verlangt das geladene Modul (`loadFileio()`); die App ruft es im
|
||||
// Web-Worker (`dxfParserAsync.ts`), Tests laden es per `loadFileioForTests()`.
|
||||
|
||||
import type { Contour, ContourSet, ImportedMesh, ImportedText } from "../model/types";
|
||||
import type { Contour, ContourSet, ImportedMesh, ImportedText, Vec2 } from "../model/types";
|
||||
import { GENERIC_IMPORT_CATEGORY } from "../model/contextCategories";
|
||||
import { fileioLoaded } from "../engine/fileioWasm";
|
||||
|
||||
@@ -65,6 +65,16 @@ export interface DxfImportResult {
|
||||
recovered?: boolean;
|
||||
}
|
||||
|
||||
/**
|
||||
* Kontur aus dem DXF/DWG-Import. Polylinien mit Bögen (LWPOLYLINE/POLYLINE, Schraffur-Rand aus einer
|
||||
* Polylinie) tragen zusätzlich ihre Stützpunkte mit Bulge (DXF-Konvention = `Drawing2DGeom` polyline
|
||||
* `bulge`): die 2D-Zeichnung bekommt echte Bögen statt des tessellierten `pts` (Kataster-Fund 29.10.:
|
||||
* Strassenparzellen mit hunderten Zerlegungspunkten). Nur beim Import gebraucht, nicht im Modell.
|
||||
*/
|
||||
export interface ImportContour extends Contour {
|
||||
bulgePolyline?: { pts: Vec2[]; bulge: number[] };
|
||||
}
|
||||
|
||||
let importSeq = 0;
|
||||
const nextId = (prefix: string, idPrefix: string) => `${idPrefix}${prefix}-${Date.now()}-${importSeq++}`;
|
||||
|
||||
@@ -141,6 +151,17 @@ export function decodeImport(geom: Float64Array, strings: readonly string[], idP
|
||||
for (let p = 0; p < np; p++) pts[p] = { x: geom[i + 2 * p], y: geom[i + 2 * p + 1] };
|
||||
i += 2 * np;
|
||||
c.pts = pts;
|
||||
if (flags & 8) {
|
||||
const nv = num();
|
||||
const vpts: Vec2[] = new Array(nv);
|
||||
const bulge: number[] = new Array(nv);
|
||||
for (let v = 0; v < nv; v++) {
|
||||
vpts[v] = { x: geom[i + 3 * v], y: geom[i + 3 * v + 1] };
|
||||
bulge[v] = geom[i + 3 * v + 2];
|
||||
}
|
||||
i += 3 * nv;
|
||||
(c as ImportContour).bulgePolyline = { pts: vpts, bulge };
|
||||
}
|
||||
contours.push(c);
|
||||
}
|
||||
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
// Bezeichner englisch, Kommentare deutsch (CONVENTIONS.md).
|
||||
|
||||
import type { Contour, ContourSet, Drawing2D, Drawing2DGeom, ImportedText, LayerCategory } from "../model/types";
|
||||
import type { ImportContour } from "./dxfParser";
|
||||
|
||||
/** Wie DXF-Layer auf Kategorien abgebildet werden. */
|
||||
export type CategoryMode = "active" | "byLayer";
|
||||
@@ -115,6 +116,20 @@ function contourGeom(contour: Contour): Drawing2DGeom | null {
|
||||
}
|
||||
return { shape: "arc", center: { x: c.cx, y: c.cy }, r: c.r, a0: c.a0, a1: c.a1 };
|
||||
}
|
||||
// Polylinie mit Bögen (DXF-Bulges): Stützpunkte + `bulge` statt des tessellierten Linienzugs.
|
||||
// VORZEICHEN: In DXF heisst Bulge > 0 „Bogen im Gegenuhrzeigersinn von a nach b" (Scheitel rechts
|
||||
// der Sehne), im Modell liegt der Scheitel bei Bulge > 0 LINKS der Sehne (`kernel2d/src/bulge.rs`,
|
||||
// Links-Normale) — also umgekehrt. Geprüft in `dxfBulgeImport.test.ts` gegen die Tessellierung des
|
||||
// Imports.
|
||||
const bp = (contour as ImportContour).bulgePolyline;
|
||||
if (bp && bp.pts.length >= 2 && bp.bulge.length === bp.pts.length) {
|
||||
return {
|
||||
shape: "polyline",
|
||||
pts: bp.pts.map((p) => ({ ...p })),
|
||||
closed: contour.closed,
|
||||
bulge: bp.bulge.map((b) => (b === 0 ? 0 : -b)),
|
||||
};
|
||||
}
|
||||
const pts = contour.pts;
|
||||
if (pts.length < 2) return null;
|
||||
if (pts.length === 2 && !contour.closed) {
|
||||
|
||||
Reference in new issue
Block a user