@rig-c/parts 2.34.0 → 2.35.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/src/config.ts CHANGED
@@ -249,6 +249,12 @@ export interface Patch {
249
249
  * for a `from` a limb takes (issue #564), whether the polygon takes a pixel a
250
250
  * segment of the limb holds (`ASSEMBLE_CUT_CROSSES_LIMB`).
251
251
  */
252
+ export interface CutUnderPlate {
253
+ plate: string;
254
+ }
255
+
256
+ export type CutUnder = string | CutUnderPlate;
257
+
252
258
  export interface Cut {
253
259
  from: string;
254
260
  into: string;
@@ -262,13 +268,16 @@ export interface Cut {
262
268
  */
263
269
  overlap: number;
264
270
  /**
265
- * Issue #193, optional: a PNG, its path relative to the config's directory,
266
- * of what lies under the piece — in rig pixels over the polygon's bounding
267
- * box (`underBox` in `src/assemble.ts`). Where the cut removed pixels from
268
- * the base (the piece's pixels less the band), the base takes this image's
269
- * pixels; it is read nowhere else. Absent: the base keeps only its band.
271
+ * Issue #193 / #1230, optional: a PNG, its path relative to the config's
272
+ * directory, of what lies under the piece — in rig pixels over the polygon's
273
+ * bounding box (`underBox` in `src/assemble.ts`) — or `{"plate": "<dir>"}`
274
+ * naming a `comfy plate --mode occluder` output directory whose `plate.png`
275
+ * is resampled to rig pixels and cropped to `underBox`. Where the cut
276
+ * removed pixels from the base (the piece's pixels less the band), the base
277
+ * takes this image's pixels; it is read nowhere else. Absent: the base keeps
278
+ * only its band.
270
279
  */
271
- under?: string;
280
+ under?: CutUnder;
272
281
  /**
273
282
  * Issue #360 (item 11), optional, one value: `"colour"` — where the under
274
283
  * fills a removed pixel, the base takes the under's colour and keeps the
@@ -2572,7 +2581,7 @@ function checkRequiredHiddenExtent(c: Check, a: Record<string, Json>, names: rea
2572
2581
  }
2573
2582
 
2574
2583
  /**
2575
- * Issue #1230 / #1241 / #1246: `config.assemble.occluders`, `[{image, sha256, under, over?, rgb_within, plate?, part?}]`.
2584
+ * Issue #1230 / #1241 / #1246 / #1251: `config.assemble.occluders`, `[{image, sha256, under, over?, rgb_within, plate?, part?, grow?}]`.
2576
2585
  * Shape at every door; `under`, `over` and `part` resolved against the plan where the door reads it; the file and its
2577
2586
  * sha256 where the door knows the config's directory (`checkOccluderFiles`). Returns the declared `part` names, in order.
2578
2587
  */
@@ -2584,7 +2593,7 @@ function checkOccluders(c: Check, a: Record<string, Json>, names: readonly strin
2584
2593
  const partNames: string[] = [];
2585
2594
  (a.occluders as Json[]).forEach((value, i) => {
2586
2595
  const p = `${at}[${i}]`;
2587
- const row = c.object(p, value, ['image', 'sha256', 'under', 'rgb_within'], ['over', 'plate', 'part']);
2596
+ const row = c.object(p, value, ['image', 'sha256', 'under', 'rgb_within'], ['over', 'plate', 'part', 'grow']);
2588
2597
  if (row === null) return;
2589
2598
  const imageOk = c.string(`${p}.image`, row.image);
2590
2599
  const shaOk = typeof row.sha256 === 'string' && SHA256_PATTERN.test(row.sha256);
@@ -2613,8 +2622,15 @@ function checkOccluders(c: Check, a: Record<string, Json>, names: readonly strin
2613
2622
  }
2614
2623
  }
2615
2624
  }
2616
- if (imageOk && shaOk && underOk && overOk && rgbOk && plateOk && partOk) {
2617
- declarations.push({ image: row.image as string, sha256: row.sha256 as string, under: row.under as string[], ...('over' in row ? { over: row.over as string[] } : {}), rgb_within: row.rgb_within as number, ...('plate' in row ? { plate: row.plate as string } : {}), ...(partName !== undefined ? { part: partName } : {}) });
2625
+ let growOk = true;
2626
+ let growVal: number | undefined;
2627
+ if ('grow' in row) {
2628
+ growOk = typeof row.grow === 'number' && Number.isInteger(row.grow) && row.grow >= 0;
2629
+ if (!growOk) c.fail('CONFIG_FIELD_TYPE', `${p}.grow`, `is ${show(row.grow)}; a non-negative integer is required`);
2630
+ else growVal = row.grow as number;
2631
+ }
2632
+ if (imageOk && shaOk && underOk && overOk && rgbOk && plateOk && partOk && growOk) {
2633
+ declarations.push({ image: row.image as string, sha256: row.sha256 as string, under: row.under as string[], ...('over' in row ? { over: row.over as string[] } : {}), rgb_within: row.rgb_within as number, ...('plate' in row ? { plate: row.plate as string } : {}), ...(partName !== undefined ? { part: partName } : {}), ...(growVal !== undefined ? { grow: growVal } : {}) });
2618
2634
  }
2619
2635
  });
2620
2636
  c.problems.push(...occluderNameProblems(declarations, names));
@@ -2881,8 +2897,13 @@ function checkCuts(c: Check, v: Json, plan: string[], patches: string[], p = 'co
2881
2897
  const at = `${p}[${i}]`;
2882
2898
  const e = c.object(at, entry, ['from', 'into', 'polygon', 'draw', 'overlap'], ['under', 'under_fill']);
2883
2899
  if (e === null) return;
2884
- if ('under' in e && !(typeof e.under === 'string' && e.under !== '')) {
2885
- c.fail('CONFIG_FIELD_TYPE', `${at}.under`, `is ${show(e.under)}; a non-empty path to a PNG is required, relative to the config's directory — the image of what lies under the piece, in rig pixels over the polygon's bounding box`);
2900
+ if ('under' in e) {
2901
+ if (typeof e.under === 'object' && e.under !== null && !Array.isArray(e.under)) {
2902
+ const u = c.object(`${at}.under`, e.under, ['plate'], []);
2903
+ if (u !== null && 'plate' in u) c.string(`${at}.under.plate`, u.plate);
2904
+ } else if (!(typeof e.under === 'string' && e.under !== '')) {
2905
+ c.fail('CONFIG_FIELD_TYPE', `${at}.under`, `is ${show(e.under)}; a non-empty path to a PNG or {"plate": "<dir>"} is required, relative to the config's directory — the image of what lies under the piece, in rig pixels over the polygon's bounding box, or a comfy plate --mode occluder output directory`);
2906
+ }
2886
2907
  }
2887
2908
  if ('under_fill' in e && e.under_fill !== 'colour') {
2888
2909
  c.fail('CONFIG_FIELD_TYPE', `${at}.under_fill`, `is ${show(e.under_fill)}; "colour" is required — the base takes the under's colour and keeps the alpha the cut removed, so its silhouette does not grow; leave under_fill out for the under's colour and alpha`);
@@ -151,12 +151,12 @@ export function editedRunImages(runs: { full: LayerSet; head: LayerSet; single:
151
151
  return out;
152
152
  }
153
153
 
154
- /** The images a config names by path that the author painted: every cut's `under` and every limb segment's `cap`. */
155
- export function editedConfigImages(configPath: string, cuts: ReadonlyArray<{ into: string; under?: string }>, limbs: Readonly<Record<string, { segments: ReadonlyArray<{ part: string; cap?: string }> }>> | undefined, cutsAt = 'config.assemble.cuts'): EditedImage[] {
154
+ /** The images a config names by path that the author painted: every string-form cut's `under` and every limb segment's `cap` (a `{plate}` under carries its own machine receipt). */
155
+ export function editedConfigImages(configPath: string, cuts: ReadonlyArray<{ into: string; under?: string | { plate: string } }>, limbs: Readonly<Record<string, { segments: ReadonlyArray<{ part: string; cap?: string }> }>> | undefined, cutsAt = 'config.assemble.cuts'): EditedImage[] {
156
156
  const base = dirname(resolve(configPath));
157
157
  const out: EditedImage[] = [];
158
158
  cuts.forEach((q, i) => {
159
- if (q.under !== undefined) out.push({ object: `${cutsAt}[${i}].under (part "${q.into}")`, path: resolve(base, q.under) });
159
+ if (typeof q.under === 'string') out.push({ object: `${cutsAt}[${i}].under (part "${q.into}")`, path: resolve(base, q.under) });
160
160
  });
161
161
  for (const [l, limb] of Object.entries(limbs ?? {})) {
162
162
  limb.segments.forEach((sg, k) => {
package/src/occluders.ts CHANGED
@@ -36,6 +36,8 @@ export interface OccluderDeclaration {
36
36
  plate?: string;
37
37
  /** An optional part name (`painting:<part>`) emitted from the painting for occluder pixels not held at rest by front parts (issue #1246). */
38
38
  part?: string;
39
+ /** An optional non-negative integer rig-px radius by which the occluder's > 128 core is dilated on the rig grid before the under guard, the occluder part and UNHELD read it (issue #1251). */
40
+ grow?: number;
39
41
  }
40
42
 
41
43
  export const OCCLUDER_COLOUR_COPIED = 'ASSEMBLE_OCCLUDER_COLOUR_COPIED';
@@ -249,13 +251,45 @@ export function occluderFileProblems(declarations: readonly OccluderDeclaration[
249
251
  /**
250
252
  * Reorder a draft `assemble.plan` in place so each declared `occluders[i].over`
251
253
  * part sits after every `under` part of the same entry across `full` and `head`
252
- * rows, keeping every other row's relative order unchanged (issue #1247).
254
+ * rows, keeping every other row's relative order unchanged (issues #1247, #1251).
255
+ *
256
+ * A declared `over` or `under` name matches a proposed row whose name (`row[0]`)
257
+ * equals it, or whose See-through tag (`row[2]`) equals `takenTags[name]` (the
258
+ * tag of the config's taken layer for that name). Any `over` or `under` name on
259
+ * an entry with `over` that matches no proposed row is returned as a note for
260
+ * `proposal.notes`.
253
261
  */
254
262
  export function orderPlanForOccluders<T extends readonly [string, ...unknown[]]>(
255
263
  plan: T[],
256
264
  declarations: readonly OccluderDeclaration[] | undefined,
257
- ): void {
258
- if (declarations === undefined || declarations.length === 0) return;
265
+ takenTags?: Readonly<Record<string, string>>,
266
+ ): string[] {
267
+ if (declarations === undefined || declarations.length === 0) return [];
268
+ const matchesRow = (row: T, name: string): boolean => {
269
+ if (row[0] === name) return true;
270
+ const tag = takenTags?.[name];
271
+ return tag !== undefined && typeof row[2] === 'string' && row[2] === tag;
272
+ };
273
+ const matchesSet = (row: T, names: ReadonlySet<string>): boolean => {
274
+ for (const name of names) {
275
+ if (matchesRow(row, name)) return true;
276
+ }
277
+ return false;
278
+ };
279
+ const notes: string[] = [];
280
+ declarations.forEach((d, i) => {
281
+ if (d.over === undefined || d.over.length === 0) return;
282
+ for (const name of d.under) {
283
+ if (!plan.some((row) => matchesRow(row, name))) {
284
+ notes.push(`occluders[${i}].under "${name}" matched no proposed row`);
285
+ }
286
+ }
287
+ for (const name of d.over) {
288
+ if (!plan.some((row) => matchesRow(row, name))) {
289
+ notes.push(`occluders[${i}].over "${name}" matched no proposed row`);
290
+ }
291
+ }
292
+ });
259
293
  for (let pass = 0; pass <= plan.length; pass++) {
260
294
  let moved = false;
261
295
  for (const d of declarations) {
@@ -263,14 +297,14 @@ export function orderPlanForOccluders<T extends readonly [string, ...unknown[]]>
263
297
  const underSet = new Set(d.under);
264
298
  let lastUnder = -1;
265
299
  for (let i = 0; i < plan.length; i++) {
266
- if (underSet.has(plan[i][0])) lastUnder = i;
300
+ if (matchesSet(plan[i], underSet)) lastUnder = i;
267
301
  }
268
302
  if (lastUnder < 0) continue;
269
303
  const overSet = new Set(d.over);
270
304
  const beforeOver: T[] = [];
271
305
  const keptBefore: T[] = [];
272
306
  for (let i = 0; i < lastUnder; i++) {
273
- if (overSet.has(plan[i][0])) beforeOver.push(plan[i]);
307
+ if (matchesSet(plan[i], overSet)) beforeOver.push(plan[i]);
274
308
  else keptBefore.push(plan[i]);
275
309
  }
276
310
  if (beforeOver.length === 0) continue;
@@ -280,6 +314,7 @@ export function orderPlanForOccluders<T extends readonly [string, ...unknown[]]>
280
314
  }
281
315
  if (!moved) break;
282
316
  }
317
+ return notes;
283
318
  }
284
319
 
285
320
  export interface OccluderCopy {
@@ -318,6 +353,6 @@ export function occluderColourWarning(index: number, copy: OccluderCopy, rgbWith
318
353
  return `WARN ${OCCLUDER_COLOUR_COPIED}: ${AT}[${index}] part "${copy.part}" — ${copy.px} rig px of its selected layer at alpha > ${COPIED_ALPHA_ABOVE} under the occluder (alpha > 0) lie within ${rgbWithin} of the painting (max channel); first at ${copy.first[0]},${copy.first[1]}; the layer holds the occluder's own colour — take this part from a See-through run on the painting with the occluder removed (comfy plate --mode occluder)`;
319
354
  }
320
355
 
321
- export function occluderUnheldWarning(index: number, image: string, under: readonly string[], px: number, first: readonly [number, number]): string {
322
- return `WARN ${OCCLUDER_UNHELD}: ${AT}[${index}] — ${px} rig px of occluder "${image}" (alpha > 8, first at ${first[0]},${first[1]}) are not held at alpha >= 250 by any part drawn in front of under [${under.map((u) => `"${u}"`).join(', ')}]; declare ${AT}[${index}].part to fill the unheld occluder pixels`;
356
+ export function occluderUnheldWarning(index: number, image: string, under: readonly string[], px: number, first: readonly [number, number], coreAlpha: number): string {
357
+ return `WARN ${OCCLUDER_UNHELD}: ${AT}[${index}] — ${px} rig px of occluder "${image}" (alpha > ${COPIED_ALPHA_ABOVE}, first at ${first[0]},${first[1]}) are not held at alpha >= ${coreAlpha} by any part drawn in front of under [${under.map((u) => `"${u}"`).join(', ')}]; declare ${AT}[${index}].part to fill the unheld occluder pixels`;
323
358
  }
package/src/parts.ts CHANGED
@@ -392,6 +392,19 @@ export interface OccluderPlateRecord {
392
392
  mask_sha256: string;
393
393
  }
394
394
 
395
+ export interface OccluderGrowRecord {
396
+ /** Zero-based index into `config.assemble.occluders`. */
397
+ occluder: number;
398
+ /** The declared `config.assemble.occluders[occluder].image` path. */
399
+ image: string;
400
+ /** The declared positive integer `config.assemble.occluders[occluder].grow` radius in rig px. */
401
+ grow: number;
402
+ /** Rig pixels of the occluder core (`alpha > 128`) before the dilation. */
403
+ covered_px_before: number;
404
+ /** Rig pixels of the occluder core (`alpha > 128`) after the `(2 * grow + 1)^2` dilation. */
405
+ covered_px_after: number;
406
+ }
407
+
395
408
  export interface PartsFile {
396
409
  /** Optional on legacy packages; binds the opaque RGB raster assemble actually read. */
397
410
  painting_in_rig?: PaintingInRig;
@@ -411,6 +424,8 @@ export interface PartsFile {
411
424
  single_run_pad?: SingleRunPad;
412
425
  /** Written only when an `assemble.occluders` entry declares `plate` (issue #1237); absent otherwise. */
413
426
  occluder_plates?: OccluderPlateRecord[];
427
+ /** Written only when an `assemble.occluders` entry declares `grow > 0` (issue #1251); absent otherwise. */
428
+ occluder_grow?: OccluderGrowRecord[];
414
429
  /** Written only when alternate painting sets were assembled (issue #454); absent otherwise. */
415
430
  alternates?: AlternatePartsRecord[];
416
431
  }
@@ -447,9 +462,10 @@ export interface SceneRecord {
447
462
  figure_mask: string;
448
463
  }
449
464
 
450
- const TOP_KEYS = ['painting_in_rig', 'rig_size', 'scale_rig_per_source', 'parts', 'ghost_px', 'recomposite', 'scene', 'occluder_plates', 'single_run_pad', 'alternates', 'motion_seams', 'cut_ownership'] as const;
451
- const REQUIRED_TOP_KEYS = TOP_KEYS.filter((k) => k !== 'painting_in_rig' && k !== 'recomposite' && k !== 'scene' && k !== 'single_run_pad' && k !== 'occluder_plates' && k !== 'alternates' && k !== 'motion_seams' && k !== 'cut_ownership');
465
+ const TOP_KEYS = ['painting_in_rig', 'rig_size', 'scale_rig_per_source', 'parts', 'ghost_px', 'recomposite', 'scene', 'occluder_plates', 'occluder_grow', 'single_run_pad', 'alternates', 'motion_seams', 'cut_ownership'] as const;
466
+ const REQUIRED_TOP_KEYS = TOP_KEYS.filter((k) => k !== 'painting_in_rig' && k !== 'recomposite' && k !== 'scene' && k !== 'single_run_pad' && k !== 'occluder_plates' && k !== 'occluder_grow' && k !== 'alternates' && k !== 'motion_seams' && k !== 'cut_ownership');
452
467
  export const OCCLUDER_PLATE_KEYS = ['receipt', 'receipt_sha256', 'occluder_sha256', 'painting_sha256', 'output_sha256', 'mask_sha256'] as const;
468
+ export const OCCLUDER_GROW_KEYS = ['occluder', 'image', 'grow', 'covered_px_before', 'covered_px_after'] as const;
453
469
  export const SINGLE_RUN_PAD_KEYS = ['file_size', 'side', 'left', 'top'] as const;
454
470
  export const SCENE_KEYS = ['figure_alpha_above', 'figure_px', 'figure_mask'] as const;
455
471
  export const RECOMPOSITE_KEYS = ['mean_abs', 'within_limit', 'within_share', 'error_limit', 'error_px', 'covered_alpha', 'uncovered_error_px', 'hole_count', 'holes_listed', 'holes'] as const;
@@ -512,20 +528,45 @@ export function tagOf(from: string): string | null {
512
528
  return f === null || f.run === 'painting' ? null : f.tag;
513
529
  }
514
530
 
515
- const OWNERSHIP_KEYS = ['edit', 'from', 'into', 'moved_in_opaque_px', 'retained_band_opaque_px', 'cleared_opaque_px', 'under_filled_px', 'under_filled_opaque_px', 'net_cleared_opaque_px'] as const;
531
+ const OWNERSHIP_KEYS = ['edit', 'from', 'into', 'moved_in_opaque_px', 'retained_band_opaque_px', 'cleared_opaque_px', 'under_filled_px', 'under_filled_opaque_px', 'net_cleared_opaque_px', 'under_plate'] as const;
532
+ const REQUIRED_OWNERSHIP_KEYS = OWNERSHIP_KEYS.filter((k) => k !== 'under_plate');
516
533
  function orderedOwnership(rows: readonly CutOwnership[]): Array<Record<string, unknown>> {
517
- return rows.map(r => Object.fromEntries(OWNERSHIP_KEYS.map(k => [k, r[k]])));
534
+ return rows.map((r) => ({
535
+ ...Object.fromEntries(REQUIRED_OWNERSHIP_KEYS.map((k) => [k, r[k]])),
536
+ ...(r.under_plate === undefined
537
+ ? {}
538
+ : {
539
+ under_plate: Object.fromEntries(OCCLUDER_PLATE_KEYS.map((k) => [k, r.under_plate![k]])),
540
+ }),
541
+ }));
542
+ }
543
+ function checkOccluderPlateEntry(entry: unknown, at: string, fail: (code: string, object: string, detail: string) => void): void {
544
+ if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
545
+ fail('PARTS_FIELD_TYPE', at, `is ${show(entry)}; an object is required`);
546
+ return;
547
+ }
548
+ const r = entry as Record<string, unknown>;
549
+ for (const k of Object.keys(r)) if (!(OCCLUDER_PLATE_KEYS as readonly string[]).includes(k)) fail('PARTS_KEY_KNOWN', `${at} key "${k}"`, `is not an occluder_plates field; known: ${OCCLUDER_PLATE_KEYS.join(', ')}`);
550
+ for (const k of OCCLUDER_PLATE_KEYS) if (!(k in r)) fail('PARTS_FIELD_PRESENT', `${at} field "${k}"`, 'is absent and required');
551
+ if ('receipt' in r && (typeof r.receipt !== 'string' || r.receipt.length === 0)) fail('PARTS_FIELD_TYPE', `${at} field "receipt"`, `is ${show(r.receipt)}; a non-empty string path is required`);
552
+ for (const k of ['receipt_sha256', 'occluder_sha256', 'painting_sha256', 'output_sha256', 'mask_sha256'] as const) {
553
+ if (k in r && (typeof r[k] !== 'string' || !/^[a-f0-9]{64}$/.test(r[k] as string))) {
554
+ fail('PARTS_FIELD_TYPE', `${at} field "${k}"`, `is ${show(r[k])}; 64 lowercase hex characters are required`);
555
+ }
556
+ }
518
557
  }
519
558
  function checkOwnership(raw: unknown, object: string, fail: (code: string, object: string, detail: string) => void): void {
520
559
  if (!Array.isArray(raw)) { fail('PARTS_FIELD_TYPE', object, `is ${show(raw)}; an array of indexed cut ownership records is required`); return; }
521
560
  const seen = new Set<string>();
522
561
  raw.forEach((row, i) => {
523
562
  const r = row as CutOwnership | null;
524
- const shape = r !== null && typeof r === 'object' && !Array.isArray(r) && Object.keys(r).sort().join(',') === [...OWNERSHIP_KEYS].sort().join(',') &&
563
+ const keys = r !== null && typeof r === 'object' && !Array.isArray(r) ? Object.keys(r).filter((k) => k !== 'under_plate').sort().join(',') : '';
564
+ const shape = r !== null && typeof r === 'object' && !Array.isArray(r) && keys === [...REQUIRED_OWNERSHIP_KEYS].sort().join(',') &&
525
565
  typeof r.edit === 'string' && /^cuts\[\d+\]$/.test(r.edit) && !seen.has(r.edit) && typeof r.from === 'string' && r.from !== '' && typeof r.into === 'string' && r.into !== '' &&
526
- OWNERSHIP_KEYS.slice(3).every(k => Number.isSafeInteger(r[k]) && (k === 'net_cleared_opaque_px' || (r[k] as number) >= 0));
566
+ REQUIRED_OWNERSHIP_KEYS.slice(3).every(k => Number.isSafeInteger(r[k]) && (k === 'net_cleared_opaque_px' || (r[k] as number) >= 0));
527
567
  if (!shape) { fail('PARTS_FIELD_TYPE', `${object}[${i}]`, `is ${show(row)}; a distinct cuts[i] with from/into names, nonnegative move/clear/fill counts and signed net_cleared_opaque_px is required`); return; }
528
568
  const q = r as CutOwnership; seen.add(q.edit);
569
+ if ('under_plate' in q && q.under_plate !== undefined) checkOccluderPlateEntry(q.under_plate, `${object}[${i}].under_plate`, fail);
529
570
  if (q.moved_in_opaque_px - q.retained_band_opaque_px !== q.cleared_opaque_px || q.cleared_opaque_px - q.under_filled_opaque_px !== q.net_cleared_opaque_px || q.under_filled_opaque_px > q.under_filled_px) {
530
571
  fail('PARTS_COUNTS_ADD_UP', `${object}[${i}]`, `moved ${q.moved_in_opaque_px} - retained ${q.retained_band_opaque_px} = ${q.moved_in_opaque_px - q.retained_band_opaque_px} (gross cleared ${q.cleared_opaque_px} required); cleared - opaque fill ${q.under_filled_opaque_px} = ${q.cleared_opaque_px - q.under_filled_opaque_px} (net ${q.net_cleared_opaque_px} required); opaque fill must be at most total fill ${q.under_filled_px}`);
531
572
  }
@@ -587,6 +628,7 @@ export function serializeParts(file: PartsFile): string {
587
628
  ...(file.recomposite === undefined ? {} : { recomposite: serializeRecomposite(file.recomposite) }),
588
629
  ...(file.scene === undefined ? {} : { scene: Object.fromEntries(SCENE_KEYS.map((k) => [k, (file.scene as SceneRecord)[k]])) }),
589
630
  ...(file.occluder_plates === undefined ? {} : { occluder_plates: file.occluder_plates.map((p) => Object.fromEntries(OCCLUDER_PLATE_KEYS.map((k) => [k, p[k]]))) }),
631
+ ...(file.occluder_grow === undefined ? {} : { occluder_grow: file.occluder_grow.map((g) => Object.fromEntries(OCCLUDER_GROW_KEYS.map((k) => [k, g[k]]))) }),
590
632
  ...(file.single_run_pad === undefined ? {} : { single_run_pad: Object.fromEntries(SINGLE_RUN_PAD_KEYS.map((k) => [k, (file.single_run_pad as SingleRunPad)[k]])) }),
591
633
  ...(file.alternates === undefined
592
634
  ? {}
@@ -930,19 +972,34 @@ function checkParts(raw: unknown, path: string): PartsFile {
930
972
  if (!Array.isArray(o.occluder_plates) || o.occluder_plates.length === 0) {
931
973
  fail('PARTS_FIELD_TYPE', `${path} field "occluder_plates"`, `is ${show(o.occluder_plates)}; a non-empty array of occluder plate records is required`);
932
974
  } else {
933
- o.occluder_plates.forEach((entry, i) => {
934
- const at = `${path} occluder_plates[${i}]`;
975
+ o.occluder_plates.forEach((entry, i) => checkOccluderPlateEntry(entry, `${path} occluder_plates[${i}]`, fail));
976
+ }
977
+ }
978
+ if ('occluder_grow' in o) {
979
+ if (!Array.isArray(o.occluder_grow) || o.occluder_grow.length === 0) {
980
+ fail('PARTS_FIELD_TYPE', `${path} field "occluder_grow"`, `is ${show(o.occluder_grow)}; a non-empty array of occluder grow records is required`);
981
+ } else {
982
+ o.occluder_grow.forEach((entry, i) => {
983
+ const at = `${path} occluder_grow[${i}]`;
935
984
  if (typeof entry !== 'object' || entry === null || Array.isArray(entry)) {
936
985
  fail('PARTS_FIELD_TYPE', at, `is ${show(entry)}; an object is required`);
937
986
  return;
938
987
  }
939
988
  const r = entry as Record<string, unknown>;
940
- for (const k of Object.keys(r)) if (!(OCCLUDER_PLATE_KEYS as readonly string[]).includes(k)) fail('PARTS_KEY_KNOWN', `${at} key "${k}"`, `is not an occluder_plates field; known: ${OCCLUDER_PLATE_KEYS.join(', ')}`);
941
- for (const k of OCCLUDER_PLATE_KEYS) if (!(k in r)) fail('PARTS_FIELD_PRESENT', `${at} field "${k}"`, 'is absent and required');
942
- if ('receipt' in r && (typeof r.receipt !== 'string' || r.receipt.length === 0)) fail('PARTS_FIELD_TYPE', `${at} field "receipt"`, `is ${show(r.receipt)}; a non-empty string path is required`);
943
- for (const k of ['receipt_sha256', 'occluder_sha256', 'painting_sha256', 'output_sha256', 'mask_sha256'] as const) {
944
- if (k in r && (typeof r[k] !== 'string' || !/^[a-f0-9]{64}$/.test(r[k] as string))) {
945
- fail('PARTS_FIELD_TYPE', `${at} field "${k}"`, `is ${show(r[k])}; 64 lowercase hex characters are required`);
989
+ for (const k of Object.keys(r)) if (!(OCCLUDER_GROW_KEYS as readonly string[]).includes(k)) fail('PARTS_KEY_KNOWN', `${at} key "${k}"`, `is not an occluder_grow field; known: ${OCCLUDER_GROW_KEYS.join(', ')}`);
990
+ for (const k of OCCLUDER_GROW_KEYS) if (!(k in r)) fail('PARTS_FIELD_PRESENT', `${at} field "${k}"`, 'is absent and required');
991
+ if ('occluder' in r && !(typeof r.occluder === 'number' && Number.isInteger(r.occluder) && r.occluder >= 0)) {
992
+ fail('PARTS_FIELD_TYPE', `${at} field "occluder"`, `is ${show(r.occluder)}; a non-negative integer index is required`);
993
+ }
994
+ if ('image' in r && (typeof r.image !== 'string' || r.image.length === 0)) {
995
+ fail('PARTS_FIELD_TYPE', `${at} field "image"`, `is ${show(r.image)}; a non-empty string path is required`);
996
+ }
997
+ if ('grow' in r && !(typeof r.grow === 'number' && Number.isInteger(r.grow) && r.grow > 0)) {
998
+ fail('PARTS_FIELD_TYPE', `${at} field "grow"`, `is ${show(r.grow)}; a positive integer is required`);
999
+ }
1000
+ for (const k of ['covered_px_before', 'covered_px_after'] as const) {
1001
+ if (k in r && !(typeof r[k] === 'number' && Number.isInteger(r[k]) && (r[k] as number) >= 0)) {
1002
+ fail('PARTS_FIELD_TYPE', `${at} field "${k}"`, `is ${show(r[k])}; a non-negative integer is required`);
946
1003
  }
947
1004
  }
948
1005
  });
package/src/partsource.ts CHANGED
@@ -62,10 +62,12 @@ export function untracedPartSources(cfg: Pick<AssembleConfig, 'assemble' | 'seet
62
62
  };
63
63
  const a = cfg.assemble;
64
64
  (a.cuts ?? []).forEach((q, i) => {
65
+ if (typeof q.under === 'object' && q.under !== null) return;
65
66
  refuse(`part "${q.into}" (config.assemble.cuts[${i}])`, `its pixels are carved out of part "${q.from}" by a hand-drawn ${q.polygon.length}-point polygon`);
66
67
  });
67
68
  (a.alternates ?? []).forEach((set, j) => {
68
69
  (set.cuts ?? []).forEach((q, i) => {
70
+ if (typeof q.under === 'object' && q.under !== null) return;
69
71
  refuse(`part "${q.into}" (config.assemble.alternates[${j}].cuts[${i}], alternate set "${set.name}")`, `its pixels are carved out of part "${q.from}" by a hand-drawn ${q.polygon.length}-point polygon`);
70
72
  });
71
73
  });
package/src/provenance.ts CHANGED
@@ -137,6 +137,15 @@ export function provenanceLines(parts: readonly PartRecord[]): string[] {
137
137
  return lines;
138
138
  }
139
139
 
140
+ export interface CutUnderPlateRecord {
141
+ receipt: string;
142
+ receipt_sha256: string;
143
+ occluder_sha256: string;
144
+ painting_sha256: string;
145
+ output_sha256: string;
146
+ mask_sha256: string;
147
+ }
148
+
140
149
  /** Structural cut census, independent of the value partition. Counts are from
141
150
  * the original parent partition before limb/fringe/seam processing. */
142
151
  export interface CutOwnership {
@@ -149,6 +158,7 @@ export interface CutOwnership {
149
158
  under_filled_px: number;
150
159
  under_filled_opaque_px: number;
151
160
  net_cleared_opaque_px: number;
161
+ under_plate?: CutUnderPlateRecord;
152
162
  }
153
163
  export function ownershipLines(rows: readonly CutOwnership[]): string[] {
154
164
  return rows.map(r => ` ownership: ${r.edit} "${r.from}" -> "${r.into}" moved in ${r.moved_in_opaque_px} opaque px; retained band ${r.retained_band_opaque_px}; gross cleared ${r.cleared_opaque_px} before refill; under filled ${r.under_filled_px} px (${r.under_filled_opaque_px} opaque); net cleared ${r.net_cleared_opaque_px}; independent of RGBA equality`);
package/src/remesh.ts CHANGED
@@ -134,6 +134,8 @@ export interface RemeshPlant {
134
134
  unexpandedStops?: boolean;
135
135
  /** Issue #617's mutant: run just before check-input reads the input, after the first snapshot, to change a file under it. */
136
136
  beforeInputCheck?: () => void;
137
+ /** Issue #1256's mutant: hand every non-`images/` entry of the tree to `gateThroughRigc` as text, as before. */
138
+ unfilteredGateTexts?: boolean;
137
139
  }
138
140
 
139
141
  /** The versions the provenance names: this package's and the rigc that gated the revision (its `--version` line). */
@@ -866,10 +868,13 @@ export function inputTreeProblems(tree: FileTree, root: string, op: 'remesh' | '
866
868
  return out;
867
869
  }
868
870
 
871
+ /** The two text files `gateThroughRigc`'s `rigc build` reads (`src/build.ts`), in `readTree` sort order. */
872
+ export const GATE_TEXT_FILES = ['motion.json', 'rig.json'] as const;
869
873
  /** A tree's images as the gate takes them (name under `images/`, bytes). */
870
- const pngsOf = (tree: FileTree): Array<readonly [string, Uint8Array]> => [...tree].filter(([k]) => k.startsWith('images/')).map(([k, b]) => [k.slice('images/'.length), b] as const);
871
- /** A tree's other files as text. */
872
- const textsOf = (tree: FileTree): Array<readonly [string, string]> => [...tree].filter(([k]) => !k.startsWith('images/')).map(([k, b]) => [k, text(b)] as const);
874
+ export const pngsOf = (tree: FileTree): Array<readonly [string, Uint8Array]> => [...tree].filter(([k]) => k.startsWith('images/')).map(([k, b]) => [k.slice('images/'.length), b] as const);
875
+ /** A tree's text inputs for the gate (`rig.json` and `motion.json`; `unfiltered` is the pre-#1256 plant). */
876
+ export const textsOf = (tree: FileTree, unfiltered = false): Array<readonly [string, string]> =>
877
+ [...tree].filter(([k]) => (unfiltered ? !k.startsWith('images/') : (GATE_TEXT_FILES as readonly string[]).includes(k))).map(([k, b]) => [k, text(b)] as const);
873
878
 
874
879
  /**
875
880
  * The delta's `mesh_report.json` row (issue #526): the input's row, key for key, with `vertices`, `triangles`, `hull`,
@@ -973,7 +978,7 @@ export function remeshStage(input: RemeshInput, rigc: RigcRunner, checkBin: stri
973
978
  refuseIfAny(deltaSourceProblems(doc, part, inAtt, deltaPath));
974
979
  log(`rig-parts remesh: ${part} of ${input.rig}, ${tree.size} file(s); the request is a mesh edit of ${doc.ops.length} op(s), the baseline is the input itself`);
975
980
  let model = null as string | null;
976
- const inGate = gateThroughRigc(pngsOf(tree), textsOf(tree), rigc, join(scratch, 'gate-input'), { pageEdges, packShape }, (dir) => {
981
+ const inGate = gateThroughRigc(pngsOf(tree), textsOf(tree, plant.unfilteredGateTexts === true), rigc, join(scratch, 'gate-input'), { pageEdges, packShape }, (dir) => {
977
982
  const p = join(dir, RIGC_MODEL_DOCUMENT);
978
983
  model = existsSync(p) ? readFileSync(p, 'utf8') : null;
979
984
  });
@@ -1010,7 +1015,7 @@ export function remeshStage(input: RemeshInput, rigc: RigcRunner, checkBin: stri
1010
1015
  log(` ${part}: v=${before.vertices} t=${before.triangles} hull=${before.hull} -> v=${after.vertices} t=${after.triangles} hull=${after.hull}`);
1011
1016
  log(` preserved: ${identical.filter((p) => p !== PROVENANCE_FILE && !(input.recordInputCheck === true && p === INPUT_CHECK_FILE)).length} file(s) byte-identical to the input; rig.json identical outside skins.default.${part}.${part}; mesh_report.json identical but the "${part}" row`);
1012
1017
  // 7. The gate and check.
1013
- const gate = gateThroughRigc(pngsOf(revision), textsOf(revision), rigc, join(scratch, 'gate'), { pageEdges, packShape });
1018
+ const gate = gateThroughRigc(pngsOf(revision), textsOf(revision, plant.unfilteredGateTexts === true), rigc, join(scratch, 'gate'), { pageEdges, packShape });
1014
1019
  for (const g of gate) {
1015
1020
  log(` rigc ${g.label}, the revision: exit ${g.status}`);
1016
1021
  for (const l of g.lines) log(` ${l.trim()}`);
package/src/retune.ts CHANGED
@@ -40,7 +40,7 @@ import { dirname, join, resolve, sep } from 'node:path';
40
40
  import { checkStage, gateThroughRigc, type Log, rigStage } from './build.ts';
41
41
  import { type CheckReport, DEFAULT_PACK_SHAPE, DEFAULT_PAGE_EDGES, type PackShape, type PageEdges, rigcRanClause, type RigcRunner } from './check.ts';
42
42
  import { PartsError, type Problem, problemLine, refuseIfAny } from './errors.ts';
43
- import { type CheckSide, carryProvenance, type ParentProvenance, checkHeldProblems, checkSide, checkScope, type FileTree, firstDifference, type HashRow, hashRows, INPUT_CHECK_FILE, type InputCheckBinding, inputCheckHashes, inputCheckMovedProblems, inputCheckOf, inputCheckReusedLine, inputCheckText, inputTreeProblems, perturbed, readTree, sha256 } from './remesh.ts';
43
+ import { type CheckSide, carryProvenance, type ParentProvenance, checkHeldProblems, checkSide, checkScope, type FileTree, firstDifference, type HashRow, hashRows, INPUT_CHECK_FILE, type InputCheckBinding, inputCheckHashes, inputCheckMovedProblems, inputCheckOf, inputCheckReusedLine, inputCheckText, inputTreeProblems, perturbed, pngsOf, readTree, sha256, textsOf } from './remesh.ts';
44
44
  import { DEFAULT_IDLE_KEYS, type IdleKeys, rigJsonText } from './rig.ts';
45
45
 
46
46
  /** The provenance file's spec. */
@@ -89,6 +89,8 @@ export interface RetunePlant {
89
89
  skipHold?: boolean;
90
90
  /** Issue #617's mutant: run just before check-input reads the input, after the first snapshot, to change a file under it. */
91
91
  beforeInputCheck?: () => void;
92
+ /** Issue #1256's mutant: hand every non-`images/` entry of the tree to `gateThroughRigc` as text, as before. */
93
+ unfilteredGateTexts?: boolean;
92
94
  }
93
95
 
94
96
  /** One constraint the request changed: its name and type, and each field whose value moved, in the rebuild's order. */
@@ -377,9 +379,7 @@ export function retuneStage(input: RetuneInput, rigc: RigcRunner, checkBin: stri
377
379
  log(` idle: ${changed.idle.tracks_changed} track(s) changed, duration ${changed.idle.duration[0]} -> ${changed.idle.duration[1]}`);
378
380
  log(` preserved: ${identical.filter((p) => p !== RETUNE_FILE && !(input.recordInputCheck === true && p === INPUT_CHECK_FILE)).length} file(s) byte-identical to the input; rig.json identical outside constraints and invariants.detached; motion.json identical outside animations.idle`);
379
381
  // 6. The gate and check.
380
- const pngs = [...revision].filter(([k]) => k.startsWith('images/')).map(([k, b]) => [k.slice('images/'.length), b] as const);
381
- const texts = [...revision].filter(([k]) => !k.startsWith('images/')).map(([k, b]) => [k, text(b)] as const);
382
- const gate = gateThroughRigc(pngs, texts, rigc, join(scratch, 'gate'), { pageEdges, packShape });
382
+ const gate = gateThroughRigc(pngsOf(revision), textsOf(revision, plant.unfilteredGateTexts === true), rigc, join(scratch, 'gate'), { pageEdges, packShape });
383
383
  for (const g of gate) {
384
384
  log(` rigc ${g.label}, the revision: exit ${g.status}`);
385
385
  for (const l of g.lines) log(` ${l.trim()}`);