Skip to content

Commit

Permalink
Accept a Vector3 in lat_lon2n_E
Browse files Browse the repository at this point in the history
  • Loading branch information
ezzatron committed Apr 26, 2024
1 parent efa5d8a commit 3e834e5
Show file tree
Hide file tree
Showing 6 changed files with 20 additions and 15 deletions.
7 changes: 3 additions & 4 deletions src/lat_lon2n_E.ts
Original file line number Diff line number Diff line change
@@ -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);
Expand Down
5 changes: 5 additions & 0 deletions src/matrix.ts
Original file line number Diff line number Diff line change
@@ -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],
];
8 changes: 5 additions & 3 deletions src/n_E2lat_lon.ts
Original file line number Diff line number Diff line change
@@ -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;
Expand Down
2 changes: 2 additions & 0 deletions src/vector.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
export type Vector3 = [x: number, y: number, z: number];
export type Vector4 = [x: number, y: number, z: number, w: number];
4 changes: 2 additions & 2 deletions test/jest/n_E2lat_lon.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
9 changes: 3 additions & 6 deletions test/nvector-test-api.ts
Original file line number Diff line number Diff line change
@@ -1,16 +1,13 @@
import { WebSocket } from "ws";
import type { Vector3 } from "../src/vector.js";

export type NvectorTestClient = {
lat_lon2n_E: (
latitude: number,
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;
};
Expand All @@ -34,7 +31,7 @@ export async function createNvectorTestClient(): Promise<NvectorTestClient> {
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;
Expand Down

0 comments on commit 3e834e5

Please sign in to comment.