MCPcopy Create free account
hub / github.com/DeusData/codebase-memory-mcp / shiftedDifference

Function shiftedDifference

graph-ui/tools/smoke-w10.mjs:756–837  ·  view source on GitHub ↗
(page, options)

Source from the content-addressed store, hash-verified

754 * nachgerechnet.
755 */
756const shiftedDifference = (page, options) =>
757 page.evaluate((input) => {
758 const store = globalThis.__w10 ?? {};
759 const first = store[input.base];
760 const second = store[input.variant];
761 if (first === undefined || second === undefined) {
762 return null;
763 }
764 const width = first.width;
765 const height = first.height;
766 if (second.width !== width || second.height !== height) {
767 return null;
768 }
769 const grey = (image) => {
770 const out = new Float64Array(width * height);
771 for (let i = 0, p = 0; i < image.data.length; i += 4, p += 1) {
772 out[p] = (image.data[i] + image.data[i + 1] + image.data[i + 2]) / 3;
773 }
774 return out;
775 };
776 const a = grey(first);
777 const b = grey(second);
778 const columns = (values) => {
779 const sums = new Float64Array(width);
780 for (let y = 0; y < height; y += 1) {
781 const row = y * width;
782 for (let x = 0; x < width; x += 1) {
783 sums[x] += values[row + x];
784 }
785 }
786 return sums;
787 };
788 const columnsA = columns(a);
789 const columnsB = columns(b);
790 /* Der Versatz, bei dem die Spaltensummen am besten zusammenpassen. */
791 let bestShift = 0;
792 let bestScore = Number.POSITIVE_INFINITY;
793 for (let shift = -input.maxShift; shift <= input.maxShift; shift += 1) {
794 let sum = 0;
795 let count = 0;
796 for (let x = 0; x < width; x += 1) {
797 const source = x + shift;
798 if (source < 0 || source >= width) {
799 continue;
800 }
801 sum += Math.abs(columnsA[source] - columnsB[x]);
802 count += 1;
803 }
804 if (count < width / 2) {
805 continue;
806 }
807 const score = sum / count;
808 if (score < bestScore) {
809 bestScore = score;
810 bestShift = shift;
811 }
812 }
813 /* Und derselbe Vergleich am ganzen Bild: ohne Versatz und mit dem besten. */

Callers 1

dragProbeFunction · 0.85

Calls 3

greyFunction · 0.85
residualAtFunction · 0.85
columnsFunction · 0.70

Tested by

no test coverage detected