Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | 4x 4x 296x 296x 296x | // tslint:disable:member-ordering
import { roundToPrecisionSmall } from "./mathUtils";
// This uses Hue values in "degree" format. So expect a range of [0,360]. Some other implementations instead uses radians or a normalized Hue with range [0,1]. Be aware of this when checking values or using other libraries.
export class ColorHSV {
public static fromObject(data: { h: number; s: number; v: number }): ColorHSV | null {
if (data && !isNaN(data.h) && !isNaN(data.s) && !isNaN(data.v)) {
return new ColorHSV(data.h, data.s, data.v);
}
return null;
}
constructor(hue: number, sat: number, val: number) {
this.h = hue;
this.s = sat;
this.v = val;
}
public readonly h: number;
public readonly s: number;
public readonly v: number;
public equalValue(rhs: ColorHSV): boolean {
return this.h === rhs.h && this.s === rhs.s && this.v === rhs.v;
}
public roundToPrecision(precision: number): ColorHSV {
return new ColorHSV(
roundToPrecisionSmall(this.h, precision),
roundToPrecisionSmall(this.s, precision),
roundToPrecisionSmall(this.v, precision)
);
}
public toObject(): { h: number; s: number; v: number } {
return { h: this.h, s: this.s, v: this.v };
}
}
|