Skip to content

Commit 939cb4a

Browse files
committed
refactor: improve variable declarations and add marked property to Point class
1 parent 4a58f74 commit 939cb4a

File tree

3 files changed

+11
-11
lines changed

3 files changed

+11
-11
lines changed

main/util/matrix.ts

Lines changed: 7 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -117,6 +117,7 @@ export class Matrix {
117117

118118
matrix(m: Array<number>): Matrix;
119119
matrix(m: ArbitraryMatrix): Matrix;
120+
// eslint-disable-next-line @typescript-eslint/no-explicit-any
120121
matrix(m: any): Matrix {
121122
this.cache = null;
122123
if (Array.isArray(m)) {
@@ -179,7 +180,7 @@ export class Matrix {
179180
return this.cache;
180181
}
181182

182-
var cache = this.v;
183+
let cache = this.v;
183184
this.queue.forEach(
184185
(item) => (cache = Matrix.combine(cache, item.matrix6())),
185186
);
@@ -191,8 +192,6 @@ export class Matrix {
191192
// Apply list of matrixes to (x,y) point.
192193
// If `isRelative` set, `translate` component of matrix will be skipped
193194
calc(point: Point, isRelative?: boolean): Point {
194-
var m;
195-
196195
// Don't change point on empty transforms queue
197196
if (!this.queue.length) {
198197
return point;
@@ -207,7 +206,7 @@ export class Matrix {
207206
this.cache = this.toArray();
208207
}
209208

210-
m = this.cache;
209+
const m = this.cache;
211210

212211
// Apply matrix to point
213212
return new Point(
@@ -233,7 +232,7 @@ export class Matrix {
233232
applyTransformString(transformString: string): Matrix {
234233
if (!transformString) return this;
235234

236-
var operations = {
235+
const operations = {
237236
matrix: true,
238237
scale: true,
239238
rotate: true,
@@ -246,8 +245,8 @@ export class Matrix {
246245
/\s*(matrix|translate|scale|rotate|skewX|skewY)\s*\(\s*(.+?)\s*\)[\s,]*/;
247246
const PARAMS_SPLIT_RE = /[\s,]+/;
248247

249-
var cmd: string = "";
250-
var params: Array<number>;
248+
let cmd: string = "";
249+
let params: Array<number>;
251250

252251
// Split value into ['', 'translate', '10 50', '', 'scale', '2', '', 'rotate', '-45', '']
253252
for (const item of transformString.split(CMD_SPLIT_RE)) {
@@ -257,7 +256,7 @@ export class Matrix {
257256
}
258257

259258
// remember operation
260-
if (operations.hasOwnProperty(item)) {
259+
if (Object.prototype.hasOwnProperty.call(operations, item)) {
261260
cmd = item;
262261
continue;
263262
}

main/util/point.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ import { Vector } from "./vector.js";
33
export class Point {
44
x: number;
55
y: number;
6+
marked?: boolean; // For NFP generation
67
constructor(x: number, y: number) {
78
this.x = x;
89
this.y = y;
@@ -38,7 +39,7 @@ export class Point {
3839
public equals(obj: Point): boolean {
3940
return this.x === obj.x && this.y === obj.y;
4041
}
41-
public toString(): String {
42+
public toString(): string {
4243
return "<" + this.x.toFixed(1) + ", " + this.y.toFixed(1) + ">";
4344
}
4445
}

main/util/vector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
// floating point comparison tolerance
2-
var TOL = Math.pow(10, -9); // Floating point error is likely to be above 1 epsilon
2+
const TOL = Math.pow(10, -9); // Floating point error is likely to be above 1 epsilon
33

44
function _almostEqual(a: number, b: number, tolerance?: number) {
55
if (!tolerance) {
@@ -34,7 +34,7 @@ export class Vector {
3434
if (_almostEqual(sqLen, 1)) {
3535
return this; // given vector was already a unit vector
3636
}
37-
var len = Math.sqrt(sqLen);
37+
const len = Math.sqrt(sqLen);
3838
return new Vector(this.dx / len, this.dy / len);
3939
}
4040
}

0 commit comments

Comments
 (0)