diff --git a/src/lat_lon2n_E.ts b/src/lat_lon2n_E.ts index c90a980..40965a5 100644 --- a/src/lat_lon2n_E.ts +++ b/src/lat_lon2n_E.ts @@ -1,7 +1,6 @@ -export function lat_lon2n_E( - latitude: number, - longitude: number, -): [x: number, y: number, z: number] { +import type { Vector3 } from "./vector.js"; + +export function lat_lon2n_E(latitude: number, longitude: number): Vector3 { const sinLat = Math.sin(latitude); const cosLat = Math.cos(latitude); const sinLon = Math.sin(longitude); diff --git a/src/matrix.ts b/src/matrix.ts new file mode 100644 index 0000000..42df31a --- /dev/null +++ b/src/matrix.ts @@ -0,0 +1,5 @@ +export type Matrix3x3 = [ + [n00: number, n01: number, n02: number], + [n10: number, n11: number, n12: number], + [n20: number, n21: number, n22: number], +]; diff --git a/src/n_E2lat_lon.ts b/src/n_E2lat_lon.ts index bf8614a..eaee04a 100644 --- a/src/n_E2lat_lon.ts +++ b/src/n_E2lat_lon.ts @@ -1,8 +1,10 @@ +import type { Vector3 } from "./vector.js"; + export function n_E2lat_lon( - x: number, - y: number, - z: number, + n_E: Vector3, ): [latitude: number, longitude: number] { + const [x, y, z] = n_E; + const sinLat = z; const cosLat = Math.sqrt(y ** 2 + x ** 2); const cosLatSinLon = y; diff --git a/src/vector.ts b/src/vector.ts new file mode 100644 index 0000000..c46de37 --- /dev/null +++ b/src/vector.ts @@ -0,0 +1,2 @@ +export type Vector3 = [x: number, y: number, z: number]; +export type Vector4 = [x: number, y: number, z: number, w: number]; diff --git a/test/jest/n_E2lat_lon.spec.ts b/test/jest/n_E2lat_lon.spec.ts index dddd724..7b8cad6 100644 --- a/test/jest/n_E2lat_lon.spec.ts +++ b/test/jest/n_E2lat_lon.spec.ts @@ -22,11 +22,11 @@ describe("n_E2lat_lon()", () => { })("matches the Python implementation", async ([latitude, longitude]) => { const [x, y, z] = lat_lon2n_E(latitude, longitude); - const expected = await nvectorTestClient.n_E2lat_lon(x, y, z); + const expected = await nvectorTestClient.n_E2lat_lon([x, y, z]); expect(expected).toMatchObject([expect.any(Number), expect.any(Number)]); - const actual = n_E2lat_lon(x, y, z); + const actual = n_E2lat_lon([x, y, z]); expect(actual).toMatchObject([expect.any(Number), expect.any(Number)]); expect(actual[0]).toBeCloseTo(expected[0], 10); diff --git a/test/nvector-test-api.ts b/test/nvector-test-api.ts index fcbe1f6..9274d98 100644 --- a/test/nvector-test-api.ts +++ b/test/nvector-test-api.ts @@ -1,4 +1,5 @@ import { WebSocket } from "ws"; +import type { Vector3 } from "../src/vector.js"; export type NvectorTestClient = { lat_lon2n_E: ( @@ -6,11 +7,7 @@ export type NvectorTestClient = { longitude: number, ) => Promise<[x: number, y: number, z: number]>; - n_E2lat_lon: ( - x: number, - y: number, - z: number, - ) => Promise<[latitude: number, longitude: number]>; + n_E2lat_lon: (n_E: Vector3) => Promise<[latitude: number, longitude: number]>; close: () => void; }; @@ -34,7 +31,7 @@ export async function createNvectorTestClient(): Promise { return [x, y, z]; }, - async n_E2lat_lon(x, y, z) { + async n_E2lat_lon([x, y, z]) { const { latitude, longitude } = await call<{ latitude: number; longitude: number;