[K4] Projekt-Verschiebung: nicht endliche Werte ändern nichts (hostile-Test georef)
This commit is contained in:
3 files changed
+16
-6
No files matched your search
@@ -1,7 +1,7 @@
|
||||
import { describe, it, expect } from "vitest";
|
||||
import type { Column, ExtrudedSolid, Project } from "./types";
|
||||
import { sampleProject } from "./sampleProject";
|
||||
import { translateProject, projectToWorldCoords, projectGeoOrigin } from "./geoRebase";
|
||||
import { translateProject, translateOps, projectToWorldCoords, projectGeoOrigin } from "./geoRebase";
|
||||
|
||||
const DX = 100;
|
||||
const DY = -50;
|
||||
@@ -252,3 +252,12 @@ describe("projectGeoOrigin / projectToWorldCoords", () => {
|
||||
expect(world.walls[0].end).toEqual({ x: 2600015, y: 1200020 });
|
||||
});
|
||||
});
|
||||
|
||||
describe("translate: nicht endliche Verschiebung", () => {
|
||||
it("ändert nichts (kein NaN im Modell)", () => {
|
||||
for (const [dx, dy] of [[NaN, 1], [1, Infinity], [-Infinity, NaN]] as const) {
|
||||
expect(translateProject(sampleProject, dx, dy)).toBe(sampleProject);
|
||||
expect(translateOps(sampleProject, dx, dy)).toEqual([]);
|
||||
}
|
||||
});
|
||||
});
|
||||
@@ -29,10 +29,10 @@ import type { Project } from "./types";
|
||||
* (`geoAnchor.model`, damit der LV95-Bezug exakt erhalten bleibt). Richtungs-
|
||||
* Vektoren (z. B. `Stair.dir`) und Winkel-Felder bleiben unangetastet — eine
|
||||
* reine Translation ändert keine Orientierung. Unveränderte Teile behalten ihre Identität;
|
||||
* (0,0) liefert das Projekt selbst.
|
||||
* (0,0) und nicht endliche Werte (NaN, ±Infinity) liefern das Projekt selbst.
|
||||
*/
|
||||
export function translateProject(project: Project, dx: number, dy: number): Project {
|
||||
if (dx === 0 && dy === 0) return project;
|
||||
if ((dx === 0 && dy === 0) || !Number.isFinite(dx) || !Number.isFinite(dy)) return project;
|
||||
const patch = documentFor(project).queryRoot<Partial<Project>>("translatePatch", JSON.stringify([dx, dy]));
|
||||
return { ...project, ...patch };
|
||||
}
|
||||
@@ -40,10 +40,10 @@ export function translateProject(project: Project, dx: number, dy: number): Proj
|
||||
/**
|
||||
* Ops für {@link translateProject}: je geändertem Element ein `replace` (Reihenfolge und Identität
|
||||
* unveränderter Elemente bleiben), `geoAnchor` als Feld. Das Ergebnis von `applyOps` ist gleich
|
||||
* `translateProject(project, dx, dy)`.
|
||||
* `translateProject(project, dx, dy)`. Nicht endliche Werte ergeben keine Ops.
|
||||
*/
|
||||
export function translateOps(project: Project, dx: number, dy: number): CoreOp[] {
|
||||
if (dx === 0 && dy === 0) return [];
|
||||
if ((dx === 0 && dy === 0) || !Number.isFinite(dx) || !Number.isFinite(dy)) return [];
|
||||
return documentFor(project).queryRoot<CoreOp[]>("translateOps", JSON.stringify([dx, dy]));
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user