UNPKG

@itwin/core-common

Version:

iTwin.js components common to frontend and backend

66 lines 2.45 kB
"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 Symbology */ Object.defineProperty(exports, "__esModule", { value: true }); exports.HSVColor = exports.HSVConstants = void 0; const ColorDef_1 = require("./ColorDef"); /** * @public * @extensions */ var HSVConstants; (function (HSVConstants) { HSVConstants[HSVConstants["VISIBILITY_GOAL"] = 40] = "VISIBILITY_GOAL"; HSVConstants[HSVConstants["HSV_SATURATION_WEIGHT"] = 4] = "HSV_SATURATION_WEIGHT"; HSVConstants[HSVConstants["HSV_VALUE_WEIGHT"] = 2] = "HSV_VALUE_WEIGHT"; })(HSVConstants || (exports.HSVConstants = HSVConstants = {})); /** An immutable color defined by Hue, Saturation, and Value * @see [here](https://en.wikipedia.org/wiki/HSL_and_HSV) for difference between HSL and HSV * @public */ class HSVColor { /** Hue */ h; /** Saturation */ s; /** Value */ v; constructor(hue = 0, saturation = 0, value = 0) { this.h = hue; this.s = saturation; this.v = value; } clone(hue, saturation, value) { return new HSVColor(hue ?? this.h, saturation ?? this.s, value ?? this.v); } toColorDef(transparency = 0) { return ColorDef_1.ColorDef.fromHSV(this, transparency); } static fromColorDef(val) { return val.toHSV(); } adjusted(darkenColor, delta) { let weightedDelta; if (darkenColor) { weightedDelta = delta * HSVConstants.HSV_VALUE_WEIGHT; if (this.v >= weightedDelta) return new HSVColor(this.h, this.s, this.v - weightedDelta); weightedDelta -= this.v; const s = Math.min(this.s + weightedDelta, 100); return new HSVColor(this.h, s, 0); } weightedDelta = delta * HSVConstants.HSV_SATURATION_WEIGHT; if (this.s >= weightedDelta) return new HSVColor(this.h, this.s - weightedDelta, this.v); weightedDelta -= this.s; const v = Math.min(this.v + weightedDelta, 100); return new HSVColor(this.h, 0, v); } } exports.HSVColor = HSVColor; //# sourceMappingURL=HSVColor.js.map