import _ from 'lodash';
import '../../../../assert/js/assert.js';
import '../../../../globals.js';
// Copyright 2023-2024, University of Colorado Boulder
/**
 * A pair of counts (reducible/complete).
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import { alpenglow } from '../../imports.js';
class RasterSplitReduceData {
    constructor(numReducible, numComplete) {
        this.numReducible = numReducible;
        this.numComplete = numComplete;
    }
    toString() {
        if (isNaN(this.numReducible)) {
            return 'RasterSplitReduceData[INDETERMINATE]';
        }
        return `RasterSplitReduceData[reduce:${this.numReducible} complete:${this.numComplete}]`;
    }
    writeEncoding(encoder) {
        encoder.pushU32(this.numReducible);
        encoder.pushU32(this.numComplete);
    }
    static readEncoding(arrayBuffer, byteOffset) {
        const uintBuffer = new Uint32Array(arrayBuffer, byteOffset, RasterSplitReduceData.ENCODING_BYTE_LENGTH / 4);
        return new RasterSplitReduceData(uintBuffer[0], uintBuffer[1]);
    }
    static fromArrayBuffer(arrayBuffer) {
        assert && assert(arrayBuffer.byteLength % RasterSplitReduceData.ENCODING_BYTE_LENGTH === 0);
        return _.range(0, arrayBuffer.byteLength / RasterSplitReduceData.ENCODING_BYTE_LENGTH).map(i => {
            return RasterSplitReduceData.readEncoding(arrayBuffer, i * RasterSplitReduceData.ENCODING_BYTE_LENGTH);
        });
    }
    static combine(a, b) {
        return new RasterSplitReduceData(a.numReducible + b.numReducible, a.numComplete + b.numComplete);
    }
    static from(edgeClip, clippedChunk, exists) {
        const isReducible = clippedChunk.isReducible;
        const count = exists ? edgeClip.getCount() : 0;
        return new RasterSplitReduceData(isReducible ? count : 0, clippedChunk.isExportingCompleteEdges() ? count : 0);
    }
}
RasterSplitReduceData.ENCODING_BYTE_LENGTH = 4 * 2;
RasterSplitReduceData.INDETERMINATE = new RasterSplitReduceData(NaN, NaN);
RasterSplitReduceData.IDENTITY = new RasterSplitReduceData(0, 0);
export default RasterSplitReduceData;
alpenglow.register('RasterSplitReduceData', RasterSplitReduceData);
//# sourceMappingURL=RasterSplitReduceData.js.map