[K4] S3 Split und Segment löschen im Kern (cmd_split.rs); Segment löschen ersetzt jetzt an Ort und Stelle
cutSegment lieferte ein Element mit neuer id als replace: der Kern hängte es an, das Original blieb stehen. Jetzt behält das Element id und Attribute. TS-Rechnung, Kernel-Fassaden und k2_*-Bindungen für Split/Segment löschen gelöscht. Gleichheit (einmalig, Test gelöscht): 2808 Split- und 9000 Segment-Fälle.
This commit is contained in:
11 files changed
+528
-513
No files matched your search
@@ -45,45 +45,12 @@ function encPts(pts: Vec2[]): Float64Array {
|
||||
return out;
|
||||
}
|
||||
|
||||
/** Fehlende/`null`-Einträge → 0 (Gerade), wie im Rust-Kern. */
|
||||
function encBulge(bulge: (number | undefined)[] | undefined): Float64Array {
|
||||
return Float64Array.from(bulge ?? [], (b) => b ?? 0);
|
||||
}
|
||||
|
||||
/** Liste von Punktlisten: `[n, (n_pts, xy…)…]`. */
|
||||
function encPtLists(lists: Vec2[][]): Float64Array {
|
||||
const out: number[] = [lists.length];
|
||||
for (const l of lists) {
|
||||
out.push(l.length);
|
||||
for (const p of l) out.push(p.x, p.y);
|
||||
}
|
||||
return Float64Array.from(out);
|
||||
}
|
||||
|
||||
function decPts(buf: Float64Array, from = 0, count = (buf.length - from) / 2): Vec2[] {
|
||||
const out: Vec2[] = [];
|
||||
for (let k = 0; k < count; k++) out.push({ x: buf[from + 2 * k], y: buf[from + 2 * k + 1] });
|
||||
return out;
|
||||
}
|
||||
|
||||
function decPtLists(buf: Float64Array): Vec2[][] {
|
||||
const n = buf[0] ?? 0;
|
||||
const out: Vec2[][] = [];
|
||||
let i = 1;
|
||||
for (let k = 0; k < n; k++) {
|
||||
const m = buf[i++];
|
||||
out.push(decPts(buf, i, m));
|
||||
i += 2 * m;
|
||||
}
|
||||
return out;
|
||||
}
|
||||
|
||||
/** `[n_pts, xy…, bulge…]`. */
|
||||
function decPtsBulge(buf: Float64Array): { pts: Vec2[]; bulge: number[] } {
|
||||
const n = buf[0] ?? 0;
|
||||
return { pts: decPts(buf, 1, n), bulge: Array.from(buf.subarray(1 + 2 * n)) };
|
||||
}
|
||||
|
||||
// ── Punkt/Strecke, Fläche ───────────────────────────────────────────────────
|
||||
|
||||
/** Abstand von p zur Strecke a→b. */
|
||||
@@ -164,56 +131,3 @@ export function filletCorner(corner: Vec2, p1: Vec2, p2: Vec2, r: number): Fille
|
||||
endAngle: f[8],
|
||||
};
|
||||
}
|
||||
|
||||
// ── Split / Segment löschen ─────────────────────────────────────────────────
|
||||
|
||||
/**
|
||||
* Teilt eine Polylinie an P = lerp(pts[edgeIndex], pts[edgeIndex+1], t). Offen → zwei
|
||||
* offene Stücke; geschlossen → eine offene, bei P aufgeschnittene Polylinie.
|
||||
*/
|
||||
export function splitPolylineAtParam(pts: Vec2[], closed: boolean, edgeIndex: number, t: number): Vec2[][] {
|
||||
return decPtLists(core().k2_split_polyline_at_param(encPts(pts), closed, edgeIndex, t));
|
||||
}
|
||||
|
||||
/**
|
||||
* Teilt ein geschlossenes Polygon an zwei Randpunkten (Kanten i/j, Parameter ti/tj) über die
|
||||
* Sehne in zwei geschlossene Polygone; null bei i==j.
|
||||
*/
|
||||
export function splitClosedByChord(
|
||||
pts: Vec2[],
|
||||
i: number,
|
||||
ti: number,
|
||||
j: number,
|
||||
tj: number,
|
||||
): [Vec2[], Vec2[]] | null {
|
||||
const r = decPtLists(core().k2_split_closed_by_chord(encPts(pts), i, ti, j, tj));
|
||||
return r.length === 2 ? [r[0], r[1]] : null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Entfernt das Segment `edgeIndex`. Offen: innere Kante → das punktreichere Stück bleibt,
|
||||
* Randkante → End-Vertex fällt weg. Geschlossen: an der Kante zur offenen Polylinie aufgetrennt.
|
||||
*/
|
||||
export function removeSegment(pts: Vec2[], closed: boolean, edgeIndex: number): { pts: Vec2[]; closed: boolean } {
|
||||
return { pts: decPts(core().k2_remove_segment(encPts(pts), closed, edgeIndex)), closed: false };
|
||||
}
|
||||
|
||||
/** Wie {@link removeSegment}, trägt aber das bulge-Array mit (bulge bleibt an seinem Punktepaar). */
|
||||
export function removeSegmentWithBulge(
|
||||
pts: Vec2[],
|
||||
bulge: number[],
|
||||
closed: boolean,
|
||||
edgeIndex: number,
|
||||
): { pts: Vec2[]; closed: boolean; bulge: number[] } {
|
||||
const r = decPtsBulge(core().k2_remove_segment_with_bulge(encPts(pts), encBulge(bulge), closed, edgeIndex));
|
||||
return { pts: r.pts, closed: false, bulge: r.bulge };
|
||||
}
|
||||
|
||||
/**
|
||||
* Teilt das Ziel an allen Schnittpunkten mit `others`. Geschlossen + genau zwei Schnitte →
|
||||
* zwei geschlossene Polygone; offen → Stücke an den Schnittpunkten.
|
||||
*/
|
||||
export function splitAtIntersections(targetPts: Vec2[], closed: boolean, others: Vec2[][]): Vec2[][] {
|
||||
return decPtLists(core().k2_split_at_intersections(encPts(targetPts), closed, encPtLists(others)));
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user