@rig-c/parts 2.49.1 → 2.51.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +1 -0
- package/cli.ts +245 -11
- package/docs/AUTHORING.md +274 -66
- package/docs/STABILITY.md +116 -18
- package/package.json +3 -2
- package/src/behindseams.ts +164 -11
- package/src/build.ts +2 -0
- package/src/bustlandmarks.ts +656 -0
- package/src/check.ts +306 -52
- package/src/checkrow.ts +1 -0
- package/src/cloth-targets.json +10 -0
- package/src/config.ts +50 -43
- package/src/configwrite.ts +132 -13
- package/src/instruments.ts +2 -2
- package/src/outputpaths.ts +24 -0
- package/src/physicscontrib.ts +311 -0
- package/src/propose.ts +30 -22
package/src/check.ts
CHANGED
|
@@ -11,6 +11,7 @@ import { ART_JOINT_LINE, artJointLine, type ArtJointLine } from './artjoints.ts'
|
|
|
11
11
|
import { BOUNDARY_COLOUR_LINE, BOUNDARY_COLOUR_UNMEASURED_CODE, BOUNDARY_COLOUR_UNMEASURED_SUFFIX, measureBoundaryColour, type BoundaryColourMeasured } from './boundarycolour.ts';
|
|
12
12
|
import { BEHIND_SEAM_LINE, behindTurnAnimations, measureBehindSeams, type BehindSeamsMeasured } from './behindseams.ts';
|
|
13
13
|
import { baseAnchorMoves, type AnchorRegion } from './baseanchor.ts';
|
|
14
|
+
import { PHYSICS_CONTRIBUTES_LINE, measurePhysicsContribution, physicsLine, type PhysicsContributionLine } from './physicscontrib.ts';
|
|
14
15
|
/**
|
|
15
16
|
* The check stage: build a rig through rig-c, gate it under both
|
|
16
17
|
* profiles, render its idle, and measure the two things the gate cannot see —
|
|
@@ -96,8 +97,8 @@ import { createHash } from 'node:crypto';
|
|
|
96
97
|
import { createRequire } from 'node:module';
|
|
97
98
|
import type { Candidate, Piece, Viewport as RootCoverageViewport } from '@rig-c/core/render-shared';
|
|
98
99
|
import { fillHoles } from './raster/morph.ts';
|
|
99
|
-
import { copyFileSync, cpSync, existsSync, mkdirSync, readdirSync, readFileSync, renameSync, rmSync, statSync, writeFileSync } from 'node:fs';
|
|
100
|
-
import { diagnosticSegment, diagnosticSiblings } from './outputpaths.ts';
|
|
100
|
+
import { closeSync, copyFileSync, cpSync, existsSync, mkdirSync, openSync, readdirSync, readFileSync, readSync, renameSync, rmSync, statSync, writeFileSync, writeSync } from 'node:fs';
|
|
101
|
+
import { diagnosticSegment, diagnosticSiblings, unsafeSegmentReason } from './outputpaths.ts';
|
|
101
102
|
import { basename, delimiter, dirname, isAbsolute, join, relative, resolve, sep } from 'node:path';
|
|
102
103
|
import { measureRecomposite, type RecompositeFigures, recompositeRecord, scenePhrase, sourceInRig, figureSilhouette } from './assemble.ts';
|
|
103
104
|
import { type BoneTransform, computeExactFrameTransforms, cropToSpineY, normaliseDegrees, toBoneLocal } from './coords.ts';
|
|
@@ -1070,36 +1071,45 @@ function retainedCheckRenderPlan(source: string) {
|
|
|
1070
1071
|
const bytes = readFileSync(index, 'utf8');
|
|
1071
1072
|
const raw: unknown = JSON.parse(bytes);
|
|
1072
1073
|
if (!isRecord(raw) || !Array.isArray(raw.sets)) return sidecarProblem(index, 'requires a frames.json sets array to retain a render');
|
|
1073
|
-
|
|
1074
|
-
|
|
1075
|
-
|
|
1076
|
-
|
|
1077
|
-
|
|
1078
|
-
|
|
1079
|
-
|
|
1080
|
-
|
|
1081
|
-
const
|
|
1082
|
-
if (
|
|
1083
|
-
|
|
1084
|
-
|
|
1085
|
-
|
|
1086
|
-
|
|
1074
|
+
// Issue #1367: rig-c's render names each frame-set folder (rig-c/core#1744)
|
|
1075
|
+
// and records it under sets[].dir. That value is copied as it is, never
|
|
1076
|
+
// rebuilt from the animation's name; it is joined under the output only once
|
|
1077
|
+
// it is one safe path segment, and two that one case-insensitive
|
|
1078
|
+
// filesystem would make one folder are refused before anything is copied.
|
|
1079
|
+
const problems: Problem[] = [];
|
|
1080
|
+
const folded = new Map<string, { at: number; dir: string }>();
|
|
1081
|
+
const dirs = raw.sets.map((set: unknown, i: number): string => {
|
|
1082
|
+
const which = `${index} sets[${i}]` + (isRecord(set) && typeof set.animation === 'string' ? ` (animation ${JSON.stringify(set.animation)})` : '');
|
|
1083
|
+
if (!isRecord(set)) {
|
|
1084
|
+
problems.push({ code: 'FRAMES_SIDECAR', object: which, detail: 'is not an object; a set record with a "dir" is required to retain a render' });
|
|
1085
|
+
return '';
|
|
1086
|
+
}
|
|
1087
|
+
const why = unsafeSegmentReason(set.dir);
|
|
1088
|
+
if (why !== null) {
|
|
1089
|
+
problems.push({ code: 'FRAMES_SIDECAR', object: which, detail: `"dir" ${set.dir === undefined ? '' : JSON.stringify(set.dir) + ' '}${why}; one path segment of [A-Za-z0-9_@+.~-], not ending in ".", not a Windows device name and at most 255 characters is required to retain a render, as rigc render records it from rig-c/core#1744 on — Parts copies "dir" as it is and maps nothing` });
|
|
1090
|
+
return '';
|
|
1091
|
+
}
|
|
1092
|
+
const dir = set.dir as string;
|
|
1093
|
+
const previous = folded.get(dir.toLowerCase());
|
|
1094
|
+
if (previous !== undefined) {
|
|
1095
|
+
problems.push({ code: 'FRAMES_SIDECAR', object: which, detail: `"dir" ${JSON.stringify(dir)} and sets[${previous.at}] "dir" ${JSON.stringify(previous.dir)} are one folder ${JSON.stringify(dir.toLowerCase())} on a case-insensitive filesystem; distinct case-folded set directories are required to retain a render` });
|
|
1096
|
+
} else folded.set(dir.toLowerCase(), { at: i, dir });
|
|
1097
|
+
return dir;
|
|
1087
1098
|
});
|
|
1088
|
-
|
|
1089
|
-
return { bytes,
|
|
1099
|
+
refuseIfAny(problems);
|
|
1100
|
+
return { bytes, dirs };
|
|
1090
1101
|
}
|
|
1091
1102
|
|
|
1092
|
-
/** Copy a retained render and
|
|
1103
|
+
/** Copy a retained render: each set's folder and `frames.json` as rigc wrote them (issue #1367). */
|
|
1093
1104
|
export function retainCheckRender(source: string, target: string): void {
|
|
1094
|
-
const { bytes,
|
|
1105
|
+
const { bytes, dirs } = retainedCheckRenderPlan(source);
|
|
1095
1106
|
mkdirSync(target, { recursive: true });
|
|
1096
1107
|
// Root sidecars and set-local filenames are fixed renderer protocol names.
|
|
1097
1108
|
for (const entry of readdirSync(source, { withFileTypes: true })) {
|
|
1098
1109
|
if (entry.isFile() && entry.name !== 'frames.json') copyFileSync(join(source, entry.name), join(target, entry.name));
|
|
1099
1110
|
}
|
|
1100
|
-
|
|
1101
|
-
|
|
1102
|
-
writeFileSync(join(target, 'frames.json'), changed ? JSON.stringify({ ...raw, sets }, null, 2) + '\n' : bytes);
|
|
1111
|
+
for (const dir of dirs) cpSync(join(source, dir), join(target, dir), { recursive: true });
|
|
1112
|
+
writeFileSync(join(target, 'frames.json'), bytes);
|
|
1103
1113
|
}
|
|
1104
1114
|
|
|
1105
1115
|
/**
|
|
@@ -2834,6 +2844,8 @@ export interface CheckFigures {
|
|
|
2834
2844
|
[MOTION_SEAM_LINE]?: MotionSeamLine;
|
|
2835
2845
|
/** Written only when the rig declares a physics constraint and has an idle (issue #501): {@link ClothLine}, a warning, never a bar. */
|
|
2836
2846
|
[CLOTH_LINE]?: ClothLine;
|
|
2847
|
+
/** Written only when it reads a part under physics (issue #1320): {@link PhysicsContributionLine}, a warning, never a bar. */
|
|
2848
|
+
[PHYSICS_CONTRIBUTES_LINE]?: PhysicsContributionLine;
|
|
2837
2849
|
[COINCIDE_LINE]?: SupportReport;
|
|
2838
2850
|
RECOMPOSITE_HOLES: ReportedLine;
|
|
2839
2851
|
/** Issue #933: openings inside the figure over motion across undeclared setup-overlapping layer pairs; omitted when SKIP. */
|
|
@@ -3268,6 +3280,8 @@ export interface CheckReport {
|
|
|
3268
3280
|
behindSeams: BehindSeamsMeasured | null;
|
|
3269
3281
|
/** `CLOTH_SETTLES` (issue #501): a warning, never a bar — in `check.json` only when the rig declares a physics constraint and has an idle; its SKIP is printed either way. */
|
|
3270
3282
|
cloth: ClothLine;
|
|
3283
|
+
/** `PHYSICS_CONTRIBUTES` (issue #1320): a warning, never a bar — in `check.json` only when it reads a part under physics; its SKIP is printed either way. */
|
|
3284
|
+
physics?: PhysicsContributionLine;
|
|
3271
3285
|
/** `WIND_BAND` (issue #590): the steady-wind band each declared seam pair holds, written under `--wind-band` only. */
|
|
3272
3286
|
windBand?: WindBandLine;
|
|
3273
3287
|
/**
|
|
@@ -3289,9 +3303,9 @@ export function barsSummary(r: Pick<CheckReport, 'bars'>): string {
|
|
|
3289
3303
|
return `${measured.length} of ${measured.length + skipped.length} bar(s) measured, ${skipped.length} skipped${skipped.length === 0 ? '' : ` (${skipped.map((s) => s.bar).join(', ')})`}`;
|
|
3290
3304
|
}
|
|
3291
3305
|
|
|
3292
|
-
/** The summary's warning clause: each warning line that read something, named, with the warnings they printed together, and `SETUP_PAINTING_MOSTLY_UNCOVERED` only when
|
|
3306
|
+
/** The summary's warning clause: each warning line that read something, named, with the warnings they printed together, and `PHYSICS_CONTRIBUTES` (issue #1320) and `SETUP_PAINTING_MOSTLY_UNCOVERED` only when they printed one (issue #1421); empty when none read. */
|
|
3293
3307
|
export function warningsClause(r: Pick<CheckReport, 'motionSeam' | 'cloth' | 'figures'>): string {
|
|
3294
|
-
const read = [...(r.motionSeam.status === 'SKIP' || (r.motionSeam.roots !== undefined && r.motionSeam.pairs.every(p => p.root !== undefined)) ? [] : [{ name: MOTION_SEAM_LINE, n: r.motionSeam.warnings }]), ...(r.cloth.status === 'SKIP' ? [] : [{ name: CLOTH_LINE, n: r.cloth.warnings }]), ...(setupPaintingWarningCount(r.figures[SETUP_PAINTING_LINE]) === 0 ? [] : [{ name: SETUP_PAINTING_UNCOVERED_WARNING, n: setupPaintingWarningCount(r.figures[SETUP_PAINTING_LINE]) }])];
|
|
3308
|
+
const read = [...(r.motionSeam.status === 'SKIP' || (r.motionSeam.roots !== undefined && r.motionSeam.pairs.every(p => p.root !== undefined)) ? [] : [{ name: MOTION_SEAM_LINE, n: r.motionSeam.warnings }]), ...(r.cloth.status === 'SKIP' ? [] : [{ name: CLOTH_LINE, n: r.cloth.warnings }]), ...((r.figures[PHYSICS_CONTRIBUTES_LINE]?.warnings ?? 0) === 0 ? [] : [{ name: PHYSICS_CONTRIBUTES_LINE, n: r.figures[PHYSICS_CONTRIBUTES_LINE]?.warnings ?? 0 }]), ...(setupPaintingWarningCount(r.figures[SETUP_PAINTING_LINE]) === 0 ? [] : [{ name: SETUP_PAINTING_UNCOVERED_WARNING, n: setupPaintingWarningCount(r.figures[SETUP_PAINTING_LINE]) }])];
|
|
3295
3309
|
if (read.length === 0) return '';
|
|
3296
3310
|
return `; ${read.reduce((a, x) => a + x.n, 0)} warning(s) (${read.map((x) => x.name).join(', ')}, not a bar)`;
|
|
3297
3311
|
}
|
|
@@ -3318,7 +3332,7 @@ export type CheckStatus = 'PASS' | 'FAIL' | 'SKIP' | 'WARN' | 'CLEAR' | 'REPORTE
|
|
|
3318
3332
|
* never skipped); `loop` SKIP when `loop_max_diff` is null, `seam` SKIP when `seam_mean` is null, otherwise FAIL when
|
|
3319
3333
|
* {@link barsNotMet} names it and PASS when it does not. Every other block carries its own `status` key and is copied:
|
|
3320
3334
|
* the judgement lines, then {@link FOLD_LINE}, {@link LEVEL_LINE}, {@link STRESS_LINE}, {@link LIMB_LINE},
|
|
3321
|
-
* {@link SWEEP_LINE}, {@link MOTION_SEAM_LINE}, {@link CLOTH_LINE}, the reported lines, {@link SOURCE_LINE} and
|
|
3335
|
+
* {@link SWEEP_LINE}, {@link MOTION_SEAM_LINE}, {@link CLOTH_LINE}, {@link PHYSICS_CONTRIBUTES_LINE}, the reported lines, {@link SOURCE_LINE} and
|
|
3322
3336
|
* {@link WIND_BAND_LINE}, each where the file writes it. The `requirements` block's lines are not bars and are not read here.
|
|
3323
3337
|
*/
|
|
3324
3338
|
export function checkStatuses(fig: Omit<CheckFigures, 'spec' | 'bar_outcomes' | 'build'>): Record<string, CheckStatus> {
|
|
@@ -3326,7 +3340,7 @@ export function checkStatuses(fig: Omit<CheckFigures, 'spec' | 'bar_outcomes' |
|
|
|
3326
3340
|
const bar = (id: 'gate' | 'loop' | 'seam', measured: boolean): CheckStatus => (!measured ? 'SKIP' : checkBarStatus(raw, id) === 'FAIL' ? 'FAIL' : 'PASS');
|
|
3327
3341
|
const out: Record<string, CheckStatus> = { gate: bar('gate', true), loop: bar('loop', fig.loop_max_diff !== null), seam: bar('seam', fig.seam_mean !== null) };
|
|
3328
3342
|
for (const n of JUDGEMENT_LINES) out[n] = fig[n].status;
|
|
3329
|
-
for (const n of [FOLD_LINE, LEVEL_LINE, STRESS_LINE, LIMB_LINE, SWEEP_LINE, MOTION_SEAM_LINE, CLOTH_LINE, ...REPORTED_LINES, 'figure_openings', SOURCE_LINE, WIND_BAND_LINE, ART_JOINT_LINE, CUT_MATERIAL_LINE, SETUP_PAINTING_LINE, BOUNDARY_COLOUR_LINE, BEHIND_SEAM_LINE, COINCIDE_LINE] as const) {
|
|
3343
|
+
for (const n of [FOLD_LINE, LEVEL_LINE, STRESS_LINE, LIMB_LINE, SWEEP_LINE, MOTION_SEAM_LINE, CLOTH_LINE, PHYSICS_CONTRIBUTES_LINE, ...REPORTED_LINES, 'figure_openings', SOURCE_LINE, WIND_BAND_LINE, ART_JOINT_LINE, CUT_MATERIAL_LINE, SETUP_PAINTING_LINE, BOUNDARY_COLOUR_LINE, BEHIND_SEAM_LINE, COINCIDE_LINE] as const) {
|
|
3330
3344
|
const l = fig[n];
|
|
3331
3345
|
if (l !== undefined) out[n] = l.status;
|
|
3332
3346
|
}
|
|
@@ -4862,7 +4876,7 @@ export function motionSeamRequired(line: MotionSeamLine, rows: readonly MotionBa
|
|
|
4862
4876
|
}
|
|
4863
4877
|
const failed = problems.length - before;
|
|
4864
4878
|
return { status: failed === 0 ? 'PASS' : 'FAIL', mode: 'gap-open', bar_px: 0, pairs: out, failed,
|
|
4865
|
-
...(cellEvidence.frames.length === 0 ? {} : { cells: { path: MOTION_CELLS_FILE, sha256:
|
|
4879
|
+
...(cellEvidence.frames.length === 0 ? {} : { cells: { path: MOTION_CELLS_FILE, sha256: hashMotionSeamCellSidecar(cellEvidence) } }) };
|
|
4866
4880
|
}
|
|
4867
4881
|
|
|
4868
4882
|
/** The inline partition counts the same cells as the sidecar, including unresolved setup slots. */
|
|
@@ -4873,7 +4887,7 @@ function motionCellClasses(cells: readonly MotionOpenCell[]): MotionOpenFrame['c
|
|
|
4873
4887
|
}
|
|
4874
4888
|
|
|
4875
4889
|
/** Refuse broken evidence links and partitions rather than silently consuming partial evidence. */
|
|
4876
|
-
export function readMotionSeamCellSidecar(dir: string, required: MotionSeamRequired): MotionCellSidecar | null {
|
|
4890
|
+
export function readMotionSeamCellSidecar(dir: string, required: MotionSeamRequired, chunkBytes = 8 * 1024 * 1024): MotionCellSidecar | null {
|
|
4877
4891
|
if (required.cells === undefined) return null;
|
|
4878
4892
|
const bad = (object: string, detail: string): never => {
|
|
4879
4893
|
refuseIfAny([{ code: 'FRAMES_SIDECAR', object, detail }]);
|
|
@@ -4882,53 +4896,53 @@ export function readMotionSeamCellSidecar(dir: string, required: MotionSeamRequi
|
|
|
4882
4896
|
const reference = required.cells;
|
|
4883
4897
|
if (reference.path !== MOTION_CELLS_FILE || !/^[a-f0-9]{64}$/.test(reference.sha256)) bad('SEAM_OVER_MOTION.required.cells', 'requires relative seam-cells.json path and a SHA-256 digest');
|
|
4884
4898
|
const path = join(dir, reference.path);
|
|
4885
|
-
|
|
4886
|
-
|
|
4887
|
-
|
|
4888
|
-
const
|
|
4889
|
-
if (digest !== reference.sha256) bad(path, `SHA-256 is ${digest}; required ${reference.sha256}`);
|
|
4890
|
-
let value: unknown;
|
|
4891
|
-
try { value = JSON.parse(bytes.toString('utf8')) as unknown; }
|
|
4892
|
-
catch { return bad(path, 'requires a JSON rig-parts-seam-cells/1 document'); }
|
|
4893
|
-
if (!isRecord(value) || value.spec !== 'rig-parts-seam-cells/1' || !Array.isArray(value.frames)) return bad(path, 'requires rig-parts-seam-cells/1 frames');
|
|
4899
|
+
// Streamed frame-by-frame scan: hashes file chunks without building one whole-file
|
|
4900
|
+
// string, verifies the canonical rig-parts-seam-cells/1 frame layout, and summarizes
|
|
4901
|
+
// each frame's cells as it streams through the file.
|
|
4902
|
+
const summaries = scanMotionSeamCellSidecarFile(path, reference.sha256, bad, chunkBytes);
|
|
4894
4903
|
const seen = new Set<number>();
|
|
4895
4904
|
for (const pair of required.pairs) for (const frame of pair.open_frames ?? []) {
|
|
4896
4905
|
const at = `${path} frames[${frame.cells_index}]`;
|
|
4897
|
-
const
|
|
4898
|
-
|
|
4906
|
+
const summary = Number.isSafeInteger(frame.cells_index) && frame.cells_index >= 0 ? summaries[frame.cells_index] : undefined;
|
|
4907
|
+
const read = summary?.frame;
|
|
4908
|
+
if (summary === undefined || read === undefined || seen.has(frame.cells_index) ||
|
|
4899
4909
|
read.pair !== pair.pair || read.animation !== frame.animation || read.index !== frame.index || read.time !== frame.time || read.px !== frame.px || read.cell !== frame.cell ||
|
|
4900
|
-
JSON.stringify(read.box) !== JSON.stringify(frame.box) ||
|
|
4910
|
+
JSON.stringify(read.box) !== JSON.stringify(frame.box) || summary.cellsLength !== frame.px) {
|
|
4901
4911
|
bad(at, 'requires one matching pair-frame with cells.length === gapOpen px; unavailable is not zero');
|
|
4902
4912
|
continue;
|
|
4903
4913
|
}
|
|
4904
4914
|
seen.add(frame.cells_index);
|
|
4905
|
-
|
|
4906
|
-
|
|
4907
|
-
if (!isRecord(cell) || typeof cell.x !== 'number' || !Number.isFinite(cell.x) || typeof cell.y !== 'number' || !Number.isFinite(cell.y) ||
|
|
4908
|
-
!(cell.setupTop === null || typeof cell.setupTop === 'string' && cell.setupTop.length > 0) ||
|
|
4909
|
-
!(cell.setupUnder === null || typeof cell.setupUnder === 'string' && cell.setupUnder.length > 0) ||
|
|
4910
|
-
!['figure', 'background', 'other'].includes(String(cell.class))) bad(at, 'requires finite world centres, setup names and figure/background/other classes');
|
|
4911
|
-
else classes[cell.class as MotionOpenCell['class']]++;
|
|
4915
|
+
if (!summary.cellsValid) {
|
|
4916
|
+
bad(at, 'requires finite world centres, setup names and figure/background/other classes');
|
|
4912
4917
|
}
|
|
4918
|
+
const classes = summary.classes;
|
|
4919
|
+
// Every cell in the sidecar frame was checked and tallied during the streamed
|
|
4920
|
+
// scan before its cell array was replaced by an on-demand slice reader, so
|
|
4921
|
+
// peak string length and retained heap stay bounded by a single frame.
|
|
4913
4922
|
if (!frame.classes || !Object.values(frame.classes).every(n => Number.isSafeInteger(n) && n >= 0) ||
|
|
4914
4923
|
frame.classes.figure + frame.classes.background + frame.classes.other !== frame.px ||
|
|
4915
4924
|
frame.classes.figure !== classes.figure || frame.classes.background !== classes.background || frame.classes.other !== classes.other) {
|
|
4916
4925
|
bad(at, `inline figure/background/other counts ${JSON.stringify(frame.classes)} must sum to gapOpen px ${frame.px} and match sidecar ${JSON.stringify(classes)}`);
|
|
4917
4926
|
}
|
|
4918
4927
|
}
|
|
4919
|
-
if (seen.size !==
|
|
4928
|
+
if (seen.size !== summaries.length) {
|
|
4929
|
+
bad(path, `has ${summaries.length} frame(s); inline rows reference ${seen.size} distinct frame(s)`);
|
|
4930
|
+
}
|
|
4920
4931
|
// Every cell and its pair/frame identity was checked above after the digest matched.
|
|
4921
|
-
return
|
|
4932
|
+
return {
|
|
4933
|
+
spec: 'rig-parts-seam-cells/1',
|
|
4934
|
+
frames: summaries.map(s => s.frame),
|
|
4935
|
+
};
|
|
4922
4936
|
}
|
|
4923
4937
|
|
|
4924
4938
|
/** Publish check.json and its cell evidence together, restoring previous bytes on refusal. */
|
|
4925
|
-
export function publishMotionSeamCells(dir: string, required: MotionSeamRequired | undefined, evidence: MotionCellSidecar, publish: () => void): void {
|
|
4939
|
+
export function publishMotionSeamCells(dir: string, required: MotionSeamRequired | undefined, evidence: MotionCellSidecar, publish: () => void, onChunk?: (chunk: string, index: number) => void): void {
|
|
4926
4940
|
const path = join(dir, MOTION_CELLS_FILE), check = join(dir, 'check.json');
|
|
4927
4941
|
const previous = existsSync(path) ? readFileSync(path) : null;
|
|
4928
4942
|
const previousCheck = existsSync(check) ? readFileSync(check) : null;
|
|
4929
4943
|
try {
|
|
4930
4944
|
if (required?.cells !== undefined) {
|
|
4931
|
-
|
|
4945
|
+
writeMotionSeamCellSidecar(path, evidence, onChunk);
|
|
4932
4946
|
readMotionSeamCellSidecar(dir, required);
|
|
4933
4947
|
}
|
|
4934
4948
|
publish();
|
|
@@ -7426,6 +7440,19 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
7426
7440
|
cloth = unread === undefined ? clothLine(rows, idle.fps, idle.frames.length, idle.duration) : clothLine([], idle.fps, idle.frames.length, idle.duration, unread);
|
|
7427
7441
|
}
|
|
7428
7442
|
|
|
7443
|
+
// 3g. every part under physics, the same compile posed with physics on and off over the idle (issue #1320): a
|
|
7444
|
+
// warning, never a bar; SKIP, named, with no idle, no parts or no physics constraint
|
|
7445
|
+
let physics: PhysicsContributionLine;
|
|
7446
|
+
if (idle === null) physics = physicsLine([], IDLE_FPS, 0, 'none', "rig-c's default environment", inp.noIdle ?? 'no idle');
|
|
7447
|
+
else if (full === null) physics = physicsLine([], IDLE_FPS, 0, 'none', "rig-c's default environment", inp.noParts ?? 'no parts.json');
|
|
7448
|
+
else {
|
|
7449
|
+
const rest = attachmentPoses(join(idle.dir, GEOMETRY_FILE), idle.written)[0] ?? new Map<string, PosedAttachment>();
|
|
7450
|
+
physics = measurePhysicsContribution(officialRenderer(), buildDir, inp.rig, inp.motion, full.parts.parts.map((p) => ({
|
|
7451
|
+
name: p.name, w: p.w, h: p.h, bound: boundBones(inp.rig, p.name), rest: rest.get(p.name) === undefined ? undefined : { vertices: (rest.get(p.name) as PosedAttachment).rest, triangles: (rest.get(p.name) as PosedAttachment).triangles },
|
|
7452
|
+
art: () => placedArt(p.x, p.y, readPng(join(dirname(inp.partsDir), partImageReference(p).path))),
|
|
7453
|
+
})), inp.stage, idle.fps);
|
|
7454
|
+
}
|
|
7455
|
+
|
|
7429
7456
|
// 4. the setup pose as a one-key throwaway animation — the seam reads it against the parts, the source line against
|
|
7430
7457
|
// the painting — and, beside it, the same pose with the eyes shut
|
|
7431
7458
|
let seam: SeamFigures | null = null;
|
|
@@ -7722,6 +7749,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
7722
7749
|
...(sweep === null ? {} : { [SWEEP_LINE]: sweep }),
|
|
7723
7750
|
...(motionSeam.pairs.length === 0 && motionSeam.roots === undefined && motionSeam.required === undefined ? {} : { [MOTION_SEAM_LINE]: motionSeam }),
|
|
7724
7751
|
...(stripped === null || idle === null ? {} : { [CLOTH_LINE]: cloth }),
|
|
7752
|
+
...(physics.status === 'SKIP' ? {} : { [PHYSICS_CONTRIBUTES_LINE]: physics }),
|
|
7725
7753
|
RECOMPOSITE_HOLES: inp.parts === null ? { status: 'SKIP', reason: inp.noParts ?? '' } : holesLine(inp.parts),
|
|
7726
7754
|
...(figureOpenings.status === 'SKIP' ? {} : { figure_openings: figureOpenings }),
|
|
7727
7755
|
...(sourceRead === null ? {} : { [SOURCE_LINE]: sourceRead }),
|
|
@@ -7839,6 +7867,7 @@ export function runCheck(rigDir: string, outDir: string, rigc: RigcRunner, parts
|
|
|
7839
7867
|
motionSeam,
|
|
7840
7868
|
figureOpenings,
|
|
7841
7869
|
cloth,
|
|
7870
|
+
physics,
|
|
7842
7871
|
boundaryColour,
|
|
7843
7872
|
behindSeams,
|
|
7844
7873
|
...(sweepSteps.size === 0 ? {} : { sweepSteps }),
|
|
@@ -9973,3 +10002,228 @@ export function stretchLine(geo: IdleGeometry | null, path: string, problems: Pr
|
|
|
9973
10002
|
|
|
9974
10003
|
/** The compiler's `build-report/1` (`--report`) written beside `build/` on the primary packed compile (issue #1394). */
|
|
9975
10004
|
export const BUILD_REPORT_FILE = 'build-report.json';
|
|
10005
|
+
|
|
10006
|
+
/**
|
|
10007
|
+
* Issue #1406: stream `seam-cells.json` (`rig-parts-seam-cells/1`) frame by frame so peak
|
|
10008
|
+
* JS string length is a single frame while emitting the exact bytes `serializeCheckRows` writes.
|
|
10009
|
+
*/
|
|
10010
|
+
export function streamMotionSeamCellSidecar(evidence: MotionCellSidecar, sink: (chunk: string) => void): void {
|
|
10011
|
+
if (evidence.frames.length === 0) {
|
|
10012
|
+
sink(`{\n "spec": ${JSON.stringify(evidence.spec)},\n "frames": [`);
|
|
10013
|
+
sink(']\n}\n');
|
|
10014
|
+
return;
|
|
10015
|
+
}
|
|
10016
|
+
sink(`{\n "spec": ${JSON.stringify(evidence.spec)},\n "frames": [\n`);
|
|
10017
|
+
for (let i = 0; i < evidence.frames.length; i++) {
|
|
10018
|
+
const suffix = i + 1 < evidence.frames.length ? ',\n' : '\n';
|
|
10019
|
+
sink(` ${JSON.stringify(evidence.frames[i], null, 1).replaceAll('\n', '\n ')}${suffix}`);
|
|
10020
|
+
}
|
|
10021
|
+
sink(' ]\n}\n');
|
|
10022
|
+
}
|
|
10023
|
+
|
|
10024
|
+
/** Compute the SHA-256 of the streamed `seam-cells.json` chunks without building a whole-document string. */
|
|
10025
|
+
export function hashMotionSeamCellSidecar(evidence: MotionCellSidecar): string {
|
|
10026
|
+
const hash = createHash('sha256');
|
|
10027
|
+
streamMotionSeamCellSidecar(evidence, (chunk) => { hash.update(chunk); });
|
|
10028
|
+
return hash.digest('hex');
|
|
10029
|
+
}
|
|
10030
|
+
|
|
10031
|
+
/** Write `seam-cells.json` chunk by chunk through one file descriptor; `onChunk` supports mid-stream failure controls. */
|
|
10032
|
+
export function writeMotionSeamCellSidecar(path: string, evidence: MotionCellSidecar, onChunk?: (chunk: string, index: number) => void): void {
|
|
10033
|
+
const fd = openSync(path, 'w');
|
|
10034
|
+
let index = 0;
|
|
10035
|
+
try {
|
|
10036
|
+
streamMotionSeamCellSidecar(evidence, (chunk) => {
|
|
10037
|
+
writeSync(fd, chunk);
|
|
10038
|
+
onChunk?.(chunk, index++);
|
|
10039
|
+
});
|
|
10040
|
+
} finally {
|
|
10041
|
+
closeSync(fd);
|
|
10042
|
+
}
|
|
10043
|
+
}
|
|
10044
|
+
|
|
10045
|
+
interface StreamedSidecarFrameSummary {
|
|
10046
|
+
frame: MotionCellFrame;
|
|
10047
|
+
cellsLength: number | null;
|
|
10048
|
+
cellsValid: boolean;
|
|
10049
|
+
classes: { figure: number; background: number; other: number };
|
|
10050
|
+
}
|
|
10051
|
+
|
|
10052
|
+
function summarizeStreamedFrame(path: string, parsed: Record<string, unknown>, startOffset: number, endOffset: number): StreamedSidecarFrameSummary {
|
|
10053
|
+
const cells = Array.isArray(parsed.cells) ? parsed.cells : null;
|
|
10054
|
+
let cellsValid = cells !== null;
|
|
10055
|
+
const classes = { figure: 0, background: 0, other: 0 };
|
|
10056
|
+
if (cells !== null) {
|
|
10057
|
+
for (const cell of cells) {
|
|
10058
|
+
if (!isRecord(cell) || typeof cell.x !== 'number' || !Number.isFinite(cell.x) || typeof cell.y !== 'number' || !Number.isFinite(cell.y) ||
|
|
10059
|
+
!(cell.setupTop === null || typeof cell.setupTop === 'string' && cell.setupTop.length > 0) ||
|
|
10060
|
+
!(cell.setupUnder === null || typeof cell.setupUnder === 'string' && cell.setupUnder.length > 0) ||
|
|
10061
|
+
!['figure', 'background', 'other'].includes(String(cell.class))) cellsValid = false;
|
|
10062
|
+
else classes[cell.class as MotionOpenCell['class']]++;
|
|
10063
|
+
}
|
|
10064
|
+
}
|
|
10065
|
+
const frame = { ...parsed } as unknown as MotionCellFrame;
|
|
10066
|
+
Object.defineProperty(frame, 'cells', {
|
|
10067
|
+
enumerable: true,
|
|
10068
|
+
configurable: true,
|
|
10069
|
+
get(): MotionOpenCell[] {
|
|
10070
|
+
const slice = Buffer.allocUnsafe(endOffset - startOffset);
|
|
10071
|
+
const fd = openSync(path, 'r');
|
|
10072
|
+
try { readSync(fd, slice, 0, slice.length, startOffset); }
|
|
10073
|
+
finally { closeSync(fd); }
|
|
10074
|
+
const loaded = (JSON.parse(slice.toString('utf8')) as { cells: MotionOpenCell[] }).cells;
|
|
10075
|
+
Object.defineProperty(frame, 'cells', { value: loaded, enumerable: true, configurable: true, writable: true });
|
|
10076
|
+
return loaded;
|
|
10077
|
+
},
|
|
10078
|
+
});
|
|
10079
|
+
return { frame, cellsLength: cells === null ? null : cells.length, cellsValid, classes };
|
|
10080
|
+
}
|
|
10081
|
+
|
|
10082
|
+
/**
|
|
10083
|
+
* Single-pass streamed reader for `seam-cells.json`: hashes raw byte chunks without allocating
|
|
10084
|
+
* a whole-file string or buffer, verifies the canonical streamed frame layout, and summarizes
|
|
10085
|
+
* each frame's cells one frame at a time.
|
|
10086
|
+
*/
|
|
10087
|
+
function scanMotionSeamCellSidecarFile(path: string, expectedSha256: string, bad: (object: string, detail: string) => never, chunkBytes = 8 * 1024 * 1024): StreamedSidecarFrameSummary[] {
|
|
10088
|
+
let fd: number;
|
|
10089
|
+
try { fd = openSync(path, 'r'); }
|
|
10090
|
+
catch { return bad(path, 'referenced cell sidecar is missing or unreadable; unavailable is not zero'); }
|
|
10091
|
+
const hash = createHash('sha256');
|
|
10092
|
+
const step = Math.max(1, Math.floor(chunkBytes));
|
|
10093
|
+
const buf = Buffer.allocUnsafe(step);
|
|
10094
|
+
let totalBytes = 0;
|
|
10095
|
+
let state: 0 | 1 | 2 | 3 | 4 | 5 | 6 | 7 = 0;
|
|
10096
|
+
let failure: 'json' | 'layout' | null = null;
|
|
10097
|
+
let carry: Buffer = Buffer.alloc(0);
|
|
10098
|
+
let carryStartOffset = 0;
|
|
10099
|
+
let frameChunks: Buffer[] = [];
|
|
10100
|
+
let frameStartOffset = 0;
|
|
10101
|
+
let frameBytes = 0;
|
|
10102
|
+
const summaries: StreamedSidecarFrameSummary[] = [];
|
|
10103
|
+
try {
|
|
10104
|
+
for (;;) {
|
|
10105
|
+
let n: number;
|
|
10106
|
+
try { n = readSync(fd, buf, 0, buf.length, totalBytes); }
|
|
10107
|
+
catch { return bad(path, 'referenced cell sidecar is missing or unreadable; unavailable is not zero'); }
|
|
10108
|
+
if (n === 0) break;
|
|
10109
|
+
const raw = buf.subarray(0, n);
|
|
10110
|
+
hash.update(raw);
|
|
10111
|
+
const rawStartOffset = totalBytes;
|
|
10112
|
+
totalBytes += n;
|
|
10113
|
+
if (failure !== null) continue;
|
|
10114
|
+
const chunk = carry.length === 0 ? raw : Buffer.concat([carry, raw]);
|
|
10115
|
+
const chunkBaseOffset = carry.length === 0 ? rawStartOffset : carryStartOffset;
|
|
10116
|
+
let lineStart = 0;
|
|
10117
|
+
while (lineStart < chunk.length && failure === null) {
|
|
10118
|
+
if (state === 4) {
|
|
10119
|
+
const runStart = lineStart;
|
|
10120
|
+
let closedFrame = false;
|
|
10121
|
+
while (lineStart < chunk.length) {
|
|
10122
|
+
const nl = chunk.indexOf(0x0a, lineStart);
|
|
10123
|
+
if (nl === -1) break;
|
|
10124
|
+
if (nl - lineStart >= 3 && chunk[lineStart] === 0x20 && chunk[lineStart + 1] === 0x20 && chunk[lineStart + 2] === 0x20) {
|
|
10125
|
+
if (frameBytes + (nl + 1 - runStart) > 0x7fff_ff00) { failure = 'layout'; closedFrame = true; break; }
|
|
10126
|
+
lineStart = nl + 1;
|
|
10127
|
+
continue;
|
|
10128
|
+
}
|
|
10129
|
+
if (lineStart > runStart) {
|
|
10130
|
+
const piece = Buffer.from(chunk.subarray(runStart, lineStart));
|
|
10131
|
+
frameChunks.push(piece);
|
|
10132
|
+
frameBytes += piece.length;
|
|
10133
|
+
}
|
|
10134
|
+
const closeLine = chunk.subarray(lineStart, nl).toString('utf8');
|
|
10135
|
+
const closeLineFileOffset = chunkBaseOffset + lineStart;
|
|
10136
|
+
lineStart = nl + 1;
|
|
10137
|
+
if (closeLine !== ' },' && closeLine !== ' }') { failure = 'layout'; closedFrame = true; break; }
|
|
10138
|
+
frameChunks.push(Buffer.from(' }'));
|
|
10139
|
+
const frameEndOffset = closeLineFileOffset + 3;
|
|
10140
|
+
const frameText = Buffer.concat(frameChunks).toString('utf8');
|
|
10141
|
+
frameChunks = [];
|
|
10142
|
+
frameBytes = 0;
|
|
10143
|
+
let parsed: unknown;
|
|
10144
|
+
try { parsed = JSON.parse(frameText) as unknown; }
|
|
10145
|
+
catch { failure = 'json'; closedFrame = true; break; }
|
|
10146
|
+
if (!isRecord(parsed) || ` ${JSON.stringify(parsed, null, 1).replaceAll('\n', '\n ')}` !== frameText) {
|
|
10147
|
+
failure = 'layout';
|
|
10148
|
+
closedFrame = true;
|
|
10149
|
+
break;
|
|
10150
|
+
}
|
|
10151
|
+
summaries.push(summarizeStreamedFrame(path, parsed, frameStartOffset, frameEndOffset));
|
|
10152
|
+
state = closeLine === ' },' ? 3 : 5;
|
|
10153
|
+
closedFrame = true;
|
|
10154
|
+
break;
|
|
10155
|
+
}
|
|
10156
|
+
if (!closedFrame) {
|
|
10157
|
+
if (lineStart > runStart) {
|
|
10158
|
+
const piece = Buffer.from(chunk.subarray(runStart, lineStart));
|
|
10159
|
+
frameChunks.push(piece);
|
|
10160
|
+
frameBytes += piece.length;
|
|
10161
|
+
if (frameBytes > 0x7fff_ff00) failure = 'layout';
|
|
10162
|
+
}
|
|
10163
|
+
break;
|
|
10164
|
+
}
|
|
10165
|
+
} else {
|
|
10166
|
+
const nl = chunk.indexOf(0x0a, lineStart);
|
|
10167
|
+
if (nl === -1) break;
|
|
10168
|
+
const lineFileOffset = chunkBaseOffset + lineStart;
|
|
10169
|
+
const line = chunk.subarray(lineStart, nl).toString('utf8');
|
|
10170
|
+
lineStart = nl + 1;
|
|
10171
|
+
if (state === 0) {
|
|
10172
|
+
if (line === '{') state = 1;
|
|
10173
|
+
else failure = 'layout';
|
|
10174
|
+
} else if (state === 1) {
|
|
10175
|
+
if (line === ' "spec": "rig-parts-seam-cells/1",') state = 2;
|
|
10176
|
+
else failure = 'layout';
|
|
10177
|
+
} else if (state === 2) {
|
|
10178
|
+
if (line === ' "frames": []') state = 6;
|
|
10179
|
+
else if (line === ' "frames": [') state = 3;
|
|
10180
|
+
else failure = 'layout';
|
|
10181
|
+
} else if (state === 3) {
|
|
10182
|
+
if (line === ' {') {
|
|
10183
|
+
frameChunks = [Buffer.from(' {\n')];
|
|
10184
|
+
frameBytes = 4;
|
|
10185
|
+
frameStartOffset = lineFileOffset;
|
|
10186
|
+
state = 4;
|
|
10187
|
+
} else failure = 'layout';
|
|
10188
|
+
} else if (state === 5) {
|
|
10189
|
+
if (line === ' ]') state = 6;
|
|
10190
|
+
else failure = 'layout';
|
|
10191
|
+
} else if (state === 6) {
|
|
10192
|
+
if (line === '}') state = 7;
|
|
10193
|
+
else failure = 'layout';
|
|
10194
|
+
} else {
|
|
10195
|
+
failure = 'layout';
|
|
10196
|
+
}
|
|
10197
|
+
}
|
|
10198
|
+
}
|
|
10199
|
+
if (failure === null) {
|
|
10200
|
+
if (lineStart < chunk.length) {
|
|
10201
|
+
carry = Buffer.from(chunk.subarray(lineStart));
|
|
10202
|
+
carryStartOffset = chunkBaseOffset + lineStart;
|
|
10203
|
+
if (carry.length > 4 * 1024 * 1024) failure = 'layout';
|
|
10204
|
+
} else {
|
|
10205
|
+
carry = Buffer.alloc(0);
|
|
10206
|
+
carryStartOffset = totalBytes;
|
|
10207
|
+
}
|
|
10208
|
+
}
|
|
10209
|
+
}
|
|
10210
|
+
} finally {
|
|
10211
|
+
closeSync(fd);
|
|
10212
|
+
}
|
|
10213
|
+
const digest = hash.digest('hex');
|
|
10214
|
+
if (digest !== expectedSha256) bad(path, `SHA-256 is ${digest}; required ${expectedSha256}`);
|
|
10215
|
+
if (failure !== null || state !== 7 || carry.length !== 0) {
|
|
10216
|
+
if (totalBytes <= 4 * 1024 * 1024) {
|
|
10217
|
+
let value: unknown;
|
|
10218
|
+
try { value = JSON.parse(readFileSync(path, 'utf8')) as unknown; }
|
|
10219
|
+
catch { return bad(path, 'requires a JSON rig-parts-seam-cells/1 document'); }
|
|
10220
|
+
if (!isRecord(value) || value.spec !== 'rig-parts-seam-cells/1' || !Array.isArray(value.frames)) {
|
|
10221
|
+
return bad(path, 'requires rig-parts-seam-cells/1 frames');
|
|
10222
|
+
}
|
|
10223
|
+
return bad(path, 'requires canonical rig-parts-seam-cells/1 streamed frame layout');
|
|
10224
|
+
}
|
|
10225
|
+
if (failure === 'json') return bad(path, 'requires a JSON rig-parts-seam-cells/1 document');
|
|
10226
|
+
return bad(path, 'requires canonical rig-parts-seam-cells/1 streamed frame layout');
|
|
10227
|
+
}
|
|
10228
|
+
return summaries;
|
|
10229
|
+
}
|
package/src/checkrow.ts
CHANGED
|
@@ -46,6 +46,7 @@ export const CHECK_ROW_PATHS = {
|
|
|
46
46
|
'PART_SUPPORT_REPORT.pairs': ['PART_SUPPORT_REPORT.pairs'],
|
|
47
47
|
'PART_SUPPORT_REPORT.raw_pairs': ['PART_SUPPORT_REPORT.raw_pairs'],
|
|
48
48
|
'PART_SUPPORT_REPORT.unowned.regions': ['PART_SUPPORT_REPORT.unowned.regions'],
|
|
49
|
+
'PHYSICS_CONTRIBUTES.rows': ['PHYSICS_CONTRIBUTES.rows'],
|
|
49
50
|
'SEAM_OVER_MOTION.pairs': ['SEAM_OVER_MOTION.pairs'],
|
|
50
51
|
'SEAM_OVER_MOTION.required.pairs': ['SEAM_OVER_MOTION.required.pairs'],
|
|
51
52
|
'SEAM_OVER_MOTION.required.pairs[].open_frames': ['SEAM_OVER_MOTION.required.pairs[].open_frames'],
|
package/src/config.ts
CHANGED
|
@@ -3792,6 +3792,54 @@ function checkRibs(c: Check, at: string, m: Record<string, Json>, chains: Map<st
|
|
|
3792
3792
|
}
|
|
3793
3793
|
}
|
|
3794
3794
|
|
|
3795
|
+
/**
|
|
3796
|
+
* The `CONFIG_BUST_CLEARANCE` rule over three landmarks and the shape's `alpha` and `clearance` (issue #475): the
|
|
3797
|
+
* refusal's detail, or null when the points pass. The loader reads it for a config's `contour.bust`, and issue #1441's
|
|
3798
|
+
* callers read it with the effective shape (`effectiveBustShape`, src/bustlandmarks.ts) before that shape is written.
|
|
3799
|
+
*/
|
|
3800
|
+
export function bustClearanceDetail(points: { apex_r: Point; apex_l: Point; cleavage: Point }, alpha: number, clearance: number): string | null {
|
|
3801
|
+
const [rx, ry] = points.apex_r;
|
|
3802
|
+
const [lx, ly] = points.apex_l;
|
|
3803
|
+
const [kx, ky] = points.cleavage;
|
|
3804
|
+
const D = edgeLength(lx - rx, ly - ry);
|
|
3805
|
+
const dR = edgeLength(kx - rx, ky - ry);
|
|
3806
|
+
const dL = edgeLength(kx - lx, ky - ly);
|
|
3807
|
+
const RR = Math.round(dR - clearance);
|
|
3808
|
+
const RL = Math.round(dL - clearance);
|
|
3809
|
+
const rR = Math.round(alpha * RR);
|
|
3810
|
+
const rL = Math.round(alpha * RL);
|
|
3811
|
+
const bandR = RR - rR;
|
|
3812
|
+
const bandL = RL - rL;
|
|
3813
|
+
if (clearance <= 0 || RR + RL >= D || rR <= 0 || rL <= 0 || bandR < 0 || bandL < 0) {
|
|
3814
|
+
// Invalid coordinates already have named problems, but c.point accepts any finite pair.
|
|
3815
|
+
// Restrict only this diagnostic search to onGrid's existing domain, not the refusal rule.
|
|
3816
|
+
let remedy = `clearance hint unavailable: correct the CONFIG_FIELD_TYPE landmark coordinates to the 1/${GRID} px grid within ±${MAX_SIDE} px first`;
|
|
3817
|
+
if ([rx, ry, lx, ly, kx, ky].every((n) => Number.isInteger(n * GRID) && Math.abs(n) <= MAX_SIDE)) {
|
|
3818
|
+
let low = 1;
|
|
3819
|
+
let high = Math.ceil(Math.max(dR, dL) * 100) + 100;
|
|
3820
|
+
// The coordinate domain bounds high below 2^24; binary search needs at most 24 steps.
|
|
3821
|
+
const maxSteps = Math.ceil(Math.log2(high));
|
|
3822
|
+
for (let step = 0; low < high && step < maxSteps; step++) {
|
|
3823
|
+
const mid = low + Math.floor((high - low) / 2);
|
|
3824
|
+
if (Math.round(dR - mid / 100) + Math.round(dL - mid / 100) < D) high = mid;
|
|
3825
|
+
else low = mid + 1;
|
|
3826
|
+
}
|
|
3827
|
+
if (low === high) {
|
|
3828
|
+
const candidate = low / 100;
|
|
3829
|
+
const nextRR = Math.round(dR - candidate);
|
|
3830
|
+
const nextRL = Math.round(dL - candidate);
|
|
3831
|
+
const nextR = Math.round(alpha * nextRR);
|
|
3832
|
+
const nextL = Math.round(alpha * nextRL);
|
|
3833
|
+
remedy = nextRR + nextRL < D && nextR > 0 && nextL > 0 && nextRR - nextR >= 0 && nextRL - nextL >= 0
|
|
3834
|
+
? `the first passing clearance in 0.01 px steps is ${candidate} px for these landmarks and alpha; set clearance to that value`
|
|
3835
|
+
: 'no clearance in 0.01 px steps meets all these rounded-radius checks; move cleavage or the apices, or change alpha, and retry';
|
|
3836
|
+
}
|
|
3837
|
+
}
|
|
3838
|
+
return `is ${clearance} (giving R_r = ${RR}, R_l = ${RL}, R_r + R_l = ${RR + RL} px against apex distance D = ${pyRound(D, 2)} px, r_r = ${rR}, band_r = ${bandR}, r_l = ${rL}, band_l = ${bandL}); a clearance > 0 with R_r + R_l < D and positive core radii and non-negative bands is required; ${remedy}`;
|
|
3839
|
+
}
|
|
3840
|
+
return null;
|
|
3841
|
+
}
|
|
3842
|
+
|
|
3795
3843
|
/**
|
|
3796
3844
|
* `meshes.<part>.contour` (issue #84). `tolerance`, `margin` and `spacing` are
|
|
3797
3845
|
* required — nothing is defaulted; `maxEdge`, `budget`, `stray` and `regions` are
|
|
@@ -3902,49 +3950,8 @@ function checkContour(c: Check, at: string, v: Json, bones: Set<string>): void {
|
|
|
3902
3950
|
}
|
|
3903
3951
|
}
|
|
3904
3952
|
if (ptsOk && alphaOk && clearanceOk) {
|
|
3905
|
-
const
|
|
3906
|
-
|
|
3907
|
-
const [kx, ky] = b.cleavage as Point;
|
|
3908
|
-
const D = edgeLength(lx - rx, ly - ry);
|
|
3909
|
-
const dR = edgeLength(kx - rx, ky - ry);
|
|
3910
|
-
const dL = edgeLength(kx - lx, ky - ly);
|
|
3911
|
-
const RR = Math.round(dR - clearance);
|
|
3912
|
-
const RL = Math.round(dL - clearance);
|
|
3913
|
-
const rR = Math.round(alpha * RR);
|
|
3914
|
-
const rL = Math.round(alpha * RL);
|
|
3915
|
-
const bandR = RR - rR;
|
|
3916
|
-
const bandL = RL - rL;
|
|
3917
|
-
if (clearance <= 0 || RR + RL >= D || rR <= 0 || rL <= 0 || bandR < 0 || bandL < 0) {
|
|
3918
|
-
// Invalid coordinates already have named problems, but c.point accepts any finite pair.
|
|
3919
|
-
// Restrict only this diagnostic search to onGrid's existing domain, not the refusal rule.
|
|
3920
|
-
let remedy = `clearance hint unavailable: correct the CONFIG_FIELD_TYPE landmark coordinates to the 1/${GRID} px grid within ±${MAX_SIDE} px first`;
|
|
3921
|
-
if ([rx, ry, lx, ly, kx, ky].every((n) => Number.isInteger(n * GRID) && Math.abs(n) <= MAX_SIDE)) {
|
|
3922
|
-
let low = 1;
|
|
3923
|
-
let high = Math.ceil(Math.max(dR, dL) * 100) + 100;
|
|
3924
|
-
// The coordinate domain bounds high below 2^24; binary search needs at most 24 steps.
|
|
3925
|
-
const maxSteps = Math.ceil(Math.log2(high));
|
|
3926
|
-
for (let step = 0; low < high && step < maxSteps; step++) {
|
|
3927
|
-
const mid = low + Math.floor((high - low) / 2);
|
|
3928
|
-
if (Math.round(dR - mid / 100) + Math.round(dL - mid / 100) < D) high = mid;
|
|
3929
|
-
else low = mid + 1;
|
|
3930
|
-
}
|
|
3931
|
-
if (low === high) {
|
|
3932
|
-
const candidate = low / 100;
|
|
3933
|
-
const nextRR = Math.round(dR - candidate);
|
|
3934
|
-
const nextRL = Math.round(dL - candidate);
|
|
3935
|
-
const nextR = Math.round(alpha * nextRR);
|
|
3936
|
-
const nextL = Math.round(alpha * nextRL);
|
|
3937
|
-
remedy = nextRR + nextRL < D && nextR > 0 && nextL > 0 && nextRR - nextR >= 0 && nextRL - nextL >= 0
|
|
3938
|
-
? `the first passing clearance in 0.01 px steps is ${candidate} px for these landmarks and alpha; set clearance to that value`
|
|
3939
|
-
: 'no clearance in 0.01 px steps meets all these rounded-radius checks; move cleavage or the apices, or change alpha, and retry';
|
|
3940
|
-
}
|
|
3941
|
-
}
|
|
3942
|
-
c.fail(
|
|
3943
|
-
'CONFIG_BUST_CLEARANCE',
|
|
3944
|
-
`${bat}.clearance`,
|
|
3945
|
-
`is ${clearance} (giving R_r = ${RR}, R_l = ${RL}, R_r + R_l = ${RR + RL} px against apex distance D = ${pyRound(D, 2)} px, r_r = ${rR}, band_r = ${bandR}, r_l = ${rL}, band_l = ${bandL}); a clearance > 0 with R_r + R_l < D and positive core radii and non-negative bands is required; ${remedy}`,
|
|
3946
|
-
);
|
|
3947
|
-
}
|
|
3953
|
+
const detail = bustClearanceDetail({ apex_r: b.apex_r as Point, apex_l: b.apex_l as Point, cleavage: b.cleavage as Point }, alpha, clearance);
|
|
3954
|
+
if (detail !== null) c.fail('CONFIG_BUST_CLEARANCE', `${bat}.clearance`, detail);
|
|
3948
3955
|
}
|
|
3949
3956
|
}
|
|
3950
3957
|
}
|