Skip to content

Commit b7caf5d

Browse files
committed
eslint fixes
1 parent 8444982 commit b7caf5d

1 file changed

Lines changed: 46 additions & 53 deletions

File tree

src/index.js

Lines changed: 46 additions & 53 deletions
Original file line numberDiff line numberDiff line change
@@ -40,12 +40,12 @@ class GCodeToolpath {
4040
this.setModalState({ 'motion': 'G0' });
4141
}
4242

43-
let v1 = {
43+
const v1 = {
4444
x: this.position.x,
4545
y: this.position.y,
4646
z: this.position.z
4747
};
48-
let v2 = {
48+
const v2 = {
4949
x: this.translateX(params.X),
5050
y: this.translateY(params.Y),
5151
z: this.translateZ(params.Z)
@@ -76,12 +76,12 @@ class GCodeToolpath {
7676
this.setModalState({ 'motion': 'G1' });
7777
}
7878

79-
let v1 = {
79+
const v1 = {
8080
x: this.position.x,
8181
y: this.position.y,
8282
z: this.position.z
8383
};
84-
let v2 = {
84+
const v2 = {
8585
x: this.translateX(params.X),
8686
y: this.translateY(params.Y),
8787
z: this.translateZ(params.Z)
@@ -116,17 +116,17 @@ class GCodeToolpath {
116116
this.setModalState({ 'motion': 'G2' });
117117
}
118118

119-
let v1 = {
119+
const v1 = {
120120
x: this.position.x,
121121
y: this.position.y,
122122
z: this.position.z
123123
};
124-
let v2 = {
124+
const v2 = {
125125
x: this.translateX(params.X),
126126
y: this.translateY(params.Y),
127127
z: this.translateZ(params.Z)
128128
};
129-
let v0 = { // fixed point
129+
const v0 = { // fixed point
130130
x: this.translateI(params.I),
131131
y: this.translateJ(params.J),
132132
z: this.translateK(params.K)
@@ -135,27 +135,27 @@ class GCodeToolpath {
135135
const targetPosition = { x: v2.x, y: v2.y, z: v2.z };
136136

137137
if (this.isXYPlane()) { // XY-plane
138-
[ v1.x, v1.y, v1.z ] = [ v1.x, v1.y, v1.z ];
139-
[ v2.x, v2.y, v2.z ] = [ v2.x, v2.y, v2.z ];
140-
[ v0.x, v0.y, v0.z ] = [ v0.x, v0.y, v0.z ];
138+
[v1.x, v1.y, v1.z] = [v1.x, v1.y, v1.z];
139+
[v2.x, v2.y, v2.z] = [v2.x, v2.y, v2.z];
140+
[v0.x, v0.y, v0.z] = [v0.x, v0.y, v0.z];
141141
} else if (this.isZXPlane()) { // ZX-plane
142-
[ v1.x, v1.y, v1.z ] = [ v1.z, v1.x, v1.y ];
143-
[ v2.x, v2.y, v2.z ] = [ v2.z, v2.x, v2.y ];
144-
[ v0.x, v0.y, v0.z ] = [ v0.z, v0.x, v0.y ];
142+
[v1.x, v1.y, v1.z] = [v1.z, v1.x, v1.y];
143+
[v2.x, v2.y, v2.z] = [v2.z, v2.x, v2.y];
144+
[v0.x, v0.y, v0.z] = [v0.z, v0.x, v0.y];
145145
} else if (this.isYZPlane()) { // YZ-plane
146-
[ v1.x, v1.y, v1.z ] = [ v1.y, v1.z, v1.x ];
147-
[ v2.x, v2.y, v2.z ] = [ v2.y, v2.z, v2.x ];
148-
[ v0.x, v0.y, v0.z ] = [ v0.y, v0.z, v0.x ];
146+
[v1.x, v1.y, v1.z] = [v1.y, v1.z, v1.x];
147+
[v2.x, v2.y, v2.z] = [v2.y, v2.z, v2.x];
148+
[v0.x, v0.y, v0.z] = [v0.y, v0.z, v0.x];
149149
} else {
150150
console.error('The plane mode is invalid', this.modalState.plane);
151151
return;
152152
}
153153

154154
if (params.R) {
155-
let radius = this.translateR(Number(params.R) || 0);
156-
let x = v2.x - v1.x;
157-
let y = v2.y - v1.y;
158-
let distance = Math.sqrt(x * x + y * y);
155+
const radius = this.translateR(Number(params.R) || 0);
156+
const x = v2.x - v1.x;
157+
const y = v2.y - v1.y;
158+
const distance = Math.sqrt(x * x + y * y);
159159
let height = Math.sqrt(4 * radius * radius - x * x - y * y) / 2;
160160

161161
if (isClockwise) {
@@ -165,8 +165,8 @@ class GCodeToolpath {
165165
height = -height;
166166
}
167167

168-
let offsetX = x / 2 - y / distance * height;
169-
let offsetY = y / 2 + x / distance * height;
168+
const offsetX = x / 2 - y / distance * height;
169+
const offsetY = y / 2 + x / distance * height;
170170

171171
v0.x = v1.x + offsetX;
172172
v0.y = v1.y + offsetY;
@@ -182,17 +182,17 @@ class GCodeToolpath {
182182
this.setModalState({ 'motion': 'G3' });
183183
}
184184

185-
let v1 = {
185+
const v1 = {
186186
x: this.position.x,
187187
y: this.position.y,
188188
z: this.position.z
189189
};
190-
let v2 = {
190+
const v2 = {
191191
x: this.translateX(params.X),
192192
y: this.translateY(params.Y),
193193
z: this.translateZ(params.Z)
194194
};
195-
let v0 = { // fixed point
195+
const v0 = { // fixed point
196196
x: this.translateI(params.I),
197197
y: this.translateJ(params.J),
198198
z: this.translateK(params.K)
@@ -201,27 +201,27 @@ class GCodeToolpath {
201201
const targetPosition = { x: v2.x, y: v2.y, z: v2.z };
202202

203203
if (this.isXYPlane()) { // XY-plane
204-
[ v1.x, v1.y, v1.z ] = [ v1.x, v1.y, v1.z ];
205-
[ v2.x, v2.y, v2.z ] = [ v2.x, v2.y, v2.z ];
206-
[ v0.x, v0.y, v0.z ] = [ v0.x, v0.y, v0.z ];
204+
[v1.x, v1.y, v1.z] = [v1.x, v1.y, v1.z];
205+
[v2.x, v2.y, v2.z] = [v2.x, v2.y, v2.z];
206+
[v0.x, v0.y, v0.z] = [v0.x, v0.y, v0.z];
207207
} else if (this.isZXPlane()) { // ZX-plane
208-
[ v1.x, v1.y, v1.z ] = [ v1.z, v1.x, v1.y ];
209-
[ v2.x, v2.y, v2.z ] = [ v2.z, v2.x, v2.y ];
210-
[ v0.x, v0.y, v0.z ] = [ v0.z, v0.x, v0.y ];
208+
[v1.x, v1.y, v1.z] = [v1.z, v1.x, v1.y];
209+
[v2.x, v2.y, v2.z] = [v2.z, v2.x, v2.y];
210+
[v0.x, v0.y, v0.z] = [v0.z, v0.x, v0.y];
211211
} else if (this.isYZPlane()) { // YZ-plane
212-
[ v1.x, v1.y, v1.z ] = [ v1.y, v1.z, v1.x ];
213-
[ v2.x, v2.y, v2.z ] = [ v2.y, v2.z, v2.x ];
214-
[ v0.x, v0.y, v0.z ] = [ v0.y, v0.z, v0.x ];
212+
[v1.x, v1.y, v1.z] = [v1.y, v1.z, v1.x];
213+
[v2.x, v2.y, v2.z] = [v2.y, v2.z, v2.x];
214+
[v0.x, v0.y, v0.z] = [v0.y, v0.z, v0.x];
215215
} else {
216216
console.error('The plane mode is invalid', this.modalState.plane);
217217
return;
218218
}
219219

220220
if (params.R) {
221-
let radius = this.translateR(Number(params.R) || 0);
222-
let x = v2.x - v1.x;
223-
let y = v2.y - v1.y;
224-
let distance = Math.sqrt(x * x + y * y);
221+
const radius = this.translateR(Number(params.R) || 0);
222+
const x = v2.x - v1.x;
223+
const y = v2.y - v1.y;
224+
const distance = Math.sqrt(x * x + y * y);
225225
let height = Math.sqrt(4 * radius * radius - x * x - y * y) / 2;
226226

227227
if (isClockwise) {
@@ -231,8 +231,8 @@ class GCodeToolpath {
231231
height = -height;
232232
}
233233

234-
let offsetX = x / 2 - y / distance * height;
235-
let offsetY = y / 2 + x / distance * height;
234+
const offsetX = x / 2 - y / distance * height;
235+
const offsetY = y / 2 + x / distance * height;
236236

237237
v0.x = v1.x + offsetX;
238238
v0.y = v1.y + offsetY;
@@ -250,15 +250,6 @@ class GCodeToolpath {
250250
// Example
251251
// G4 P200
252252
'G4': (params) => {
253-
let sleep = 0;
254-
255-
if (params.S !== undefined) {
256-
sleep = Number(params.S) * 1000; // seconds
257-
}
258-
259-
if (params.P !== undefined) {
260-
sleep = Number(params.P); // milliseconds
261-
}
262253
},
263254
// G10: Coordinate System Data Tool and Work Offset Tables
264255
'G10': (params) => {
@@ -386,17 +377,19 @@ class GCodeToolpath {
386377
// This would set the machine's X coordinate to 10. No physical motion will occur.
387378
// A G92 without coordinates will reset all axes to zero.
388379
'G92': (params) => {
389-
let v2 = {
380+
const v2 = {
390381
x: this.translateX(params.X, false),
391382
y: this.translateY(params.Y, false),
392383
z: this.translateZ(params.Z, false)
393384
};
394385

395386
// A G92 without coordinates will reset all axes to zero.
396387
if ((params.X === undefined) && (params.Y === undefined) && (params.Z === undefined)) {
397-
v2.x = v2.y = v2.z = 0;
388+
v2.x = 0;
389+
v2.y = 0;
390+
v2.z = 0;
398391
}
399-
392+
400393
// Update position
401394
this.setPosition(v2.x, v2.y, v2.z);
402395
},
@@ -429,7 +422,7 @@ class GCodeToolpath {
429422
const { modalState, addLine = noop, addArcCurve = noop } = { ...options };
430423
const nextModalState = {};
431424
Object.keys({ ...modalState }).forEach(key => {
432-
if (!this.modalState.hasOwnProperty(key)) {
425+
if (!Object.prototype.hasOwnProperty.call(this.modalState, key)) {
433426
return;
434427
}
435428
nextModalState[key] = modalState[key];

0 commit comments

Comments
 (0)