Skip to content

Commit a012893

Browse files
committed
Add (simple) eslint config and fix some issues found using it.
1 parent a3769c2 commit a012893

File tree

7 files changed

+63
-20
lines changed

7 files changed

+63
-20
lines changed

.gitignore

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
# Logs
2+
logs
3+
*.log
4+
npm-debug.log*
5+
yarn-debug.log*
6+
yarn-error.log*
7+
pnpm-debug.log*
8+
lerna-debug.log*
9+
10+
node_modules
11+
dist
12+
dist-ssr
13+
*.local
14+
15+
# Editor directories and files
16+
.vscode/*
17+
!.vscode/extensions.json
18+
.idea
19+
.DS_Store
20+
*.suo
21+
*.ntvs*
22+
*.njsproj
23+
*.sln
24+
*.sw?
25+
/competitors
26+
/papers

eslint.config.mjs

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
import globals from "globals";
2+
import pluginJs from "@eslint/js";
3+
4+
/** @type {import('eslint').Linter.Config[]} */
5+
export default [
6+
{
7+
files: ["**/*.js", "**/*.jsx", "**/*.mjs", "**/*.cjs"],
8+
...pluginJs.configs.recommended,
9+
languageOptions: { globals: globals.browser }
10+
}
11+
];

main.js

Lines changed: 13 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -403,12 +403,14 @@ function initialize3DTableGraphic(moodyReport) {
403403
canvas.height = height
404404
sizeChanged = true
405405
}
406-
const fieldOfView = (45 * Math.PI) / 180 // radians
407-
const aspect = canvas.width / canvas.height
408-
const zNear = 0.1
409-
const zFar = 1000.0
410406

411-
projectionMatrix.perspective(fieldOfView, aspect, zNear, zFar)
407+
if (sizeChanged) {
408+
const fieldOfView = (45 * Math.PI) / 180 // radians
409+
const aspect = canvas.width / canvas.height
410+
const zNear = 0.1
411+
const zFar = 1000.0
412+
projectionMatrix.perspective(fieldOfView, aspect, zNear, zFar)
413+
}
412414
}
413415
})
414416

