Use blocked scoped variables

In addition to using const and let, this also upgrades our linter config and removes lint (mostly whitespace).
This commit is contained in:
Tim Schaub
2018-01-11 23:32:36 -07:00
parent 0bf2b04dee
commit ad62739a6e
684 changed files with 18120 additions and 18184 deletions

View File

@@ -25,17 +25,17 @@ export function clamp(value, min, max) {
* @param {number} x X.
* @return {number} Hyperbolic cosine of x.
*/
export var cosh = (function() {
export const cosh = (function() {
// Wrapped in a iife, to save the overhead of checking for the native
// implementation on every invocation.
var cosh;
let cosh;
if ('cosh' in Math) {
// The environment supports the native Math.cosh function, use it…
cosh = Math.cosh;
} else {
// … else, use the reference implementation of MDN:
cosh = function(x) {
var y = Math.exp(x);
const y = Math.exp(x);
return (y + 1 / y) / 2;
};
}
@@ -65,10 +65,10 @@ export function roundUpToPowerOfTwo(x) {
* @return {number} Squared distance.
*/
export function squaredSegmentDistance(x, y, x1, y1, x2, y2) {
var dx = x2 - x1;
var dy = y2 - y1;
const dx = x2 - x1;
const dy = y2 - y1;
if (dx !== 0 || dy !== 0) {
var t = ((x - x1) * dx + (y - y1) * dy) / (dx * dx + dy * dy);
const t = ((x - x1) * dx + (y - y1) * dy) / (dx * dx + dy * dy);
if (t > 1) {
x1 = x2;
y1 = y2;
@@ -90,8 +90,8 @@ export function squaredSegmentDistance(x, y, x1, y1, x2, y2) {
* @return {number} Squared distance.
*/
export function squaredDistance(x1, y1, x2, y2) {
var dx = x2 - x1;
var dy = y2 - y1;
const dx = x2 - x1;
const dy = y2 - y1;
return dx * dx + dy * dy;
}
@@ -104,14 +104,14 @@ export function squaredDistance(x1, y1, x2, y2) {
* @return {Array.<number>} The resulting vector.
*/
export function solveLinearSystem(mat) {
var n = mat.length;
const n = mat.length;
for (var i = 0; i < n; i++) {
for (let i = 0; i < n; i++) {
// Find max in the i-th column (ignoring i - 1 first rows)
var maxRow = i;
var maxEl = Math.abs(mat[i][i]);
for (var r = i + 1; r < n; r++) {
var absValue = Math.abs(mat[r][i]);
let maxRow = i;
let maxEl = Math.abs(mat[i][i]);
for (let r = i + 1; r < n; r++) {
const absValue = Math.abs(mat[r][i]);
if (absValue > maxEl) {
maxEl = absValue;
maxRow = r;
@@ -123,14 +123,14 @@ export function solveLinearSystem(mat) {
}
// Swap max row with i-th (current) row
var tmp = mat[maxRow];
const tmp = mat[maxRow];
mat[maxRow] = mat[i];
mat[i] = tmp;
// Subtract the i-th row to make all the remaining rows 0 in the i-th column
for (var j = i + 1; j < n; j++) {
var coef = -mat[j][i] / mat[i][i];
for (var k = i; k < n + 1; k++) {
for (let j = i + 1; j < n; j++) {
const coef = -mat[j][i] / mat[i][i];
for (let k = i; k < n + 1; k++) {
if (i == k) {
mat[j][k] = 0;
} else {
@@ -141,10 +141,10 @@ export function solveLinearSystem(mat) {
}
// Solve Ax=b for upper triangular matrix A (mat)
var x = new Array(n);
for (var l = n - 1; l >= 0; l--) {
const x = new Array(n);
for (let l = n - 1; l >= 0; l--) {
x[l] = mat[l][n] / mat[l][l];
for (var m = l - 1; m >= 0; m--) {
for (let m = l - 1; m >= 0; m--) {
mat[m][n] -= mat[m][l] * x[l];
}
}
@@ -181,7 +181,7 @@ export function toRadians(angleInDegrees) {
* @return {number} Modulo.
*/
export function modulo(a, b) {
var r = a % b;
const r = a % b;
return r * b < 0 ? r + b : r;
}