[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
@@ -3,7 +3,8 @@
|
||||
* erhalten bleiben (nicht mehr stillschweigend zu Geraden entarten).
|
||||
*/
|
||||
import { describe, it, expect } from "vitest";
|
||||
import { cutSegment, nearestEdgeIndex } from "./splitJoin";
|
||||
import { cutSegmentOps, splitOps } from "./splitJoin";
|
||||
import { getState } from "../state/appStore";
|
||||
import type { Drawing2D, Project } from "../model/types";
|
||||
import { documentFor } from "../core/document";
|
||||
import { applyOps } from "../core/ops";
|
||||
@@ -67,7 +68,15 @@ describe("Join — bulge-Erhalt", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("cutSegment / nearestEdgeIndex — bulge-Erhalt", () => {
|
||||
/** Segment löschen über den Kern: die geänderte Zeichnung (null = gelöscht). */
|
||||
function cut(src: Drawing2D, at: { x: number; y: number }): Drawing2D | null {
|
||||
const p = { ...sampleProject, drawings2d: [src] } as Project;
|
||||
const next = applyOps(p, cutSegmentOps(p, src.id, at).ops).drawings2d;
|
||||
expect(next.length).toBeLessThanOrEqual(1);
|
||||
return next[0] ?? null;
|
||||
}
|
||||
|
||||
describe("Segment löschen (Kern `cmd_split.rs`) — bulge-Erhalt", () => {
|
||||
it("Segment-Löschen an einer GERADEN Kante lässt den Bogen der Nachbarkante unangetastet (offen)", () => {
|
||||
// 4 Kanten: Bogen(0->1), gerade(1->2), gerade(2->3), gerade(3->4). Löscht Kante 1
|
||||
// (das längere, punktreichere Reststück rechts wird behalten, s. removeSegmentWithBulge).
|
||||
@@ -76,28 +85,58 @@ describe("cutSegment / nearestEdgeIndex — bulge-Erhalt", () => {
|
||||
[{ x: -1, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 }, { x: 3, y: 0 }, { x: 4, y: 0 }],
|
||||
[1, 0, 0, 0],
|
||||
);
|
||||
const out = cutSegment(src, 1);
|
||||
const out = cut(src, { x: 1.5, y: 0.01 });
|
||||
expect(out).not.toBeNull();
|
||||
if (!out || out.geom.shape !== "polyline") return;
|
||||
// Rechtes (längeres) Stück bleibt: [2,0] -> [3,0] -> [4,0], keine Kante mehr mit Bogen.
|
||||
expect(out.geom.pts).toEqual([{ x: 2, y: 0 }, { x: 3, y: 0 }, { x: 4, y: 0 }]);
|
||||
// fromPolyForm lässt das bulge-Feld ganz weg, wenn kein echter Bogen mehr übrig ist.
|
||||
// Das bulge-Feld fällt ganz weg, wenn kein echter Bogen mehr übrig ist.
|
||||
expect(out.geom.bulge).toBeUndefined();
|
||||
});
|
||||
|
||||
it("Segment-Löschen an der BOGEN-Kante selbst entfernt genau diesen Bogen", () => {
|
||||
const src = poly("a", [{ x: -1, y: 0 }, { x: 1, y: 0 }, { x: 2, y: 0 }], [1, 0]);
|
||||
const out = cutSegment(src, 0);
|
||||
expect(out).not.toBeNull();
|
||||
if (!out || out.geom.shape !== "polyline") return;
|
||||
expect(out.geom.pts).toEqual([{ x: 1, y: 0 }, { x: 2, y: 0 }]);
|
||||
expect(out.geom.bulge?.[0] ?? 0).toBeCloseTo(0, 6);
|
||||
});
|
||||
|
||||
it("nearestEdgeIndex trifft die Bogen-Kante auch, wenn der Klickpunkt neben der Sehne liegt (auf dem Bogen)", () => {
|
||||
// Halbkreis von (-1,0) nach (1,0), bulge=1 -> Apex bei (0,1).
|
||||
// Halbkreis (-1,0)→(1,0) mit bulge 1 (Scheitel bei (0,-1)), dann gerade nach (1,2).
|
||||
const src = poly("a", [{ x: -1, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 2 }], [1, 0]);
|
||||
const idx = nearestEdgeIndex(src.geom, { x: 0, y: 0.95 });
|
||||
expect(idx).toBe(0); // Bogen-Kante, nicht die gerade Kante 1
|
||||
// Der Klickpunkt liegt am Bogen, aber näher an der geraden Kante als an der Sehne: getroffen wird
|
||||
// der Bogen (Abstand gegen die Kurve gemessen).
|
||||
const out = cut(src, { x: 0.7, y: -0.65 });
|
||||
expect(out).not.toBeNull();
|
||||
if (!out) return;
|
||||
expect(out.geom).toEqual({ shape: "line", a: { x: 1, y: 0 }, b: { x: 1, y: 2 } });
|
||||
});
|
||||
});
|
||||
|
||||
describe("Segment löschen ersetzt an Ort und Stelle", () => {
|
||||
it("das Element behält id und Attribute, die Liste bleibt gleich lang (Store)", () => {
|
||||
// Früher erzeugte cutSegment ein Element mit NEUER id als `replace` → angehängt, Original blieb.
|
||||
const d: Drawing2D = {
|
||||
id: "p", type: "drawing2d", levelId: "eg", categoryCode: "20", color: "#f00", opacity: 0.5,
|
||||
geom: { shape: "polyline", pts: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 1 }, { x: 2, y: 1 }], closed: false },
|
||||
};
|
||||
getState().loadProject({ ...sampleProject, drawings2d: [d] } as Project);
|
||||
getState().applyChange((p) => cutSegmentOps(p, "p", { x: 1.9, y: 1 }).ops);
|
||||
const after = getState().project.drawings2d;
|
||||
expect(after.length).toBe(1);
|
||||
expect(after[0]).toEqual({ ...d, geom: { shape: "polyline", pts: [{ x: 0, y: 0 }, { x: 1, y: 0 }, { x: 1, y: 1 }], closed: false } });
|
||||
getState().undo();
|
||||
expect(getState().project.drawings2d).toEqual([d]);
|
||||
});
|
||||
});
|
||||
|
||||
describe("Split (Kern `cmd_split.rs`)", () => {
|
||||
it("teilt an den Schnittpunkten, Stücke an der Stelle des Originals, Auswahl = Stücke", () => {
|
||||
const a: Drawing2D = { id: "a", type: "drawing2d", levelId: "eg", categoryCode: "20", geom: { shape: "line", a: { x: 0, y: 0 }, b: { x: 10, y: 0 } } };
|
||||
const b: Drawing2D = { id: "b", type: "drawing2d", levelId: "eg", categoryCode: "20", geom: { shape: "line", a: { x: 4, y: -1 }, b: { x: 4, y: 1 } } };
|
||||
const z: Drawing2D = { id: "z", type: "drawing2d", levelId: "eg", categoryCode: "20", geom: { shape: "circle", center: { x: 0, y: 0 }, r: 1 } };
|
||||
const p = { ...sampleProject, drawings2d: [a, b, z] } as Project;
|
||||
const { ops, selectIds } = splitOps(p, ["a", "z"]);
|
||||
const next = applyOps(p, ops).drawings2d;
|
||||
expect(next.map((d) => d.geom)).toEqual([
|
||||
{ shape: "line", a: { x: 0, y: 0 }, b: { x: 4, y: 0 } },
|
||||
{ shape: "line", a: { x: 4, y: 0 }, b: { x: 10, y: 0 } },
|
||||
b.geom,
|
||||
z.geom,
|
||||
]);
|
||||
expect(new Set(selectIds)).toEqual(new Set(["z", next[0].id, next[1].id]));
|
||||
});
|
||||
});
|
||||
Reference in new issue
Block a user