[32] Strichstaerken nach Massstab: Projekt-Option skaliert alle Grundriss-Staerken mit (100/n)^0.25
- plan/lineWeightScale.ts: Faktor (begrenzt 0.5..1.6), Klone je Primitiv gecacht (GPU-Chunk-Cache bleibt wirksam); generatePlan wendet ihn auf Primitive und die kompakte Linien-Unterlage an - Einstellungen > Projekt: Schalter, auch im nativen Einstellungsfenster (Sync-Bruecke) - Layout-PDF erzeugt Viewport-Plaene jetzt mit dem Viewport-Massstab (wie die Layout-Vorschau) und ohne noPrint-Elemente; Plan-Export PDF/SVG und CLI plan mit dem Export-Massstab statt fest 1:100 - Tests Claude-Session: https://claude.ai/code/session_01NTYBZBvLYCtugMJoKXaB67
This commit is contained in:
15 files changed
+168
-8
No files matched your search
@@ -74,6 +74,7 @@ import { subtractVoidsInPlan } from "./voids";
|
||||
import { addContextContours } from "./generatePlan/context";
|
||||
import { addSunShadow } from "./generatePlan/sunShadow";
|
||||
import { addSiteRules, addSiteViolations } from "./generatePlan/siteRules";
|
||||
import { lineWeightFactor, scalePrimitiveWeights } from "./lineWeightScale";
|
||||
import { DEFAULT_SCALE_DENOMINATOR } from "../model/dimension";
|
||||
import {
|
||||
addDrawing2D,
|
||||
@@ -683,11 +684,22 @@ export function generatePlan(
|
||||
filters: o.filters,
|
||||
}));
|
||||
|
||||
// Strichstärken nach Massstab ([32], nur mit Projekt-Option): auf die fertigen Primitive und
|
||||
// auf die Linien der kompakten Unterlage.
|
||||
const lwf = lineWeightFactor(project, scaleDenominator);
|
||||
const scaledUnderlay =
|
||||
lwf === 1
|
||||
? underlay
|
||||
: underlay.map((g) => ({
|
||||
...g,
|
||||
ctx: [...g.ctx, lwf],
|
||||
build: (ds: Drawing2D[]) => g.build(ds).map((p) => scalePrimitiveWeights(p, lwf)),
|
||||
}));
|
||||
return {
|
||||
primitives,
|
||||
primitives: lwf === 1 ? primitives : primitives.map((p) => scalePrimitiveWeights(p, lwf)),
|
||||
bounds: computeBounds(project, walls, drawings, ceilings, stairs, rooms, roofs, primitives.slice(0, underlayCount)),
|
||||
backgroundImages,
|
||||
...(underlay.length ? { underlay } : {}),
|
||||
...(scaledUnderlay.length ? { underlay: scaledUnderlay } : {}),
|
||||
};
|
||||
}
|
||||
|
||||
|
||||
@@ -0,0 +1,58 @@
|
||||
/**
|
||||
* [32] Strichstärken nach Massstab: Faktor (100/n)^0.25 auf alle Papier-mm-Stärken des Grundrisses,
|
||||
* nur mit `Project.scaleLineWeights`.
|
||||
*/
|
||||
|
||||
import { describe, expect, it } from "vitest";
|
||||
import { generatePlan, materializeUnderlay } from "./generatePlan";
|
||||
import { lineWeightFactor } from "./lineWeightScale";
|
||||
import { sampleProject } from "../model/sampleProject";
|
||||
import { flattenCategories } from "../model/types";
|
||||
import type { Project } from "../model/types";
|
||||
import type { Primitive } from "./generatePlan/shared";
|
||||
|
||||
const ALL = new Set(flattenCategories(sampleProject.layers).map((c) => c.code));
|
||||
const on: Project = { ...sampleProject, scaleLineWeights: true };
|
||||
const weights = (ps: Primitive[]) =>
|
||||
ps.flatMap((p) => (p.kind === "polygon" ? [p.strokeWidthMm] : "weightMm" in p && typeof p.weightMm === "number" ? [p.weightMm] : []));
|
||||
const plan = (p: Project, n: number, compact = false) =>
|
||||
materializeUnderlay(generatePlan(p, "eg", ALL, undefined, "mittel", false, false, true, n, false, compact));
|
||||
|
||||
describe("Strichstärken nach Massstab", () => {
|
||||
it("Faktor: 1 bei 1:100, kleiner bei 1:200, grösser bei 1:50, begrenzt", () => {
|
||||
expect(lineWeightFactor(on, 100)).toBe(1);
|
||||
expect(lineWeightFactor(on, 200)).toBeCloseTo(0.5 ** 0.25, 9);
|
||||
expect(lineWeightFactor(on, 50)).toBeCloseTo(2 ** 0.25, 9);
|
||||
expect(lineWeightFactor(on, 100000)).toBe(0.5);
|
||||
expect(lineWeightFactor(sampleProject, 200)).toBe(1);
|
||||
expect(lineWeightFactor(on, Number.NaN)).toBe(1);
|
||||
});
|
||||
it("Grundriss 1:200: jede Stärke × Faktor, aus → unverändert", () => {
|
||||
const base = weights(plan(sampleProject, 200).primitives);
|
||||
const scaled = weights(plan(on, 200).primitives);
|
||||
expect(scaled.length).toBe(base.length);
|
||||
const f = 0.5 ** 0.25;
|
||||
scaled.forEach((w, i) => expect(w).toBeCloseTo(base[i] * f, 9));
|
||||
});
|
||||
it("auch die kompakte Linien-Unterlage (GPU-Ansicht) wird skaliert", () => {
|
||||
const base = weights(plan(sampleProject, 200, true).primitives);
|
||||
const scaled = weights(plan(on, 200, true).primitives);
|
||||
expect(scaled.length).toBe(base.length);
|
||||
scaled.forEach((w, i) => expect(w).toBeCloseTo(base[i] * 0.5 ** 0.25, 9));
|
||||
});
|
||||
it("gleiche Eingabe → dieselben Primitiv-Objekte, wo der Plan sie wiederverwendet (GPU-Cache)", () => {
|
||||
const line = {
|
||||
id: "z1", type: "drawing2d", levelId: "eg", categoryCode: sampleProject.drawings2d[0]?.categoryCode ?? sampleProject.layers[0].code,
|
||||
geom: { shape: "polyline", pts: [{ x: 0, y: 0 }, { x: 3, y: 0 }, { x: 3, y: 2 }], closed: false },
|
||||
} as Project["drawings2d"][number];
|
||||
const shared = (p: Project) => {
|
||||
const a = generatePlan(p, "eg", ALL, undefined, "mittel", false, false, true, 200).primitives;
|
||||
const b = generatePlan(p, "eg", ALL, undefined, "mittel", false, false, true, 200).primitives;
|
||||
const inB = new Set(b);
|
||||
return a.filter((q) => inB.has(q)).length;
|
||||
};
|
||||
const baseShared = shared({ ...sampleProject, drawings2d: [...sampleProject.drawings2d, line] });
|
||||
expect(baseShared).toBeGreaterThan(0);
|
||||
expect(shared({ ...on, drawings2d: [...sampleProject.drawings2d, line] })).toBe(baseShared);
|
||||
});
|
||||
});
|
||||
@@ -0,0 +1,37 @@
|
||||
// Strichstärken nach Massstab ([32]): mit `Project.scaleLineWeights` werden alle Papier-mm-Stärken
|
||||
// eines Grundrisses mit (100/n)^0.25 skaliert — 1:200 ≈ 84 %, 1:50 ≈ 119 % (Vorgabe wie BIMCraft
|
||||
// `pen.rs`). So bleibt ein 1:200-Plan nicht zu schwer und ein 1:50-Plan nicht zu dünn, ohne eigene
|
||||
// Stiftsätze je Massstab.
|
||||
|
||||
import type { Project } from "../model/types";
|
||||
import type { Primitive } from "./generatePlan/shared";
|
||||
|
||||
const REFERENCE_SCALE = 100;
|
||||
const MIN_FACTOR = 0.5;
|
||||
const MAX_FACTOR = 1.6;
|
||||
|
||||
/** Faktor für den Massstab 1:n (1 ohne Option oder bei ungültigem n). */
|
||||
export function lineWeightFactor(project: Project, scaleDenominator: number): number {
|
||||
if (!project.scaleLineWeights || !(scaleDenominator > 0) || !Number.isFinite(scaleDenominator)) return 1;
|
||||
const f = (REFERENCE_SCALE / scaleDenominator) ** 0.25;
|
||||
return Math.min(MAX_FACTOR, Math.max(MIN_FACTOR, f));
|
||||
}
|
||||
|
||||
// Je Quell-Primitiv die zuletzt erzeugte Skalierung: gleiche Eingabe → dasselbe Objekt, damit der
|
||||
// GPU-Chunk-Cache (`glPlanChunks.ts`) Primitive wiedererkennt.
|
||||
const scaledClones = new WeakMap<Primitive, { f: number; clone: Primitive }>();
|
||||
|
||||
/** Primitiv mit skalierten Strichstärken (Original bleibt unverändert). */
|
||||
export function scalePrimitiveWeights(p: Primitive, f: number): Primitive {
|
||||
if (f === 1) return p;
|
||||
const hit = scaledClones.get(p);
|
||||
if (hit && hit.f === f) return hit.clone;
|
||||
const c = { ...p } as Record<string, unknown>;
|
||||
if (typeof c.weightMm === "number") c.weightMm = c.weightMm * f;
|
||||
if (typeof c.strokeWidthMm === "number") c.strokeWidthMm = c.strokeWidthMm * f;
|
||||
const hatch = c.hatch as { lineWeight?: unknown } | undefined;
|
||||
if (hatch && typeof hatch.lineWeight === "number") c.hatch = { ...hatch, lineWeight: hatch.lineWeight * f };
|
||||
const clone = c as unknown as Primitive;
|
||||
scaledClones.set(p, { f, clone });
|
||||
return clone;
|
||||
}
|
||||
Reference in new issue
Block a user