@fbltd/math 1.0.22 → 1.0.23

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -6,11 +6,26 @@ export class Color {
6
6
  this.red = red;
7
7
  this.green = green;
8
8
  this.blue = blue;
9
- this.red = Math.max(Math.min(red, 255), 0);
10
- this.green = Math.max(Math.min(green, 255), 0);
11
- this.blue = Math.max(Math.min(blue, 255), 0);
9
+ this.red = Math.max(Math.min(Math.round(red), 255), 0);
10
+ this.green = Math.max(Math.min(Math.round(green), 255), 0);
11
+ this.blue = Math.max(Math.min(Math.round(blue), 255), 0);
12
12
  }
13
13
  toCSS() {
14
- return `rgb(${this.red}, ${this.green}, ${this.blue})`;
14
+ return Color.toCSS(this);
15
+ }
16
+ isEqual(c) {
17
+ return Color.areEquals(this, c);
18
+ }
19
+ static ofNumber(value) {
20
+ return new Color((value & 0xFF0000) >> 16, (value & 0xFF00) >> 8, value & 0xFF);
21
+ }
22
+ static toNumber(color) {
23
+ return (((color.red << 16) | color.green) << 16) | color.blue;
24
+ }
25
+ static areEquals(c1, c2) {
26
+ return Color.toNumber(c1) === Color.toNumber(c2);
27
+ }
28
+ static toCSS(color) {
29
+ return `rgb(${color.red},${color.green},${color.blue})`;
15
30
  }
16
31
  }
@@ -29,12 +29,12 @@ export class ConicGradient {
29
29
  getAngleByColor(color) {
30
30
  let prev;
31
31
  let next = this.colors[0];
32
- if (color.red === next.color.red && color.green === next.color.green && color.blue === next.color.blue)
32
+ if (color.isEqual(next.color))
33
33
  return next.angle;
34
34
  for (let i = 1; i < this.colors.length; i++) {
35
35
  next = this.colors[i];
36
36
  prev = this.colors[i - 1];
37
- if (color.red === next.color.red && color.green === next.color.green && color.blue === next.color.blue)
37
+ if (color.isEqual(next.color))
38
38
  return next.angle;
39
39
  let redDif = next.color.red - prev.color.red;
40
40
  let greenDif = next.color.green - prev.color.green;
@@ -4,5 +4,10 @@ export declare class Color {
4
4
  blue: number;
5
5
  constructor(red: number, green: number, blue: number);
6
6
  toCSS(): string;
7
+ isEqual(c: Color): boolean;
8
+ static ofNumber(value: number): Color;
9
+ static toNumber(color: Color): number;
10
+ static areEquals(c1: Color, c2: Color): boolean;
11
+ static toCSS(color: Color): string;
7
12
  }
8
13
  //# sourceMappingURL=color.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../../src/colors/color.ts"],"names":[],"mappings":"AAAA,qBAAa,KAAK;IACK,GAAG,EAAE,MAAM;IAAS,KAAK,EAAE,MAAM;IAAS,IAAI,EAAE,MAAM;gBAAtD,GAAG,EAAE,MAAM,EAAS,KAAK,EAAE,MAAM,EAAS,IAAI,EAAE,MAAM;IAMzE,KAAK;CAGR"}
1
+ {"version":3,"file":"color.d.ts","sourceRoot":"","sources":["../../../../src/colors/color.ts"],"names":[],"mappings":"AAAA,qBAAa,KAAK;IACK,GAAG,EAAE,MAAM;IAAS,KAAK,EAAE,MAAM;IAAS,IAAI,EAAE,MAAM;gBAAtD,GAAG,EAAE,MAAM,EAAS,KAAK,EAAE,MAAM,EAAS,IAAI,EAAE,MAAM;IAMzE,KAAK;IAIL,OAAO,CAAC,CAAC,EAAE,KAAK;IAIhB,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,MAAM;IAQ7B,MAAM,CAAC,QAAQ,CAAC,KAAK,EAAE,KAAK;IAI5B,MAAM,CAAC,SAAS,CAAC,EAAE,EAAE,KAAK,EAAE,EAAE,EAAE,KAAK;IAIrC,MAAM,CAAC,KAAK,CAAC,KAAK,EAAE,KAAK;CAI5B"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fbltd/math",
3
- "version": "1.0.22",
3
+ "version": "1.0.23",
4
4
  "description": "Math and geometry utilities",
5
5
  "sideEffects": false,
6
6
  "main": "dist/bin/index.js",