@@ -552,7 +554,7 @@ function initialize3DTableGraphic(moodyReport) {
552554
const buffers = createAndBindTableVAO(moodyReport, gl, programInfo)
553555

554556
function render(now) {
555-
now = updateFps(now)
557+
updateFps(now)
556558

557559
drawTableSurface(moodyReport, gl, programInfo, buffers, texture)
558560
requestAnimationFrame(render)
@@ -572,7 +574,6 @@ function initialize3DTableGraphic(moodyReport) {
572574
frameCursor %= maxFrames
573575
const averageFPS = totalFPS / numFrames
574576
avgElem.textContent = averageFPS.toFixed(1)
575-
return now
576577
}
577578

578579
let then = 0
@@ -839,7 +840,7 @@ function getNonColorBuffers(gl, moodyReport, zMultiplier) {
839840
gl.bufferData(gl.ARRAY_BUFFER, positions, gl.STATIC_DRAW)
840841

841842
// Calculate and create normal buffer.
842-
const lineNormals = moodyReport.vertices(zMultiplier).map(v => [0.0, 0.0, 0.0]).flat(1)
843+
const lineNormals = moodyReport.vertices(zMultiplier).map(() => [0.0, 0.0, 0.0]).flat(1)
843844
// Each triangle has 3 vertices with the same surface normal.
844845
const triangleNormals = triangulation.map(triangle => {
845846
const length = Math.sqrt(triangle.surfaceNormal().x * triangle.surfaceNormal().x +
@@ -856,7 +857,7 @@ function getNonColorBuffers(gl, moodyReport, zMultiplier) {
856857
gl.bufferData(gl.ARRAY_BUFFER, normals, gl.STATIC_DRAW)
857858

858859
// Calculate and create texture buffer.
859-
const lineTextureCoords = moodyReport.vertices(zMultiplier).map(v => [0.0, 1.0]).flat(1)
860+
const lineTextureCoords = moodyReport.vertices(zMultiplier).map(() => [0.0, 1.0]).flat(1)
860861

861862
if (!(zMultiplier in boundingBoxCache)) {
862863
boundingBoxCache[zMultiplier] = getBoundingBox(moodyReport)
@@ -882,8 +883,8 @@ function getNonColorBuffers(gl, moodyReport, zMultiplier) {
882883
gl.bufferData(gl.ARRAY_BUFFER, textureCoordinates, gl.STATIC_DRAW)
883884

884885
const types = new Float32Array(
885-
moodyReport.vertices(zMultiplier).map(v => [0.0]).flat(1) // "Union jack" colored lines have type "0.0"
886-
.concat(triangulation.map(_ => [1.0, 1.0, 1.0]).flat(1)) // Table vertices have type "1.0"
886+
moodyReport.vertices(zMultiplier).map(() => [0.0]).flat(1) // "Union jack" colored lines have type "0.0"
887+
.concat(triangulation.map(() => [1.0, 1.0, 1.0]).flat(1)) // Table vertices have type "1.0"
887888
.concat(0.0, 0.0, 0.0, 0.0, 0.0, 0.0)) // Axis vertices have type "0.0"
888889

889890
const typeBuffer = gl.createBuffer()
@@ -900,7 +901,7 @@ function getColorBuffer(gl, moodyReport, triangleVertices) {
900901
const minZ = Math.min(...triangleZValues)
901902
const maxZ = Math.max(...triangleZValues)
902903
// In case all values are the same minZ = maxZ (i.e. it is a totally flat plate with zero deviation) so we must avoid division by zero - just set all values to 0.0.
903-
const normalizedTriangleZValues = minZ === maxZ ? triangleZValues.map(value => 0.0) : triangleZValues.map(value => (value - minZ) / (maxZ - minZ))
904+
const normalizedTriangleZValues = minZ === maxZ ? triangleZValues.map(() => 0.0) : triangleZValues.map(value => (value - minZ) / (maxZ - minZ))
904905
const colorMappedZValues = normalizedTriangleZValues.map(value => interpolate(turboColormapData, value))
905906
console.log(colorMappedZValues)
906907
const colors = new Array(moodyReport.topStartingDiagonalTable.numStations).fill([0.9568627450980393, 0.2627450980392157, 0.21176470588235294, 1.0]).flat(1)

math.js

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -137,15 +137,15 @@ class Vector3 extends Float32Array {
137137
return Vector3.norm(this, this)
138138
}
139139

140-
static scale(out, a) {
140+
static scale(out, a, scale) {
141141
out[0] = a[0] * scale
142142
out[1] = a[1] * scale
143143
out[2] = a[2] * scale
144144
return out
145145
}
146146

147-
scale(a) {
148-
return Vector3.scale(this, a)
147+
scale(a, scale) {
148+
return Vector3.scale(this, a, scale)
149149
}
150150

151151
static magnitude(a) {

moody.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,3 @@
1-
import { Vector3 } from "./math.js"
2-
31
const sineOfOneArcsecond = 0.00000484813
42

53
function roundTo(n, numDecimalPlaces = 2) {

package.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@
44
"description": "",
55
"main": "moody.js",
66
"scripts": {
7-
"serve": "npx http-server -c-1 -p 5000 -o"
7+
"serve": "npx http-server -c-1 -p 5000 -o",
8+
"lint": "npx eslint ."
89
},
910
"keywords": [],
1011
"author": "Michael Ennen (brcolow)",
11-
"license": "MIT"
12-
}
12+
"license": "MIT",
13+
"devDependencies": {
14+
"@eslint/js": "^9.17.0",
15+
"eslint": "^9.17.0",
16+
"globals": "^15.14.0"
17+
}
18+
}

webgl-debug.js

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
/* eslint-disable */
12
/*
23
** Copyright (c) 2012 The Khronos Group Inc.
34
**

0 commit comments

Comments
 (0)