/*!
 * Copyright (c) 2026 Vertex Software LLC. All rights reserved.
 */
import { Point, Rectangle } from "@vertexvis/geometry";
import { Color } from "@vertexvis/utils";
import { flattenPointArray } from "./util";
export class Drawable {
    constructor(createShape, identifier, points, outlineColor, fillColor, shapeProps = {}, disabled = false) {
        this.createShape = createShape;
        this.identifier = identifier;
        this.points = points;
        this.outlineColor = outlineColor;
        this.fillColor = fillColor;
        this.shapeProps = shapeProps;
        this.disabled = disabled;
        const pointsAsArray = points.toArray();
        this.pointsArray = new Float64Array(pointsAsArray.length * 2 + 4);
        flattenPointArray(pointsAsArray).forEach((v, i) => (this.pointsArray[i] = v));
        this.initialFillColor = fillColor;
        this.draw = createShape(this.pointsArray, {
            count: pointsAsArray.length,
            thickness: 2,
            join: 'rect',
            fill: this.fillColor,
            color: this.outlineColor,
            ...shapeProps,
        });
    }
    updateFillColor(color, isInitialColor = false) {
        if (color != null) {
            this.fillColor =
                typeof color === 'string' ? color : Color.toHexString(color);
            this.initialFillColor = isInitialColor
                ? this.fillColor
                : this.initialFillColor;
        }
    }
    updateOutlineColor(color) {
        if (color != null) {
            this.outlineColor =
                typeof color === 'string' ? color : Color.toHexString(color);
        }
    }
    updatePoints(points) {
        if (points != null) {
            this.points = points;
            flattenPointArray(points.toArray()).forEach((v, i) => (this.pointsArray[i] = v));
        }
    }
}
export function computeDrawable2dBounds(viewport, ...elements) {
    let min = Point.create(Number.MAX_SAFE_INTEGER, Number.MAX_SAFE_INTEGER);
    let max = Point.create();
    elements
        .filter((m) => m.points.valid)
        .forEach((m) => {
        m.points
            .toArray()
            .map((pt) => viewport.transformNdcPointToViewport(pt))
            .forEach((pt) => {
            min = Point.create(Math.min(pt.x, min.x), Math.min(pt.y, min.y));
            max = Point.create(Math.max(pt.x, max.x), Math.max(pt.y, max.y));
        });
    });
    return Rectangle.fromPoints(min, max);
}
//# sourceMappingURL=drawable.js.map
