@fbltd/math 1.0.7 → 1.0.9

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.
@@ -0,0 +1,42 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ const src_1 = require("../src");
4
+ describe('Matrix', () => {
5
+ let matrix;
6
+ test('should be the same', () => {
7
+ matrix = src_1.identityMatrix;
8
+ matrix = src_1.Matrix2d.multiply(matrix, src_1.identityMatrix);
9
+ expect(matrix).toEqual(src_1.identityMatrix);
10
+ expect(matrix).not.toBe(src_1.identityMatrix);
11
+ });
12
+ test('transform', () => {
13
+ matrix = src_1.identityMatrix;
14
+ matrix = src_1.Matrix2d.translate(matrix, 10);
15
+ expect(matrix).toEqual([1, 0, 0, 1, 10, 0]);
16
+ matrix = src_1.Matrix2d.translate(matrix, 10);
17
+ expect(matrix).not.toEqual([1, 0, 0, 1, 10, 0]);
18
+ expect(matrix[4]).toBe(20);
19
+ matrix = src_1.Matrix2d.translate(matrix, 0, 1);
20
+ expect(matrix[4]).toBe(20);
21
+ expect(matrix[5]).toBe(1);
22
+ matrix = src_1.Matrix2d.scale(matrix, 2);
23
+ expect(matrix[0]).toBe(2);
24
+ expect(matrix[1]).toBe(0);
25
+ expect(matrix[2]).toBe(0);
26
+ expect(matrix[3]).toBe(2);
27
+ expect(matrix[4]).toBe(20);
28
+ expect(matrix[5]).toBe(1);
29
+ matrix = src_1.Matrix2d.rotate(matrix, 90);
30
+ expect((0, src_1.approximately)(matrix[0], 0)).toBe(true);
31
+ expect((0, src_1.approximately)(matrix[1], 2)).toBe(true);
32
+ expect((0, src_1.approximately)(matrix[2], -2)).toBe(true);
33
+ expect((0, src_1.approximately)(matrix[3], 0)).toBe(true);
34
+ expect((0, src_1.approximately)(matrix[4], 20)).toBe(true);
35
+ expect((0, src_1.approximately)(matrix[5], 1)).toBe(true);
36
+ matrix = src_1.Matrix2d.rotateIdentity(45);
37
+ expect((0, src_1.approximately)(matrix[0], matrix[1])).toBe(true);
38
+ expect((0, src_1.approximately)(matrix[2], -matrix[3])).toBe(true);
39
+ matrix = src_1.Matrix2d.skewIdentity(-45, 0);
40
+ expect((0, src_1.approximately)(matrix[3], 1)).toBe(true);
41
+ });
42
+ });
@@ -1,7 +1,12 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Matrix2d = exports.identityMatrix = void 0;
4
+ exports.getIdentityMatrix = getIdentityMatrix;
5
+ const angle_1 = require("./angle");
4
6
  exports.identityMatrix = [1, 0, 0, 1, 0, 0];
