static patternMatchVariance(counters, pattern, maxIndividualVariance) {
        const numCounters = counters.length;
        let total = 0;
        let patternLength = 0;
        for (let i = 0; i < numCounters; i++) {
            total += counters[i];
            patternLength += pattern[i];
        }
        if (total < patternLength) {
            // If we don't even have one pixel per unit of bar width, assume this is too small
            // to reliably match, so fail:
            return Number.POSITIVE_INFINITY;
        }
        const unitBarWidth = total / patternLength;
        maxIndividualVariance *= unitBarWidth;
        let totalVariance = 0.0;
        for (let x = 0; x < numCounters; x++) {
            const counter = counters[x];
            const scaledPattern = pattern[x] * unitBarWidth;
            const variance = counter > scaledPattern ? counter - scaledPattern : scaledPattern - counter;
            if (variance > maxIndividualVariance) {
                return Number.POSITIVE_INFINITY;
            }
            totalVariance += variance;
        }
        return totalVariance / total;
    }
/**
     * Determines how closely a set of observed counts of runs of black/white values matches a given
     * target pattern. This is reported as the ratio of the total variance from the expected pattern
     * proportions across all pattern elements, to the length of the pattern.
     *
     * @param counters observed counters
     * @param pattern expected pattern
     * @param maxIndividualVariance The most any counter can differ before we give up
     * @return ratio of total variance between counters and pattern compared to total pattern size
     */
Determines how closely a set of observed counts of runs of black/white values matches a given
target pattern. This is reported as the ratio of the total variance from the expected pattern
proportions across all pattern elements, to the length of the pattern.

@param counters observed counters
@param pattern expected pattern
@param maxIndividualVariance The most any counter can differ before we give up
@return ratio of total variance between counters and pattern compared to total pattern size
Determines how closely a set of observed counts of runs of black / white values matches a given target pattern . This is reported as the ratio of the total variance from the expected pattern proportions across all pattern elements to the length of the pattern . @param counters observed counters @param pattern expected pattern @param maxIndividualVariance The most any counter can differ before we give up @return ratio of total variance between counters and pattern compared to total pattern size
static patternMatchVariance(counters, pattern, maxIndividualVariance) {
        const numCounters = counters.length;
        let total = 0;
        let patternLength = 0;
        for (let i = 0; i < numCounters; i++) {
            total += counters[i];
            patternLength += pattern[i];
        }
        if (total < patternLength) {
            return Number.POSITIVE_INFINITY;
        }
        const unitBarWidth = total / patternLength;
        maxIndividualVariance *= unitBarWidth;
        let totalVariance = 0.0;
        for (let x = 0; x < numCounters; x++) {
            const counter = counters[x];
            const scaledPattern = pattern[x] * unitBarWidth;
            const variance = counter > scaledPattern ? counter - scaledPattern : scaledPattern - counter;
            if (variance > maxIndividualVariance) {
                return Number.POSITIVE_INFINITY;
            }
            totalVariance += variance;
        }
        return totalVariance / total;
    }
static patternMatchVariance ( counters , pattern , maxIndividualVariance ) { const numCounters = counters . length ; let total = 0 ; let patternLength = 0 ; for ( let i = 0 ; i < numCounters ; i ++ ) { total += counters [ i ] ; patternLength += pattern [ i ] ; } if ( total < patternLength ) { return Number . POSITIVE_INFINITY ; } const unitBarWidth = total / patternLength ; maxIndividualVariance *= unitBarWidth ; let totalVariance = 0.0 ; for ( let x = 0 ; x < numCounters ; x ++ ) { const counter = counters [ x ] ; const scaledPattern = pattern [ x ] * unitBarWidth ; const variance = counter > scaledPattern ? counter - scaledPattern : scaledPattern - counter ; if ( variance > maxIndividualVariance ) { return Number . POSITIVE_INFINITY ; } totalVariance += variance ; } return totalVariance / total ; }
Determines how closely a set of observed counts of runs of black/white values matches a given
 target pattern.
Determines how closely a set of observed counts of runs of black / white values matches a given target pattern .
// If we don't even have one pixel per unit of bar width, assume this is too small // to reliably match, so fail: