"use strict";
/*---------------------------------------------------------------------------------------------
* Copyright (c) Bentley Systems, Incorporated. All rights reserved.
* See LICENSE.md in the project root for license terms and full copyright notice.
*--------------------------------------------------------------------------------------------*/
/** @packageDocumentation
 * @module DisplayStyles
 */
Object.defineProperty(exports, "__esModule", { value: true });
exports.SolarShadowSettings = void 0;
const core_bentley_1 = require("@itwin/core-bentley");
const ColorByName_1 = require("./ColorByName");
const ColorDef_1 = require("./ColorDef");
const RgbColor_1 = require("./RgbColor");
const defaultColor = RgbColor_1.RgbColor.fromColorDef(ColorDef_1.ColorDef.fromTbgr(ColorByName_1.ColorByName.grey));
/** Settings controlling display of solar shadows for a [[DisplayStyle3dSettings]].
 * Solar shadows are imposed as a color scaling on geometry occluded from solar lighting.
 * @public
 */
class SolarShadowSettings {
    constructor(props) {
        this.bias = core_bentley_1.JsonUtils.asDouble(props.bias, 0.001);
        if (undefined === props.color || null === props.color)
            this.color = defaultColor;
        else
            this.color = RgbColor_1.RgbColor.fromColorDef(ColorDef_1.ColorDef.fromJSON(props.color));
    }
    static fromJSON(props) {
        return props ? new SolarShadowSettings(props) : this.defaults;
    }
    toJSON() {
        const defaults = SolarShadowSettings.defaults;
        if (this.equals(defaults))
            return undefined;
        const props = {};
        if (!this.color.equals(defaults.color))
            props.color = this.color.toColorDef().toJSON();
        if (this.bias !== defaults.bias)
            props.bias = this.bias;
        return props;
    }
    equals(rhs) {
        return this.bias === rhs.bias && this.color.equals(rhs.color);
    }
    /** Create a copy of these settings.
     * @param changedProps Any property explicitly defined will be overridden in the copy.
     * @returns A settings object equivalent to this one except for any properties explicitly overridden by `changedProps`.
     */
    clone(changedProps) {
        if (!changedProps)
            return this;
        const props = this.toJSON() ?? {};
        if (changedProps.color)
            props.color = changedProps.color;
        if (undefined !== changedProps.bias)
            props.bias = changedProps.bias;
        return SolarShadowSettings.fromJSON(props);
    }
}
exports.SolarShadowSettings = SolarShadowSettings;
SolarShadowSettings.defaults = new SolarShadowSettings({});
//# sourceMappingURL=SolarShadows.js.map