diff --git a/package.json b/package.json index 40064eb..fb8a15e 100644 --- a/package.json +++ b/package.json @@ -47,19 +47,19 @@ }, "homepage": "https://github.com/mljs/conrec#readme", "devDependencies": { - "@babel/plugin-transform-modules-commonjs": "^7.21.2", - "@babel/preset-typescript": "^7.21.4", - "@types/jest": "^29.5.1", - "eslint": "^8.38.0", - "eslint-config-cheminfo-typescript": "^11.3.1", + "@babel/plugin-transform-modules-commonjs": "^7.24.1", + "@babel/preset-typescript": "^7.24.1", + "@types/jest": "^29.5.12", + "eslint": "^8.57.0", + "eslint-config-cheminfo-typescript": "^12.4.0", "esm": "^3.2.25", - "jcampconverter": "^9.1.1", - "jest": "^29.5.0", - "prettier": "^2.8.7", - "rimraf": "^5.0.0", - "typescript": "^5.0.4" + "jcampconverter": "^9.6.4", + "jest": "^29.7.0", + "prettier": "^3.2.5", + "rimraf": "^5.0.5", + "typescript": "^5.4.5" }, "dependencies": { - "cheminfo-types": "^1.7.1" + "cheminfo-types": "^1.7.3" } } diff --git a/src/ContourBuilder.ts b/src/ContourBuilder.ts index 9e68cab..f02c0ae 100644 --- a/src/ContourBuilder.ts +++ b/src/ContourBuilder.ts @@ -186,8 +186,8 @@ export class ContourBuilder { } if (ma === null && mb === null) { // both unmatched, add as new sequence - let aa: SequenceNode = { p: a, prev: null, next: null }; - let bb: SequenceNode = { p: b, prev: null, next: null }; + const aa: SequenceNode = { p: a, prev: null, next: null }; + const bb: SequenceNode = { p: b, prev: null, next: null }; aa.next = bb; bb.prev = aa; // create sequence element and push onto head of main list. The order @@ -275,8 +275,8 @@ export class ContourBuilder { } function pointsEqual(a: Point, b: Point) { - let x = a.x - b.x; - let y = a.y - b.y; + const x = a.x - b.x; + const y = a.y - b.y; return x * x + y * y < Number.EPSILON; } @@ -302,16 +302,16 @@ export interface Point { x: number; y: number; } -export type SequenceNode = { +export interface SequenceNode { p: Point; next: SequenceNode | null; prev: SequenceNode | null; -}; +} -type Sequence = { +interface Sequence { head: SequenceNode; tail: SequenceNode; next: Sequence | null; prev: Sequence | null; closed: boolean; -}; +} diff --git a/src/ShapeContourDrawer.ts b/src/ShapeContourDrawer.ts index bc25c24..85a5a12 100644 --- a/src/ShapeContourDrawer.ts +++ b/src/ShapeContourDrawer.ts @@ -102,11 +102,11 @@ export class ShapeContourDrawer { } getContour() { - let l: ShapeContour[] = []; - let a = this.contours; + const l: ShapeContour[] = []; + const a = this.contours; for (let k = 0; k < a.length; k++) { let s = a[k].s; - let level = a[k].level; + const level = a[k].level; while (s) { let h: SequenceNode | null = s.head; const l2: ShapeContour = { lines: [], level, k }; diff --git a/src/__tests__/shape.test.ts b/src/__tests__/shape.test.ts index 82ab41b..2c44eb6 100644 --- a/src/__tests__/shape.test.ts +++ b/src/__tests__/shape.test.ts @@ -84,7 +84,7 @@ function parse(string: string) { .filter((line) => line); const matrix: number[][] = []; - for (let line of lines) { + for (const line of lines) { matrix.push(line.split('').map((value: string) => parseInt(value, 10))); } return matrix; diff --git a/src/calculateContour.ts b/src/calculateContour.ts index a95060b..3f4d724 100644 --- a/src/calculateContour.ts +++ b/src/calculateContour.ts @@ -185,10 +185,10 @@ export function calculateContour( return true; } for (let i = ilb; i < iub; i++) { - let dij = matrix[i][j]; - let dij1 = matrix[i][j + 1]; - let di1j = matrix[i + 1][j]; - let di1j1 = matrix[i + 1][j + 1]; + const dij = matrix[i][j]; + const dij1 = matrix[i][j + 1]; + const di1j = matrix[i + 1][j]; + const di1j1 = matrix[i + 1][j + 1]; let min1, min2, max1, max2; if (dij > dij1) { min1 = dij1; @@ -204,8 +204,8 @@ export function calculateContour( min2 = di1j; max2 = di1j1; } - let dmin = Math.min(min1, min2); - let dmax = Math.max(max1, max2); + const dmin = Math.min(min1, min2); + const dmax = Math.max(max1, max2); // Ternary operator is now much slower: https://jsbench.me/d5l0dh502g //let dmin = min1 > min2 ? min2 : min1; //let dmax = max1 > max2 ? max1 : max2; @@ -270,7 +270,7 @@ export function calculateContour( } else { m3 = 1; } - let caseValue = castab[sh[m1] + 1][sh[m2] + 1][sh[m3] + 1]; + const caseValue = castab[sh[m1] + 1][sh[m2] + 1][sh[m3] + 1]; if (caseValue !== 0) { switch (caseValue) { case 1: // Line between vertices 1 and 2 diff --git a/src/index.ts b/src/index.ts index 7cce9c7..9fc3a25 100644 --- a/src/index.ts +++ b/src/index.ts @@ -17,10 +17,10 @@ export type ContourDrawerName = 'basic' | 'shape'; type ContourDrawerByName = DrawerName extends 'basic' ? BasicContourDrawer : ShapeContourDrawer; -export type DrawContourResult = { +export interface DrawContourResult { contours: ReturnType['getContour']>; timeout: boolean; -}; +} export class Conrec { matrix: Readonly;