Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Making the scrubber sticky #955

Merged
merged 2 commits into from
Jan 15, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,6 @@

Thank you for contributing to developer happiness all over the world!

For notes on contributing to BackstopJS please see https://github.com/garris/BackstopJS/blob/master/README.md#developing-bug-fixing-contributing
For notes on contributing to BackstopJS please see [Developing, bug fixing, contributing...](./README.md#developing-bug-fixing-contributing)

☮️
86 changes: 28 additions & 58 deletions compare/output/diverged.js
Original file line number Diff line number Diff line change
@@ -1,25 +1,19 @@
'use strict';
const noop = function (){};
let LCS_DIFF_ARRAY_METHOD = undefined;

let MEYERS_DIFF_ARRAY_METHOD = undefined;
// debugger
if (typeof require !== 'undefined') {
LCS_DIFF_ARRAY_METHOD = require('diff').diffArrays;
MEYERS_DIFF_ARRAY_METHOD = require('diff').diffArrays;
} else {
try {
LCS_DIFF_ARRAY_METHOD = JsDiff.diffArrays;
} catch(err) {
console.error(err);
}
MEYERS_DIFF_ARRAY_METHOD = JsDiff.diffArrays;
}

const rowSpread = 1;

const spread = 50; // range of adjacent pixels to aggregate when calculating diff
const IS_ADDED_WORD = '0_255_0_255';
const IS_REMOVED_WORD = '255_0_0_255';
const IS_ADDED_AND_REMOVED_WORD = '0_255_255_255';
const IS_SAME_WORD = '';
const OPACITY = '40'; // 0-255 range
const OPACITY = '30'; // 0-255 range

/**
* Applies meyers-diff algorithm to imageData formatted arrays
Expand Down Expand Up @@ -66,7 +60,7 @@ function diverged(reference, test, h, w) {
// console.log("reducedColumnDiff>>>", reducedColumnDiff);

console.time("unGroupAdjacent");
const expandedColumns = ungroupAdjacent(reducedColumnDiff, spread, cols_rows_test.columns, h, w);
const expandedColumns = ungroupAdjacent(reducedColumnDiff, spread, cols_rows_ref.columns, h, w);
console.timeEnd("unGroupAdjacent");

console.time("columnWordDataToImgDataFormatAsWords");
Expand Down Expand Up @@ -124,7 +118,6 @@ function reduceColumnDiffRaw(columnDiffs, h, w) {
for (let depthIndex = 0; depthIndex < columnDiff.length; depthIndex++) {
let segmentLength = 0;

// Categorize the current segment
if (columnDiff[depthIndex].removed) {
segmentLength = columnDiff[depthIndex].count;
removedCounter += segmentLength;
Expand All @@ -140,6 +133,7 @@ function reduceColumnDiffRaw(columnDiffs, h, w) {
resultClass = IS_SAME_WORD;
}


segmentLength = columnDiff[depthIndex].count;

if (removedCounter > 0) {
Expand All @@ -153,15 +147,14 @@ function reduceColumnDiffRaw(columnDiffs, h, w) {
}
}

// Limit segmentLength to total length of column
if (!segmentLength) {
continue;
} else {
segmentLength = Math.min(segmentLength, h - resultColumn.length);
}

const printSampleMap = false;
if (!printSampleMap || resultClass !== IS_SAME_WORD){

if (debug || resultClass !== IS_SAME_WORD){
segment = new Array(segmentLength).fill(resultClass);
} else {
// reduced resolution image
Expand Down Expand Up @@ -190,7 +183,7 @@ function reduceColumnDiffRaw(columnDiffs, h, w) {
function diffArr(refArr, testArr, h, w) {
let rawResultArr = [];
for (let i = 0; i < refArr.length; i++) {
rawResultArr.push(LCS_DIFF_ARRAY_METHOD(refArr[i], testArr[i]));
rawResultArr.push(MEYERS_DIFF_ARRAY_METHOD(refArr[i], testArr[i]));
}
return rawResultArr;
}
Expand Down Expand Up @@ -223,47 +216,26 @@ function groupAdjacent(columns, spread, h, w) {
return interpolated;
}

function getCompositeColumnDepthValues(columns, sequence, depth) {
return sequence.reduce((acc, column) => {
function getCompositeColumnDepthValues(columns, range, depth) {
return range.reduce((acc, column) => {
return acc.concat(columns[column][depth]);
}, [])
}

function getCompositeRowIndexValues(groupedColumns, sequence, column) {
return sequence.reduce((acc, depth) => {
return acc.concat(groupedColumns[column][depth]);
}, [])
}

const groupedColumns = new Array();
let columnPointer = 0;
while (columnPointer < w) {
const adjacentColumnBounds = getAdjacentArrayBounds(columnPointer, spread, w);
const interpolatedColumns = getInterpolatedSequence(...adjacentColumnBounds);
const interpolatedColumnsValues = new Array();
let i = 0;
while (i < w) {
const adjacentBounds = getAdjacentArrayBounds(i, spread, w);
const interpolatedColumns = getInterpolatedSequence(...adjacentBounds);

const columnComposite = new Array();
const columnComposite = new Array(h);
for (var depth = 0; depth < h; depth++) {
columnComposite[depth] = getCompositeColumnDepthValues(columns, interpolatedColumns, depth).join('|');
}
groupedColumns.push(columnComposite);
columnPointer += spread;
}

const groupedRows = new Array();
if (rowSpread > 1) {
for (var index = 0; index < groupedColumns.length; index++) {
const rowComposite = new Array();
let depthPointer = 0;
while (depthPointer < h) {
const adjacentRowBounds = getAdjacentArrayBounds(depthPointer, rowSpread, h);
const interpolatedRows = getInterpolatedSequence(...adjacentRowBounds);
rowComposite.push(getCompositeRowIndexValues(groupedColumns, interpolatedRows, index).join(','));
depthPointer += rowSpread;
}
groupedRows[index] = rowComposite;
}
interpolatedColumnsValues.push(columnComposite);
i += spread;
}
return groupedRows.length ? groupedRows : groupedColumns ;
return interpolatedColumnsValues;
}

function ungroupAdjacent(grouped, spread, columnUnderlay, h, w) {
Expand All @@ -275,18 +247,16 @@ function ungroupAdjacent(grouped, spread, columnUnderlay, h, w) {
return Math.floor(index / spread);
}

// expand columns
const ungrouped = new Array(w);
for (let index = 0; index < w; index++) {
if (!ungrouped[index]) {
ungrouped[index] = new Array(h);
for (let i = 0; i < w; i++) {
if (!ungrouped[i]) {
ungrouped[i] = new Array(h);
}

const groupedIndexMap = mapUngroupedColumnIndexToGroupedIndex(index, spread);
for (let depth = 0; depth < h; depth++) {
const groupedDepthMap = rowSpread > 1 ? mapUngroupedColumnIndexToGroupedIndex(depth, rowSpread) : depth;
const value = grouped[groupedIndexMap][groupedDepthMap].split('|')[0];
ungrouped[index][depth] = value ? value : columnUnderlay[index][depth].replace(/\d+$/, OPACITY);
const groupedIndex = mapUngroupedColumnIndexToGroupedIndex(i, spread);
for (let j = 0; j < h; j++) {
const value = grouped[groupedIndex][j].split('|')[0];
ungrouped[i][j] = value ? value : columnUnderlay[i][j].replace(/\d+$/, OPACITY);
}
}

Expand Down
Loading