@itwin/core-common
Version:
iTwin.js components common to frontend and backend
62 lines • 2.27 kB
JavaScript
/*---------------------------------------------------------------------------------------------
* 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
*/
import { ColorDef } from "./ColorDef";
/**
* @public
* @extensions
*/
export 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 || (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
*/
export 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.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);
}
}
//# sourceMappingURL=HSVColor.js.map