7
+ function getIdentityMatrix() {
8
+ return [1, 0, 0, 1, 0, 0];
9
+ }
5
10
  class Matrix2d {
6
11
  static multiply(matrix, ...matrices) {
7
12
  for (let m of matrices) {
@@ -22,5 +27,48 @@ class Matrix2d {
22
27
  matrix[1] * point[0] + matrix[3] * point[1] + matrix[5],
23
28
  ];
24
29
  }
30
+ static scaleIdentity(x, y = x) {
31
+ return [x, 0, 0, y, 0, 0];
32
+ }
33
+ static scale(m, x, y = x) {
34
+ return Matrix2d.multiply(m, Matrix2d.scaleIdentity(x, y));
35
+ }
36
+ static rotateIdentity(angle, units = angle_1.AngleUnits.Deg) {
37
+ angle = angle_1.Angle.toRad(angle, units);
38
+ const cos = Math.cos(angle);
39
+ const sin = Math.sin(angle);
40
+ return [cos, sin, -sin, cos, 0, 0];
41
+ }
42
+ static rotate(m, angle, units = angle_1.AngleUnits.Deg) {
43
+ return Matrix2d.multiply(m, Matrix2d.rotateIdentity(angle, units));
44
+ }
45
+ static translateIdentity(x, y = 0) {
46
+ return [1, 0, 0, 1, x, y];
47
+ }
48
+ static translate(m, x, y = 0) {
49
+ return Matrix2d.multiply(m, Matrix2d.translateIdentity(x, y));
50
+ }
51
+ static translateX(m, x) {
52
+ return Matrix2d.multiply(m, this.translateIdentity(x));
53
+ }
54
+ static translateY(m, y) {
55
+ return Matrix2d.multiply(m, this.translateIdentity(0, y));
56
+ }
57
+ static skewIdentity(x, y, units = angle_1.AngleUnits.Deg) {
58
+ x = angle_1.Angle.toRad(x, units);
59
+ y = angle_1.Angle.toRad(y, units);
60
+ x = Math.tan(x);
61
+ y = Math.tan(y);
62
+ return [1, y, x, 1, 0, 0];
63
+ }
64
+ static skewX(m, x, units = angle_1.AngleUnits.Deg) {
65
+ return Matrix2d.multiply(m, Matrix2d.skewIdentity(x, 0, units));
66
+ }
67
+ static skewY(m, y, units = angle_1.AngleUnits.Deg) {
68
+ return Matrix2d.multiply(m, Matrix2d.skewIdentity(0, y, units));
69
+ }
70
+ static skew(m, x, y = 0, units = angle_1.AngleUnits.Deg) {
71
+ return Matrix2d.multiply(m, Matrix2d.skewIdentity(x, y, units));
72
+ }
25
73
  }
26
74
  exports.Matrix2d = Matrix2d;
@@ -1,21 +1,6 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.Operator = void 0;
4
- const angle_1 = require("./angle");
5
4
  class Operator {
6
- static temp1;
7
- static temp2;
8
- static rotateIdentity(angle, unit = angle_1.AngleUnits.Deg) {
9
- angle = angle_1.Angle.toRad(angle, unit);
10
- this.temp1 = Math.cos(angle);
11
- this.temp2 = Math.sin(angle);
12
- return [
13
- this.temp1,
14
- this.temp2,
15
- -this.temp2,
16
- this.temp1,
17
- 0, 0
18
- ];
19
- }
20
5
  }
21
6
  exports.Operator = Operator;
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=matrix.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"matrix.test.d.ts","sourceRoot":"","sources":["../../../__tests__/matrix.test.ts"],"names":[],"mappings":""}
@@ -1 +1 @@
1
- {"version":3,"file":"angle.d.ts","sourceRoot":"","sources":["../../../src/angle.ts"],"names":[],"mappings":"AAEA,oBAAY,UAAU;IAClB,GAAG,IAAI;IACP,GAAG,IAAI;IACP,IAAI,IAAI;CACX;AAGD,qBAAa,KAAK;IAGd,MAAM,CAAC,KAAK,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nits } from "./angle";
1
2
  import { IPoint2 } from "./figures";
2
3
  export type IMatrix2d = [
3
4
  number,
@@ -8,8 +9,21 @@ export type IMatrix2d = [
8
9
  number
9
10
  ];
10
11
  export declare const identityMatrix: IMatrix2d;
12
+ export declare function getIdentityMatrix(): IMatrix2d;
11
13
  export declare class Matrix2d {
12
14
  static multiply(matrix: IMatrix2d, ...matrices: IMatrix2d[]): IMatrix2d;
13
15
  static apply(matrix: IMatrix2d, point: IPoint2): IPoint2;
16
+ static scaleIdentity(x: number, y?: number): IMatrix2d;
17
+ static scale(m: IMatrix2d, x: number, y?: number): IMatrix2d;
18
+ static rotateIdentity(angle: number, units?: AngleUnits): IMatrix2d;
19
+ static rotate(m: IMatrix2d, angle: number, units?: AngleUnits): IMatrix2d;
20
+ static translateIdentity(x: number, y?: number): IMatrix2d;
21
+ static translate(m: IMatrix2d, x: number, y?: number): IMatrix2d;
22
+ static translateX(m: IMatrix2d, x: number): IMatrix2d;
23
+ static translateY(m: IMatrix2d, y: number): IMatrix2d;
24
+ static skewIdentity(x: number, y: number, units?: AngleUnits): IMatrix2d;
25
+ static skewX(m: IMatrix2d, x: number, units?: AngleUnits): IMatrix2d;
26
+ static skewY(m: IMatrix2d, y: number, units?: AngleUnits): IMatrix2d;
27
+ static skew(m: IMatrix2d, x: number, y?: number, units?: AngleUnits): IMatrix2d;
14
28
  }
15
29
  //# sourceMappingURL=matrix.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"matrix.d.ts","sourceRoot":"","sources":["../../../src/matrix.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,OAAO,EAAC,MAAM,WAAW,CAAC;AAElC,MAAM,MAAM,SAAS,GAAG;IACpB,MAAM;IAAE,MAAM;IAAE,MAAM;IACtB,MAAM;IAAE,MAAM;IAAE,MAAM;CACzB,CAAA;AAED,eAAO,MAAM,cAAc,EAAE,SAA8B,CAAA;AAE3D,qBAAa,QAAQ;IACjB,MAAM,CAAC,QAAQ,CAAC,MAAM,EA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AAC,EAAE,MAAM,EAAE,CAAC,GAAE,MAAU,GAAG,SAAS;IAInE,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS;IAIrD,MAAM,CAAC,UAAU,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,GAAG,SAAS;IAIrD,MAAM,CAAC,YAAY,CAAC,CAAC,EAAE,MAAM,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,aAAiB,GAAG,SAAS;IAQ5E,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,aAAiB,GAAG,SAAS;IAIxE,MAAM,CAAC,KAAK,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,KAAK,aAAiB,GAAG,SAAS;IAIxE,MAAM,CAAC,IAAI,CAAC,CAAC,EAAE,SAAS,EAAE,CAAC,EAAE,MAAM,EAAE,CAAC,SAAI,EAAE,KAAK,aAAiB,GAAG,SAAS;CAGjF"}
@@ -1,8 +1,3 @@
1
- import { IMatrix2d } from "./matrix";
2
- import { AngleUnits } from "./angle";
3
1
  export declare class Operator {
4
- private static temp1;
5
- private static temp2;
6
- static rotateIdentity(angle: number, unit?: AngleUnits): IMatrix2d;
7
2
  }
8
3
  //# sourceMappingURL=operator.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"operator.d.ts","sourceRoot":"","sources":["../../../src/operator.ts"],"names":[],"mappings":"AAAA,OAAO,EAAC,SAAS,EAAC,MAAM,UAAU,CAAC;AACnC,OAAO,EAAQ,UAAU,EAAC,MAAM,SAAS,CAAC;AAE1C,qBAAa,QAAQ;IACjB,OAAO,CAAC,MAAM,CAAC,KAAK,CAAQ;IAC5B,OAAO,CAAC,MAAM,CAAC,KAAK,CAAQ;IAK5B,MAAM,CAAC,cAAc,CAAC,KAAK,EAAE,MAAM,EAAE,IAAI,GAAE,UAA2B,GAAG,SAAS;CAYrF"}
1
+ {"version":3,"file":"operator.d.ts","sourceRoot":"","sources":["../../../src/operator.ts"],"names":[],"mappings":"AAGA,qBAAa,QAAQ;CAEpB"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fbltd/math",
3
- "version": "1.0.7",
3
+ "version": "1.0.9",
4
4
  "description": "",
5
5
  "main": "dist/bin/index.js",
6
6
  "types": "dist/types/index.d.ts",
@@ -17,8 +17,9 @@
17
17
  "README.ms"
18
18
  ],
19
19
  "scripts": {
20
- "build": "rm -r dist || echo '' && node_modules/.bin/tsc",
21
- "deploy": "npm run build && npm version patch && git push && npm publish",
20
+ "clean": "rm -r dist || echo ''",
21
+ "build": "node_modules/.bin/tsc",
22
+ "deploy": "npm run clean && npm run build && npm version patch && git push && npm publish && npm run clean",
22
23
  "make": "node_modules/.bin/fbltd_make",
23
24
  "test": "node_modules/.bin/fbltd_test"
24
25
  },