From ecb5e45cd30bf108d759f2b4ffe79da40531d2e9 Mon Sep 17 00:00:00 2001 From: Val Erastov Date: Mon, 15 Aug 2022 21:44:25 -0700 Subject: [PATCH] prefer-const rule for JS / manual fixes --- modules/scene/controls/CADTrackballControls.js | 16 ++++++++-------- modules/scene/objects/auxiliary.js | 3 +-- web/app/cad/cad-utils.js | 3 ++- web/app/cad/legacy/mesh/workbench.js | 6 ++++-- web/app/sketcher/components/TerminalView.jsx | 3 ++- web/app/sketcher/shapes/dim.js | 9 ++++----- 6 files changed, 21 insertions(+), 19 deletions(-) diff --git a/modules/scene/controls/CADTrackballControls.js b/modules/scene/controls/CADTrackballControls.js index a7cbc23d..56003b9f 100644 --- a/modules/scene/controls/CADTrackballControls.js +++ b/modules/scene/controls/CADTrackballControls.js @@ -53,21 +53,20 @@ export function CADTrackballControls( object, domElement ) { let _state = STATE.NONE, _prevState = STATE.NONE, + _lastAngle = 0, + _touchZoomDistanceStart = 0, + _touchZoomDistanceEnd = 0; - _eye = new THREE.Vector3(), + const _eye = new THREE.Vector3(), _movePrev = new THREE.Vector2(), _moveCurr = new THREE.Vector2(), _lastAxis = new THREE.Vector3(), - _lastAngle = 0, _zoomStart = new THREE.Vector2(), _zoomEnd = new THREE.Vector2(), - _touchZoomDistanceStart = 0, - _touchZoomDistanceEnd = 0, - _panStart = new THREE.Vector2(), _panEnd = new THREE.Vector2(); @@ -154,13 +153,14 @@ export function CADTrackballControls( object, domElement ) { this.rotateCamera = ( function() { - let axis = new THREE.Vector3(), + const axis = new THREE.Vector3(), quaternion = new THREE.Quaternion(), eyeDirection = new THREE.Vector3(), objectUpDirection = new THREE.Vector3(), objectSidewaysDirection = new THREE.Vector3(), - moveDirection = new THREE.Vector3(), - angle; + moveDirection = new THREE.Vector3(); + + let angle; return function rotateCamera() { diff --git a/modules/scene/objects/auxiliary.js b/modules/scene/objects/auxiliary.js index 0a8bcd32..3ecbb7d3 100644 --- a/modules/scene/objects/auxiliary.js +++ b/modules/scene/objects/auxiliary.js @@ -63,9 +63,8 @@ export class MeshArrow extends Object3D { this.quaternion.set(1, 0, 0, 0); } else { const axis = new Vector3(); - let radians; axis.set(dir.z, 0, -dir.x).normalize(); - radians = Math.acos(dir.y); + const radians = Math.acos(dir.y); this.quaternion.setFromAxisAngle(axis, radians); } diff --git a/web/app/cad/cad-utils.js b/web/app/cad/cad-utils.js index f16b1578..f8693a6d 100644 --- a/web/app/cad/cad-utils.js +++ b/web/app/cad/cad-utils.js @@ -355,7 +355,8 @@ export function Sketch() { } export function iteratePath(path, shift, callback) { - let p, q, n = path.length; + let p, q; + const n = path.length; for (p = n - 1,q = 0;q < n; p = q++) { const ai = (p + shift) % n; const bi = (q + shift) % n; diff --git a/web/app/cad/legacy/mesh/workbench.js b/web/app/cad/legacy/mesh/workbench.js index 3ddcbcf3..b78d33fc 100644 --- a/web/app/cad/legacy/mesh/workbench.js +++ b/web/app/cad/legacy/mesh/workbench.js @@ -80,7 +80,8 @@ export function polygonsToSegments(polygons) { for (let pi = 0; pi < polygons.length; pi++) { const segments = []; const poly = polygons[pi]; - let p, q, n = poly.vertices.length; + let p, q; + const n = poly.vertices.length; for(p = n - 1, q = 0; q < n; p = q ++) { const a = poly.vertices[p]; const b = poly.vertices[q]; @@ -105,7 +106,8 @@ export function reconstructSketchBounds(csg, face, strict) { } continue; } - let p, q, n = poly.vertices.length; + let p, q; + const n = poly.vertices.length; for(p = n - 1, q = 0; q < n; p = q ++) { const a = poly.vertices[p]; const b = poly.vertices[q]; diff --git a/web/app/sketcher/components/TerminalView.jsx b/web/app/sketcher/components/TerminalView.jsx index 36354909..f0174649 100644 --- a/web/app/sketcher/components/TerminalView.jsx +++ b/web/app/sketcher/components/TerminalView.jsx @@ -221,7 +221,8 @@ export function SketcherTerminal() { } function sharedStartOfSortedArray(array) { - let a1 = array[0], a2 = array[array.length - 1], L = a1.length, i = 0; + const a1 = array[0], a2 = array[array.length - 1], L = a1.length; + let i = 0; while (i < L && a1.charAt(i) === a2.charAt(i)) i++; return a1.substring(0, i); } \ No newline at end of file diff --git a/web/app/sketcher/shapes/dim.js b/web/app/sketcher/shapes/dim.js index 99f7850e..eb6c2152 100644 --- a/web/app/sketcher/shapes/dim.js +++ b/web/app/sketcher/shapes/dim.js @@ -112,11 +112,10 @@ export class LinearDimension extends Dimension { this.unscale = scale; - let a, b, startA, startB; - a = this.getB(); - b = this.getA(); - startA = this.b; - startB = this.a; + const a = this.getB(); + const b = this.getA(); + const startA = this.b; + const startB = this.a; const d = distanceAB(a, b);