"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.TempColorizer = exports.SpeedColorizer = exports.LutColorizer = exports.SimpleColorizer = exports.LineColorizer = void 0;
const three_1 = require("three");
const Lut_1 = require("three/examples/jsm/math/Lut");
const DEFAULT_COLOR = new three_1.Color("#29BEB0");
class LineColorizer {
    constructor(lineColorConfig, options) {
        this.lineColorConfig = lineColorConfig;
        this.options = options;
        // This assumes that getColor is called ordered by gCodeLine.
        this.currentConfigIndex = 0;
    }
    getColor(meta) {
        var _a, _b;
        // Safeguard check if the config is too short.
        if (this.lineColorConfig[this.currentConfigIndex] === undefined) {
            return ((_a = this.options) === null || _a === void 0 ? void 0 : _a.defaultColor) || DEFAULT_COLOR;
        }
        if (this.lineColorConfig[this.currentConfigIndex].toLine < meta.gCodeLine) {
            this.currentConfigIndex++;
        }
        return this.lineColorConfig[this.currentConfigIndex].color || ((_b = this.options) === null || _b === void 0 ? void 0 : _b.defaultColor) || DEFAULT_COLOR;
    }
}
exports.LineColorizer = LineColorizer;
class SimpleColorizer {
    constructor(color = DEFAULT_COLOR) {
        this.color = color;
    }
    getColor() {
        return this.color;
    }
}
exports.SimpleColorizer = SimpleColorizer;
class LutColorizer {
    constructor(lut = new Lut_1.Lut("cooltowarm")) {
        this.lut = lut;
    }
}
exports.LutColorizer = LutColorizer;
class SpeedColorizer extends LutColorizer {
    constructor(minSpeed, maxSpeed) {
        super();
        this.lut.setMin(minSpeed);
        this.lut.setMax(maxSpeed);
    }
    getColor(meta) {
        return this.lut.getColor(meta.speed);
    }
}
exports.SpeedColorizer = SpeedColorizer;
class TempColorizer extends LutColorizer {
    constructor(minTemp, maxTemp) {
        super();
        this.lut.setMin(minTemp);
        this.lut.setMax(maxTemp);
    }
    getColor(meta) {
        return this.lut.getColor(meta.temp);
    }
}
exports.TempColorizer = TempColorizer;
