import '../../../assert/js/assert.js';
import '../../../globals.js';
// Copyright 2023-2024, University of Colorado Boulder
/**
 * Represents a path that controls what regions things are drawn in.
 *
 * @author Jonathan Olson <jonathan.olson@colorado.edu>
 */
import Bounds2 from '../../../dot/js/Bounds2.js';
import Vector2 from '../../../dot/js/Vector2.js';
import { alpenglow } from '../imports.js';
let globalPathId = 0;
export default class RenderPath {
    constructor(fillRule, subpaths) {
        this.fillRule = fillRule;
        this.subpaths = subpaths;
        this.id = globalPathId++;
        assert && subpaths.forEach(subpath => subpath.forEach(point => {
            assert && assert(point.isFinite());
        }));
    }
    transformed(transform) {
        return new RenderPath(this.fillRule, this.subpaths.map(subpath => subpath.map(point => transform.timesVector2(point))));
    }
    getBounds() {
        const bounds = Bounds2.NOTHING.copy();
        for (let i = 0; i < this.subpaths.length; i++) {
            const subpath = this.subpaths[i];
            for (let j = 0; j < subpath.length; j++) {
                bounds.addPoint(subpath[j]);
            }
        }
        return bounds;
    }
    /**
     * Without scanning the entire path, returns whether we can guarantee that this path is empty and has zero area.
     */
    isTriviallyEmpty() {
        // TODO: if we support an inverted fill rule, this logic will need to change!
        return this.subpaths.every(subpath => subpath.length < 3);
    }
    serialize() {
        return {
            fillRule: this.fillRule,
            subpaths: this.subpaths.map(subpath => subpath.map(point => ({ x: point.x, y: point.y })))
        };
    }
    static deserialize(obj) {
        return new RenderPath(obj.fillRule, obj.subpaths.map(subpath => subpath.map(point => new Vector2(point.x, point.y))));
    }
    static fromBounds(bounds) {
        return new RenderPath('nonzero', [
            [
                new Vector2(bounds.minX, bounds.minY),
                new Vector2(bounds.maxX, bounds.minY),
                new Vector2(bounds.maxX, bounds.maxY),
                new Vector2(bounds.minX, bounds.maxY)
            ]
        ]);
    }
}
alpenglow.register('RenderPath', RenderPath);
//# sourceMappingURL=RenderPath.js.map