import _ from 'lodash';
import '../../../../assert/js/assert.js';
import '../../../../globals.js';
// Copyright 2023-2024, University of Colorado Boulder
/**
 * Like RasterChunkReduceQuad, but for the initial case where our left/right values are the same, and we can do a
 * slightly different optimized reduce.
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import { alpenglow, RasterChunkReduceData } from '../../imports.js';
class RasterChunkReducePair {
    constructor(min, max) {
        this.min = min;
        this.max = max;
        assert && assert(min.isFirstEdge === max.isFirstEdge);
        assert && assert(min.isLastEdge === max.isLastEdge);
        assert && assert(isFinite(min.clippedChunkIndex) && min.clippedChunkIndex > 0 ? (min.clippedChunkIndex + 1 === max.clippedChunkIndex) : true);
    }
    isFirstEdge() {
        return this.min.isFirstEdge;
    }
    isLastEdge() {
        return this.min.isLastEdge;
    }
    static combine(a, b) {
        return new RasterChunkReducePair(RasterChunkReduceData.combine(a.min, b.min), RasterChunkReduceData.combine(a.max, b.max));
    }
    toStrings() {
        return [
            `min: ${this.min.toString()}`,
            `max: ${this.max.toString()}`
        ];
    }
    writeEncoding(encoder) {
        this.min.writeEncoding(encoder);
        this.max.writeEncoding(encoder);
    }
    static readEncoding(arrayBuffer, byteOffset) {
        return new RasterChunkReducePair(RasterChunkReduceData.readEncoding(arrayBuffer, byteOffset), RasterChunkReduceData.readEncoding(arrayBuffer, byteOffset + RasterChunkReduceData.ENCODING_BYTE_LENGTH));
    }
    static fromArrayBuffer(arrayBuffer) {
        assert && assert(arrayBuffer.byteLength % RasterChunkReducePair.ENCODING_BYTE_LENGTH === 0);
        return _.range(0, arrayBuffer.byteLength / RasterChunkReducePair.ENCODING_BYTE_LENGTH).map(i => {
            return RasterChunkReducePair.readEncoding(arrayBuffer, i * RasterChunkReducePair.ENCODING_BYTE_LENGTH);
        });
    }
}
RasterChunkReducePair.ENCODING_BYTE_LENGTH = 2 * RasterChunkReduceData.ENCODING_BYTE_LENGTH;
RasterChunkReducePair.INDETERMINATE = new RasterChunkReducePair(RasterChunkReduceData.INDETERMINATE, RasterChunkReduceData.INDETERMINATE);
RasterChunkReducePair.OUT_OF_RANGE = new RasterChunkReducePair(RasterChunkReduceData.OUT_OF_RANGE, RasterChunkReduceData.OUT_OF_RANGE);
export default RasterChunkReducePair;
alpenglow.register('RasterChunkReducePair', RasterChunkReducePair);
//# sourceMappingURL=RasterChunkReducePair.js.map