import '../../globals.js';
// Copyright 2020-2023, University of Colorado Boulder
/**
 * Draws a set of lines within a graph.  For example, the minor horizontal lines.  Back-computes the model
 * locations given the view area.
 *
 * See also CanvasGridLineSet for one that renders to canvas. Note, these 2 files should be maintained together,
 * to keep as similar an API as possible.
 *
 * @author Sam Reid (PhET Interactive Simulations)
 */
import { Shape } from '../../kite/js/imports.js';
import Orientation from '../../phet-core/js/Orientation.js';
import { Path } from '../../scenery/js/imports.js';
import bamboo from './bamboo.js';
import optionize from '../../phet-core/js/optionize.js';
class GridLineSet extends Path {
    /**
     * @param chartTransform
     * @param axisOrientation - axis along which successive grid lines appear.  For example,
     *                                      - grid lines that are drawn horizontally progress up the Orientation.VERTICAL axis
     * @param spacing - in model coordinates
     * @param [providedOptions]
     */
    constructor(chartTransform, axisOrientation, spacing, providedOptions) {
        const options = optionize()({
            // SelfOptions
            origin: 0,
            clippingType: 'strict',
            // Path options
            stroke: 'black'
        }, providedOptions);
        super(null, options);
        this.chartTransform = chartTransform;
        this.axisOrientation = axisOrientation;
        this.spacing = spacing;
        this.origin = options.origin;
        this.clippingType = options.clippingType;
        // Initialize
        this.update();
        // Update when the transform changes.
        const changedListener = () => this.update();
        chartTransform.changedEmitter.addListener(changedListener);
        this.disposeGridLineSet = () => chartTransform.changedEmitter.removeListener(changedListener);
    }
    update() {
        const shape = new Shape();
        this.chartTransform.forEachSpacing(this.axisOrientation, this.spacing, this.origin, this.clippingType, (modelPosition, viewPosition) => {
            if (this.axisOrientation === Orientation.VERTICAL) {
                shape.moveTo(0, viewPosition);
                shape.lineTo(this.chartTransform.viewWidth, viewPosition);
            }
            else {
                shape.moveTo(viewPosition, 0);
                shape.lineTo(viewPosition, this.chartTransform.viewHeight);
            }
        });
        this.shape = shape.makeImmutable();
    }
    setSpacing(spacing) {
        if (this.spacing !== spacing) {
            this.spacing = spacing;
            this.update();
        }
    }
    getSpacing() {
        return this.spacing;
    }
    dispose() {
        this.disposeGridLineSet();
        super.dispose();
    }
    getSpacingBorders() {
        return this.chartTransform.getSpacingBorders(this.axisOrientation, this.spacing, this.origin, this.clippingType);
    }
}
bamboo.register('GridLineSet', GridLineSet);
export default GridLineSet;
//# sourceMappingURL=GridLineSet.js.map