@rig-c/parts 1.41.1 → 1.43.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/rig.ts CHANGED
@@ -757,6 +757,30 @@ export function influenceReach(points: ReadonlyArray<readonly [number, number]>,
757
757
  return best;
758
758
  }
759
759
 
760
+ /**
761
+ * Issue #518: the figure {@link influenceReach} holds an influence mesh's radius above, measured as the rig stage
762
+ * measures it — rig-c's segments lattice at `cell` over the part padded by {@link PAD} (alpha above
763
+ * {@link INFLUENCE_THRESHOLD}), and each vertex's distance to its nearest of `segs` (rig px, as the bones place them)
764
+ * — for `propose` to draft a radius from before any rig is built. Null when rig-c's lattice refuses the part, which
765
+ * the rig stage then names (`RIG_INFLUENCE_LATTICE`).
766
+ */
767
+ export function influenceFarthest(img: Raster, x: number, y: number, segs: readonly Segment[], cell: number): number | null {
768
+ const padded = pad(img, PAD, PAD, PAD, PAD, [0, 0, 0, 0]);
769
+ const alpha = new Uint8Array(padded.width * padded.height);
770
+ for (let i = 0; i < alpha.length; i++) alpha[i] = padded.data[i * 4 + 3];
771
+ let lattice: SegmentsLattice;
772
+ try {
773
+ lattice = buildSegmentsLattice({ mask: { width: padded.width, height: padded.height, alpha }, threshold: INFLUENCE_THRESHOLD, cell });
774
+ } catch {
775
+ return null;
776
+ }
777
+ const ox = x - PAD;
778
+ const oy = y - PAD;
779
+ const names = [...new Set(segs.map((s) => s.bone))];
780
+ const local: EntrySegment[] = segs.map((s) => ({ bone: names.indexOf(s.bone), entry: 0, a: [s.a[0] - ox, s.a[1] - oy], b: [s.b[0] - ox, s.b[1] - oy] }));
781
+ return influenceReach(lattice.points, local, names).distance;
782
+ }
783
+
760
784
  /**
761
785
  * Whether a declared radius reaches a vertex `distance` px from its nearest link: a link pulls only when it is NEARER
762
786
  * than radius (rig-c's `d < radius`; the pull is 0 at d = radius), so a radius equal to the distance does not.