import '../../assert/js/assert.js';
import '../../globals.js';
import optionize from '../../phet-core/js/optionize.js';
import tambo from './tambo.js';
class BinMapper {
    constructor(valueRange, numBins, providedOptions) {
        // parameter checking
        assert && assert(numBins > 0);
        const options = optionize()({
            tolerateOutOfRangeValues: false
        }, providedOptions);
        this.minValue = valueRange.min;
        this.maxValue = valueRange.max;
        this.span = valueRange.getLength();
        this.numBins = numBins;
        this.options = options;
    }
    /**
     * Map the provided value to a bin.
     */
    mapToBin(value) {
        if (!this.options.tolerateOutOfRangeValues) {
            assert && assert(value <= this.maxValue);
            assert && assert(value >= this.minValue);
        }
        const proportion = (value - this.minValue) / (this.span);
        // this calculation means that values on the boundaries will go into the higher bin except for the max value
        return Math.min(Math.floor(proportion * this.numBins), this.numBins - 1);
    }
}
tambo.register('BinMapper', BinMapper);
export default BinMapper;
//# sourceMappingURL=BinMapper.js.map