From a15b4e2bdd735dc378568105675985bcda70ab79 Mon Sep 17 00:00:00 2001 From: Aric Camarata Date: Sat, 30 May 2026 18:50:48 -0400 Subject: [PATCH] fix: satisfy strict null checks in spk/math/visibility --- src/math/index.ts | 14 +++++++------- src/spk/index.ts | 11 ++++++----- src/visibility/index.ts | 2 +- 3 files changed, 14 insertions(+), 13 deletions(-) diff --git a/src/math/index.ts b/src/math/index.ts index 3904cd4..a5a2264 100644 --- a/src/math/index.ts +++ b/src/math/index.ts @@ -130,7 +130,7 @@ export function rotZ(theta: number): Mat3 { export function chebyshevEval(coeffs: Float64Array, x: number): number { const n = coeffs.length if (n === 0) return 0 - if (n === 1) return coeffs[0] + if (n === 1) return coeffs[0]! // Float64Array length checked above; index 0 is valid // Double-x for Clenshaw efficiency const x2 = 2 * x @@ -138,12 +138,12 @@ export function chebyshevEval(coeffs: Float64Array, x: number): number { let b1 = 0 for (let k = n - 1; k >= 1; k--) { - const b0 = coeffs[k] + x2 * b1 - b2 + const b0 = coeffs[k]! + x2 * b1 - b2 // k in [1, n-1]; all valid indices b2 = b1 b1 = b0 } - return coeffs[0] + x * b1 - b2 + return coeffs[0]! + x * b1 - b2 // index 0 valid; n >= 2 at this point } /** @@ -162,7 +162,7 @@ export function chebyshevEvalWithDerivative( ): [number, number] { const n = coeffs.length if (n === 0) return [0, 0] - if (n === 1) return [coeffs[0], 0] + if (n === 1) return [coeffs[0]!, 0] // length checked; index 0 valid const x2 = 2 * x let b2 = 0 @@ -171,7 +171,7 @@ export function chebyshevEvalWithDerivative( let db1 = 0 for (let k = n - 1; k >= 1; k--) { - const b0 = coeffs[k] + x2 * b1 - b2 + const b0 = coeffs[k]! + x2 * b1 - b2 // k in [1, n-1]; all valid indices const db0 = 2 * b1 + x2 * db1 - db2 b2 = b1 b1 = b0 @@ -179,7 +179,7 @@ export function chebyshevEvalWithDerivative( db1 = db0 } - const value = coeffs[0] + x * b1 - b2 + const value = coeffs[0]! + x * b1 - b2 // index 0 valid; n >= 2 at this point const dvalue = b1 + x * db1 - db2 // Scale derivative from normalized domain back to seconds return [value, dvalue / radius] @@ -300,7 +300,7 @@ export function findRoots(f: (t: number) => number, a: number, b: number, steps const root = brentRoot(f, tPrev, t, 1e-9, 64) if (root !== null) { // Deduplicate roots that are too close together - if (roots.length === 0 || Math.abs(root - roots[roots.length - 1]) > 1e-6) { + if (roots.length === 0 || Math.abs(root - roots[roots.length - 1]!) > 1e-6) { // length > 0 checked via || roots.push(root) } } diff --git a/src/spk/index.ts b/src/spk/index.ts index 2991849..2bcc67e 100644 --- a/src/spk/index.ts +++ b/src/spk/index.ts @@ -386,7 +386,7 @@ export function parseLsk(text: string): ReadonlyArray const match = text.match(/DELTET\/DELTA_AT\s*=\s*\(\s*([\s\S]*?)\)/m) if (!match) return results - const block = match[1] + const block = match[1]! // regex has one capture group; match[1] is present when match succeeds const months: Record = { JAN: 1, FEB: 2, @@ -406,10 +406,11 @@ export function parseLsk(text: string): ReadonlyArray let m: RegExpExecArray | null while ((m = pairRe.exec(block)) !== null) { - const deltaAT = parseFloat(m[1]) - const year = parseInt(m[2]) - const month = months[m[3]] ?? 1 - const day = parseInt(m[4]) + // m[1]..m[4] are capture groups; regex guarantees they are present when exec matches + const deltaAT = parseFloat(m[1]!) + const year = parseInt(m[2]!) + const month = months[m[3]!] ?? 1 + const day = parseInt(m[4]!) // Gregorian to JD (noon = integer JD) const a = Math.floor((14 - month) / 12) diff --git a/src/visibility/index.ts b/src/visibility/index.ts index 01536f6..88c64f3 100644 --- a/src/visibility/index.ts +++ b/src/visibility/index.ts @@ -285,5 +285,5 @@ function azimuthToCardinal(az: number): string { 'NNW', ] const idx = Math.round(az / 22.5) % 16 - return dirs[(idx + 16) % 16] + return dirs[(idx + 16) % 16]! // dirs has 16 elements; (idx+16)%16 is always 0..15 }