spine-parts 2.23.0 → 2.23.1

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/docs/AUTHORING.md CHANGED
@@ -4442,6 +4442,29 @@ and 13,872 to 1,110 (`wind`), and the holes from 1,020 to 62, 453 to 40, 259 to
4442
4442
  291 to 34 and 1,118 to 62; `check` passes the same bars as before on all five. A
4443
4443
  painting patch is read placed on the rig canvas, and is never written. `core` is unchanged.
4444
4444
 
4445
+ **Painting ownership at a seam (#1038).** The edge estimator receives a named
4446
+ owner input. Its current supplier, `owner-a/raw-plan-alpha>=128`, selects the
4447
+ topmost original plan layer whose alpha is at least 128 after placement on the
4448
+ rig canvas. Receivers follow explicit cut `from` to `into`, limb `from` to
4449
+ `part`, and hybrid descendant edges. A receiver needs exactly one raw-plan
4450
+ ancestor, positive pre-edge support and membership in its production region.
4451
+ Missing lineage, cycles, multiple ancestors, overlapping receivers and absent
4452
+ support are named in the assembly result's `paintingEdges.allocation` reading.
4453
+
4454
+ A FRONT-owned positive-coverage pixel keeps the estimator's unmix. BEHIND-owned
4455
+ paint goes to BEHIND and FRONT is cleared. If piece preservation holds only the
4456
+ clear, BEHIND keeps its own paint and FRONT keeps its pre-edge coverage.
4457
+ FRONT-owned pixels at resolved alpha zero take their own painting pixel at
4458
+ alpha 255. A refused allocation retains the existing edge write unless it is a
4459
+ foreign-owner FRONT write or a contract-foreign BEHIND copy. That predicate is
4460
+ computed on scratch rasters through the existing edge path, reading survival at
4461
+ the edge pass's post-restoration output. Later assembly writers are outside its
4462
+ scope. The applied allocation and clean-refusal fallbacks form one plan, guarded
4463
+ once for piece preservation. A held fallback returns to pre-edge bytes and is
4464
+ counted by `fallbackHeld`. Scratch evaluation leaves the real input untouched.
4465
+ The counted public-example rest exceptions are tracked separately in #1038
4466
+ and #1141. The remaining silhouette cause in #1141 is unclosed.
4467
+
4445
4468
  **A busy ground (`assemble.ground`, issue #996).** The step above reads the painting
4446
4469
  as a figure on a ground of one colour: a painted pixel no part covers is the figure's
4447
4470
  when it differs from the border ring's colour, and the colour behind a part's edge is
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "spine-parts",
3
- "version": "2.23.0",
3
+ "version": "2.23.1",
4
4
  "description": "AI-authored 2D character parts from one anime painting and its See-through layer decomposition: measured parts, weighted-mesh rig specs, verified through rig-c before anything is written. A CLI for agents that cannot see the image.",
5
5
  "type": "module",
6
6
  "bin": {
package/src/assemble.ts CHANGED
@@ -1,10 +1,11 @@
1
+ import { paintingReceivers, rawPaintingOwner } from './paintingowner.ts';
1
2
  import { hiddenExtentProblems, type HiddenExtentDeclaration, type HiddenExtentSource } from './hiddenextent.ts';
2
3
  import { headBoxInside } from './headbox.ts';
3
4
  import { edgePairResiduals, type EdgeResidualReport } from './edgeresidual.ts';
4
5
  import type { SupportDomain } from './coincide.ts';
5
6
  import { type SeamRule } from './seamrule.ts';
6
7
  import { DEFAULT_GROUND, DEFAULT_PROJECT_RULE, type Ground, type ProjectRule } from './projectrule.ts';
7
- import { paintingEdges, type PaintingEdgeSkips } from './paintingedges.ts';
8
+ import { paintingEdges, type PaintingAllocationReading, type PaintingEdgeSkips } from './paintingedges.ts';
8
9
  import { edgeLength } from './length.ts';
9
10
  import { materialSource, type MaterialSource, materialRows, polygonMaterialEdges, type MaterialRow, type MaterialEdge, type PlacedArt } from './cutmaterial.ts';
10
11
  import { unionTakenSources } from './takesource.ts';
@@ -4785,6 +4786,7 @@ export interface AssembleResult {
4785
4786
 
4786
4787
  /** Issue #953: the edge pixels `paintingEdges` resolved, the part pixels it changed, and the edge pixels it left, by reason. */
4787
4788
  export interface PaintingEdgeReading {
4789
+ allocation?: PaintingAllocationReading;
4788
4790
  resolved: number;
4789
4791
  unseparated: number;
4790
4792
  changed: number;
@@ -5859,7 +5861,23 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
5859
5861
  }
5860
5862
  return whole;
5861
5863
  };
5862
- const e = paintingEdges(stack.map(onRig), srcr, {
5864
+ const canvases = stack.map(onRig);
5865
+ const owner = rawPaintingOwner(input.plan.map(([name, run, tag]) => {
5866
+ const layer = input[run].layers.find(l => l.name === tag)!;
5867
+ return { name, raster: layerToRig(placeLayer(layer, input.resolution), frame, run) };
5868
+ }), W * H);
5869
+ const lineage: Array<[string, string]> = [
5870
+ ...input.cuts.map(c => [c.from, c.into] as [string, string]),
5871
+ ...Object.values(input.limbs ?? {}).flatMap(l => l.segments.flatMap(segment => [
5872
+ [segment.from, segment.part] as [string, string],
5873
+ ...(segment.hybrid === undefined ? [] : [[segment.from, segment.hybrid.part] as [string, string]]),
5874
+ ])),
5875
+ ];
5876
+ const receivers = paintingReceivers(owner, order.map((d, i) => ({
5877
+ name: stack[i].record.name, image: canvases[i], region: 'patch' in d ? null : pieceAt(d).b.region,
5878
+ })), lineage);
5879
+ const e = paintingEdges(canvases, srcr, {
5880
+ owner: receivers,
5863
5881
  painted: supportPainted,
5864
5882
  figure: visibleFigure,
5865
5883
  ...(input.declaredFigure === undefined ? {} : { declaredFigure: input.declaredFigure }),
@@ -5880,7 +5898,7 @@ function assembleParts(input: AssembleInput, targets?: ReadonlySet<string>, befo
5880
5898
  order.forEach((d, i) => {
5881
5899
  if (!('patch' in d) && e.changed[i].data.some((v) => v === 1)) edged.set(pieceAt(d).name, e.changed[i]);
5882
5900
  });
5883
- edgeReading = { resolved: e.resolved, unseparated: e.unseparated, changed: e.changed.reduce((a, m) => a + m.data.reduce((x, v) => x + v, 0), 0), skipped: e.skipped };
5901
+ edgeReading = { resolved: e.resolved, unseparated: e.unseparated, changed: e.changed.reduce((a, m) => a + m.data.reduce((x, v) => x + v, 0), 0), skipped: e.skipped, allocation: e.allocation };
5884
5902
  }
5885
5903
  const pushedOf: FringePushed[][] = plan.map(() => []);
5886
5904
  const pushedOfCut: FringePushed[][] = cuts.map(() => []);
package/src/build.ts CHANGED
@@ -873,6 +873,12 @@ export function assembleStage(input: AssembleStageInput, outs: AssembleOutputs,
873
873
  if (result.paintingEdges !== undefined) {
874
874
  const e = result.paintingEdges;
875
875
  log(`painting edges: ${e.resolved} edge px resolved from the painting (${e.unseparated} against the two reference colours where the window's far sides overlap), ${e.changed} part px changed; left as they were: ${e.skipped.cover} under a part the two-layer model does not carry, ${e.skipped.contrast} where the painting draws no edge (contrast below ${EDGE_CONTRAST}), ${e.skipped.locked} kept, feathered, a patch or a turn's moving pair, ${e.skipped.noBehind} with no behind pixel in the window; ${e.skipped.pieces} part px not written so a part's art keeps its pieces`);
876
+ if (e.allocation !== undefined) {
877
+ const a = e.allocation;
878
+ log(`painting owner: ${a.supplier}; ${a.fallbackHeld} clean-fallback part px held by piece preservation`);
879
+ for (const [reason, px] of Object.entries(a.refused)) log(` painting owner refused: ${reason}, ${px} edge px`);
880
+ for (const fault of a.lineage) log(` painting receiver refused: "${fault.receiver}", ${fault.reason}; one declared raw-plan ancestor is required`);
881
+ }
876
882
  // Issue #996: under a declared busy ground, what the two ground rules left.
877
883
  if (fields.ground === 'busy') log(` busy ground (assemble.ground): ${e.skipped.mix} behind-side px left that are not a mix of the two reference colours, ${e.skipped.support} part px not raised outside the part's own support`);
878
884
  }
@@ -1,3 +1,4 @@
1
+ import { foreignPaintingReceiver, paintingReceiverAt, type PaintingReceivers } from './paintingowner.ts';
1
2
  import { OPAQUE_ALPHA_ABOVE } from './layers.ts';
2
3
  import { connectedComponents } from './raster/components.ts';
3
4
  import { type Ground } from './projectrule.ts';
@@ -131,6 +132,12 @@ import { type Mask, newMask, type Raster, RasterError } from './raster/types.ts'
131
132
  * Under a plain ground (the default) none of the three applies, and the step is
132
133
  * the one described above, byte for byte.
133
134
  *
135
+ * With a named `owner` input, allocation follows that supplier's explicit
136
+ * receiver relation after coverage estimation. FRONT-owned positive coverage
137
+ * keeps this unmix; zero coverage receives P at alpha 255. BEHIND receives its
138
+ * own P with FRONT cleared, retaining BEHIND if only the clear is held. Clean
139
+ * refusal fallbacks join the allocation before the applied piece guard.
140
+ *
134
141
  * Every decision is read off the stack as it stood before the step, then
135
142
  * applied, so the result does not depend on the order pixels are visited.
136
143
  * Deterministic: integer rig arithmetic, medians by sort, no float reduction
@@ -159,6 +166,8 @@ export interface PaintingEdgeSkips {
159
166
  export interface PaintingEdgeResult {
160
167
  /** Per part (stack index), the pixels whose RGBA the step changed. */
161
168
  changed: Mask[];
169
+ /** Named owner/receiver refusals and held clean-fallback writes. */
170
+ allocation?: PaintingAllocationReading;
162
171
  /** Edge pixels resolved (whether or not a value changed), and the ones left. */
163
172
  resolved: number;
164
173
  /** Of `resolved`, the pixels whose two far sides did not separate along the axis, read against `Cb` and `Cf` themselves. */
@@ -166,7 +175,16 @@ export interface PaintingEdgeResult {
166
175
  skipped: PaintingEdgeSkips;
167
176
  }
168
177
 
178
+ export interface PaintingAllocationReading {
179
+ supplier: string;
180
+ refused: Record<string, number>;
181
+ lineage: PaintingReceivers['faults'];
182
+ fallbackHeld: number;
183
+ }
184
+
169
185
  export interface PaintingEdgeOptions {
186
+ /** Named supplier and explicit receiver contract, frozen before the edge pass. */
187
+ owner?: PaintingReceivers;
170
188
  /**
171
189
  * Per rig pixel, 1 where the painting shows figure (`paintedFigure` in
172
190
  * `src/assemble.ts`). A figure pixel no part covers above
@@ -250,7 +268,15 @@ interface Decision {
250
268
  }
251
269
 
252
270
  /** See the invariant above {@link EDGE_RADIUS}. Modifies `parts` (full rig canvases, draw order) in place. */
253
- export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEdgeOptions): PaintingEdgeResult {
271
+ function applyPaintingEdges(
272
+ parts: Raster[], srcr: Raster, options: PaintingEdgeOptions,
273
+ existing?: { parts: Raster[]; defects: Uint8Array },
274
+ readDecision?: (q: Decision, alpha: number) => void,
275
+ ): PaintingEdgeResult {
276
+ const allocation = options.owner;
277
+ const events: Array<{ p: number; front: number; behind: number; target: number; affected: number[]; status: string; reason: string }> = [];
278
+ const reading: PaintingAllocationReading | undefined = allocation === undefined ? undefined
279
+ : { supplier: allocation.supplier, refused: {}, lineage: allocation.faults, fallbackHeld: 0 };
254
280
  const W = srcr.width;
255
281
  const H = srcr.height;
256
282
  const n = parts.length;
@@ -523,6 +549,32 @@ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEd
523
549
  if (alpha > 0 && alpha < 255) while (alpha < 255 && 2 * miss(alpha) > EDGE_CONTRAST) alpha++;
524
550
  if (alpha >= 255 - OPAQUE_ALPHA_ABOVE) alpha = 255;
525
551
  const unmix = (c: number): number => unmixAt(c, alpha);
552
+ readDecision?.(q, alpha);
553
+ if (allocation !== undefined && q.behind >= 0) {
554
+ const { target, reason } = paintingReceiverAt(allocation, q.p);
555
+ const affected = target < 0 ? [] : [...new Set([target, q.front, q.behind].filter(i => i >= target))];
556
+ const event = { p: q.p, front: q.front, behind: q.behind, target, affected, status: 'refused', reason };
557
+ events.push(event);
558
+ if (target < 0) return;
559
+ if (affected.some(i => !options.editable[i] || options.keep?.[i]?.data[q.p] === 1 || options.feathered?.[i]?.data[q.p] === 1) ||
560
+ affected.some(i => i !== target && options.movingPair?.(i, target) === true)) {
561
+ event.reason = 'protected-receiver';
562
+ return;
563
+ }
564
+ if (target === q.front) {
565
+ if (alpha === 0) {
566
+ plan(q.front, q.p, P[0], P[1], P[2], 255);
567
+ event.status = 'front-zero';
568
+ return;
569
+ }
570
+ event.status = 'front-unmix';
571
+ } else {
572
+ plan(target, q.p, P[0], P[1], P[2], 255);
573
+ for (const i of affected) if (i !== target) plan(i, q.p, 0, 0, 0, 0);
574
+ event.status = 'assigned';
575
+ return;
576
+ }
577
+ }
526
578
  // Busy ground: a BEHIND raise outside BEHIND's own support is refused in `plan`, so FRONT is not lowered there either —
527
579
  // FRONT keeps the coverage it had, and a seam whose two supports do not overlap is never left transparent.
528
580
  // The refused BEHIND raise below is the one counted in `skipped.support`.
@@ -539,6 +591,21 @@ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEd
539
591
  fills[q.behind].set(q.p, q.front);
540
592
  }
541
593
  });
594
+ // Clean refusals belong to the same plan as allocations, before its one
595
+ // applied piece guard. A scratch legacy evaluation supplies the predicate.
596
+ const fallback: Array<{ p: number; part: number; desired: readonly number[] }> = [];
597
+ for (const event of events) {
598
+ if (event.status !== 'refused' || existing === undefined || existing.defects[event.p] === 1) continue;
599
+ for (let i = 0; i < n; i++) {
600
+ const rgba = existing.parts[i].data.subarray(event.p * 4, event.p * 4 + 4);
601
+ const pre = parts[i].data.subarray(event.p * 4, event.p * 4 + 4);
602
+ if (pre.every((v, c) => v === rgba[c])) planned[i].delete(event.p);
603
+ else {
604
+ planned[i].set(event.p, [rgba[0], rgba[1], rgba[2], rgba[3]]);
605
+ fallback.push({ p: event.p, part: i, desired: Array.from(rgba) });
606
+ }
607
+ }
608
+ }
542
609
  // A part's art (alpha above the floor) keeps its pieces: rigc takes one closed outline per mesh, read 4-connected
543
610
  // (`CONTOUR_ONE_ISLAND`). A new piece holding none of the part's art is not written.
544
611
  planned.forEach((writes, i) => {
@@ -619,6 +686,43 @@ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEd
619
686
  }
620
687
  }
621
688
  });
689
+ const effective = (part: number, p: number): ArrayLike<number> => planned[part].get(p) ?? parts[part].data.subarray(p * 4, p * 4 + 4);
690
+ if (reading !== undefined) {
691
+ for (const row of fallback) {
692
+ const rgba = effective(row.part, row.p);
693
+ if (row.desired.some((v, c) => v !== rgba[c])) reading.fallbackHeld++;
694
+ }
695
+ }
696
+ for (const event of events) {
697
+ const offset = event.p * 4;
698
+ const desired = [srcr.data[offset], srcr.data[offset + 1], srcr.data[offset + 2], 255];
699
+ if (event.status === 'assigned') {
700
+ const held = event.affected.filter(i => {
701
+ const expected = i === event.target ? desired : [0, 0, 0, 0];
702
+ const rgba = effective(i, event.p);
703
+ return expected.some((v, c) => v !== rgba[c]);
704
+ });
705
+ if (held.length > 0) {
706
+ if (!held.includes(event.target) && event.target === event.behind && held.every(i => i === event.front)) {
707
+ // A held clear retains FRONT; BEHIND keeps its accepted own paint.
708
+ planned[event.front].delete(event.p);
709
+ event.status = 'retained-front';
710
+ } else {
711
+ for (const i of event.affected) planned[i].delete(event.p);
712
+ event.status = 'refused';
713
+ event.reason = 'piece-guard-allocation-held';
714
+ }
715
+ }
716
+ } else if (event.status === 'front-zero') {
717
+ const rgba = effective(event.front, event.p);
718
+ if (desired.some((v, c) => v !== rgba[c])) {
719
+ planned[event.front].delete(event.p);
720
+ event.status = 'refused';
721
+ event.reason = 'front-owner-zero-coverage-held';
722
+ }
723
+ }
724
+ if (event.status === 'refused' && reading !== undefined) reading.refused[event.reason] = (reading.refused[event.reason] ?? 0) + 1;
725
+ }
622
726
  const changed = parts.map(() => newMask(W, H));
623
727
  planned.forEach((writes, i) => {
624
728
  const d = parts[i].data;
@@ -727,5 +831,31 @@ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEd
727
831
  for (const p of writes.keys()) options.written?.(i, p);
728
832
  });
729
833
  for (const [p, front] of restore) if (!planned[front].has(p)) options.written?.(front, p);
730
- return { changed, resolved, unseparated, skipped };
834
+ return { changed, resolved, unseparated, skipped, ...(reading === undefined ? {} : { allocation: reading }) };
835
+ }
836
+
837
+ /** Apply the owner-aware plan after evaluating clean fallback on scratch art. */
838
+ export function paintingEdges(parts: Raster[], srcr: Raster, options: PaintingEdgeOptions): PaintingEdgeResult {
839
+ const allocation = options.owner;
840
+ if (allocation === undefined) return applyPaintingEdges(parts, srcr, options);
841
+ const scratch = parts.map(r => ({ ...r, data: new Uint8ClampedArray(r.data) }));
842
+ const decisions: Array<{ p: number; front: number; behind: number; alpha: number }> = [];
843
+ const old = applyPaintingEdges(scratch, srcr, { ...options, owner: undefined, written: undefined }, undefined,
844
+ (q, alpha) => decisions.push({ p: q.p, front: q.front, behind: q.behind, alpha }));
845
+ const defects = new Uint8Array(srcr.width * srcr.height);
846
+ // Survival is read at this edge pass's post-restoration output. Later
847
+ // assembly stages may replace a writer; they are outside this predicate.
848
+ for (const { p, front, behind, alpha } of decisions) {
849
+ const owner = allocation.pixels[p];
850
+ if (owner < 0) continue;
851
+ const offset = p * 4;
852
+ if (old.changed[front].data[p] === 1 && scratch[front].data[offset + 3] > 0 &&
853
+ allocation.roots[front] !== owner) defects[p] = 1;
854
+ if (behind < 0 || alpha !== 0 || !foreignPaintingReceiver(allocation, p, behind)) continue;
855
+ const pre = parts[behind].data;
856
+ const post = scratch[behind].data;
857
+ if ([0, 1, 2].some(c => pre[offset + c] !== post[offset + c]) &&
858
+ [0, 1, 2].every(c => post[offset + c] === srcr.data[offset + c]) && post[offset + 3] === 255) defects[p] = 1;
859
+ }
860
+ return applyPaintingEdges(parts, srcr, options, { parts: scratch, defects });
731
861
  }
@@ -0,0 +1,90 @@
1
+ import { type Mask, type Raster } from './raster/types.ts';
2
+
3
+ /** A named owner supplier, independent of the edge estimator and receivers. */
4
+ export interface PaintingOwner {
5
+ supplier: string;
6
+ names: readonly string[];
7
+ pixels: Int32Array;
8
+ }
9
+
10
+ export interface PaintingReceivers extends PaintingOwner {
11
+ receiverNames: readonly string[];
12
+ roots: Int32Array;
13
+ receivers: Int32Array;
14
+ reasons: string[];
15
+ faults: Array<{ receiver: string; reason: string }>;
16
+ }
17
+
18
+ /** Owner (a), the last raw plan layer at alpha >=128 on the rig canvas. */
19
+ export function rawPaintingOwner(raw: ReadonlyArray<{ name: string; raster: Raster }>, pixels: number): PaintingOwner {
20
+ const owner = new Int32Array(pixels).fill(-1);
21
+ raw.forEach(({ raster }, i) => {
22
+ for (let p = 0; p < pixels; p++) if (raster.data[p * 4 + 3] >= 128) owner[p] = i;
23
+ });
24
+ return { supplier: 'owner-a/raw-plan-alpha>=128', names: raw.map(q => q.name), pixels: owner };
25
+ }
26
+
27
+ /** Resolve declared cut/limb ancestry, frozen support and production regions. */
28
+ export function paintingReceivers(
29
+ owner: PaintingOwner,
30
+ parts: ReadonlyArray<{ name: string; image: Raster; region: Mask | null }>,
31
+ lineage: ReadonlyArray<readonly [string, string]>,
32
+ ): PaintingReceivers {
33
+ const parents = new Map<string, string[]>();
34
+ for (const [from, into] of lineage) parents.set(into, [...(parents.get(into) ?? []), from]);
35
+ const ancestors = (name: string, path: readonly string[] = []): string[] | null => {
36
+ if (path.includes(name)) return null;
37
+ const sources = parents.get(name) ?? [];
38
+ if (sources.length === 0) return owner.names.includes(name) ? [name] : [];
39
+ const roots: string[] = [];
40
+ for (const source of sources) {
41
+ const found = ancestors(source, [...path, name]);
42
+ if (found === null) return null;
43
+ roots.push(...found);
44
+ }
45
+ return [...new Set(roots)];
46
+ };
47
+ const roots = new Int32Array(parts.length).fill(-1);
48
+ const faults: PaintingReceivers['faults'] = [];
49
+ parts.forEach((part, i) => {
50
+ const found = ancestors(part.name);
51
+ if (found === null || found.length !== 1) {
52
+ faults.push({ receiver: part.name, reason: found === null ? 'cycle' : found.length === 0 ? 'missing-lineage' : 'multiple-ancestors' });
53
+ } else roots[i] = owner.names.indexOf(found[0]);
54
+ });
55
+ const receivers = new Int32Array(owner.pixels.length).fill(-1);
56
+ const reasons = new Array<string>(owner.pixels.length).fill('no-owner');
57
+ for (let p = 0; p < owner.pixels.length; p++) {
58
+ if (owner.pixels[p] < 0) continue;
59
+ let target = -1;
60
+ let ambiguous = false;
61
+ for (let i = 0; i < parts.length; i++) {
62
+ const part = parts[i];
63
+ if (roots[i] !== owner.pixels[p] || part.image.data[p * 4 + 3] === 0 ||
64
+ (part.region !== null && part.region.data[p] !== 1)) continue;
65
+ if (target >= 0) { ambiguous = true; break; }
66
+ target = i;
67
+ }
68
+ if (ambiguous) reasons[p] = 'multiple-receivers';
69
+ else if (target < 0) reasons[p] = 'no-supported-receiver';
70
+ else { receivers[p] = target; reasons[p] = 'unique'; }
71
+ }
72
+ return { ...owner, receiverNames: parts.map(q => q.name), roots, receivers, reasons, faults };
73
+ }
74
+
75
+ /** A refusal names the missing owner or the receiver contract it violates. */
76
+ export function paintingReceiverAt(input: PaintingReceivers, p: number): { target: number; reason: string } {
77
+ const owner = input.pixels[p];
78
+ if (owner === -2) return { target: -1, reason: 'mixed-owner' };
79
+ if (owner < 0) return { target: -1, reason: 'no-owner' };
80
+ if (input.names[owner] === undefined) return { target: -1, reason: 'unknown-owner' };
81
+ const target = input.receivers[p];
82
+ if (target < 0) return { target: -1, reason: input.reasons[p] };
83
+ if (input.roots[target] !== owner) return { target: -1, reason: 'receiver-owner-mismatch' };
84
+ return { target, reason: 'unique' };
85
+ }
86
+
87
+ /** Refused known-owner writes remain foreign to the receiver contract. */
88
+ export function foreignPaintingReceiver(input: PaintingReceivers, p: number, receiver: number): boolean {
89
+ return input.pixels[p] >= 0 && (input.receivers[p] !== receiver || input.roots[receiver] !== input.pixels[p]);
90
+ }