[K3c] Kern merkt sich vorbereitete Schnitte: Darstellung/Sichtbarkeit umschalten ohne Neurechnen
computeSection vergibt einen Schlüssel; sectionPlan rechnet nur beim ersten Mal (wenige Einträge, älteste fallen weg). Gleichheitstest prüft alle Optionssätze auf demselben vorbereiteten Schnitt. Umschalten Kacheln 8x8: ~1 ms statt ~110 ms.
This commit is contained in:
5 files changed
+77
-11
No files matched your search
@@ -51,7 +51,11 @@ it.skipIf(!process.env.BENCH)("Messung Schnitt/Ansicht alt gegen neu", async ()
|
||||
const b = await time(newP, runs);
|
||||
const c = skipOld ? ([NaN, NaN] as [number, number]) : await time(async () => planToRenderScene(await oldP(), 100), runs);
|
||||
const d = await time(async () => planToRenderScene(await newP(), 100), runs);
|
||||
rows.push(`${name} | ${l.id} Schnitt | ${fmt(a)} | ${fmt(b)} | ${fmt(c)} | ${fmt(d)}`);
|
||||
// Umschalten (Schwarz-Weiss) auf einem vorbereiteten Schnitt: der Kern rechnet nicht neu.
|
||||
const prepared = (await newCompute(p, l))!;
|
||||
let flip = false;
|
||||
const e = await time(() => newGen(prepared, (flip = !flip), { hiddenLines: l.hiddenLines, visibleCodes: codes, openings: true }), runs);
|
||||
rows.push(`${name} | ${l.id} Schnitt | ${fmt(a)} | ${fmt(b)} | ${fmt(c)} | ${fmt(d)} | Umschalten ${fmt(e)}`);
|
||||
process.stderr.write(rows[rows.length - 1] + "\n");
|
||||
} else {
|
||||
const skipOld = !!process.env.BENCH_NEW_ONLY;
|
||||
|
||||
@@ -16,11 +16,15 @@ import type { CategoryDisplayResolver, Plan } from "./generatePlan";
|
||||
export interface SectionOutput {
|
||||
project: Project;
|
||||
level: DrawingLevel;
|
||||
/** `[mono, openings, n, (index, nPos, pos…, nIdx, idx…) × n]`: Platz für die zwei Schalter, dann die
|
||||
* geschnittenen freien Körper. */
|
||||
/** `[mono, openings, key, n, (index, nPos, pos…, nIdx, idx…) × n]`: Platz für die zwei Schalter, der
|
||||
* Schlüssel dieses Schnitts (der Kern merkt sich die zuletzt berechneten, Umschalten von Darstellung
|
||||
* oder Sichtbarkeit rechnet nicht neu), dann die geschnittenen freien Körper. */
|
||||
bodies: Float64Array;
|
||||
}
|
||||
|
||||
/** Schlüssel der vorbereiteten Schnitte (s. `SectionOutput.bodies`). */
|
||||
let sectionKey = 0;
|
||||
|
||||
/** Ob die Ebene eine gültige Schnittlinie trägt (wie `sectionPlaneFromLevel`). */
|
||||
function hasLine(level: DrawingLevel): boolean {
|
||||
const line = level.linePoints;
|
||||
@@ -39,7 +43,7 @@ function isVoid(s: NonNullable<Project["extrudedSolids"]>[number]): boolean {
|
||||
*/
|
||||
export async function computeSection(project: Project, level: DrawingLevel): Promise<SectionOutput | null> {
|
||||
if (!hasLine(level)) return null;
|
||||
const bodies: number[] = [0, 0, 0];
|
||||
const bodies: number[] = [0, 0, ++sectionKey, 0];
|
||||
const solids = project.extrudedSolids ?? [];
|
||||
for (let index = 0; index < solids.length; index++) {
|
||||
const solid = solids[index];
|
||||
@@ -62,7 +66,7 @@ export async function computeSection(project: Project, level: DrawingLevel): Pro
|
||||
for (let i = 0; i < mesh.positions.length; i++) bodies.push(mesh.positions[i]);
|
||||
bodies.push(mesh.indices.length);
|
||||
for (let i = 0; i < mesh.indices.length; i++) bodies.push(mesh.indices[i]);
|
||||
bodies[2]++;
|
||||
bodies[3]++;
|
||||
}
|
||||
return { project, level, bodies: Float64Array.from(bodies) };
|
||||
}
|
||||
|
||||
@@ -82,12 +82,19 @@ async function oldPlan(project: Project, level: DrawingLevel, o: Opts): Promise<
|
||||
}
|
||||
|
||||
async function newPlan(project: Project, level: DrawingLevel, o: Opts): Promise<{ prims: Primitive[]; bounds: Plan["bounds"]; plan: Plan } | null> {
|
||||
const out = await newCompute(project, level);
|
||||
// Ein vorbereiteter Schnitt je Ebene für alle Optionssätze: prüft auch den Kern-Cache (Umschalten).
|
||||
let out = prepared.get(level);
|
||||
if (out === undefined || out?.project !== project) {
|
||||
out = await newCompute(project, level);
|
||||
prepared.set(level, out);
|
||||
}
|
||||
if (!out) return null;
|
||||
const plan = newGen(out, o.mono, o);
|
||||
return { prims: plan.primitives, bounds: plan.bounds, plan };
|
||||
}
|
||||
|
||||
const prepared = new WeakMap<DrawingLevel, Awaited<ReturnType<typeof newCompute>>>();
|
||||
|
||||
/** Szene (render2d) und SVG wie die Verbraucher: alt als gewöhnlicher Plan, neu aus dem Puffer. */
|
||||
function outputsDiffer(a: { prims: Primitive[]; raw: Primitive[]; bounds: Plan["bounds"] }, b: Plan): string | null {
|
||||
const sa = JSON.stringify(planToRenderScene({ primitives: a.prims, bounds: a.bounds }, 100));
|
||||
|
||||
Reference in new issue
Block a user