diff --git a/src/body/Earth.ts b/src/body/Earth.ts index ff1ed43..4fa872f 100644 --- a/src/body/Earth.ts +++ b/src/body/Earth.ts @@ -90,8 +90,8 @@ export class Earth { ); // / Calculate mean motion _(rad/s)_ from a given [semimajorAxis] _(km)_. - static smaToMeanMotion(semimajorAxis: number): number { - return Math.sqrt(Earth.mu / (semimajorAxis * semimajorAxis * semimajorAxis)); + static smaToMeanMotion(semimajorAxis: Kilometers): RadiansPerSecond { + return Math.sqrt(Earth.mu / (semimajorAxis * semimajorAxis * semimajorAxis)) as RadiansPerSecond; } /** diff --git a/src/objects/Satellite.ts b/src/objects/Satellite.ts index 40e080e..f7664a1 100644 --- a/src/objects/Satellite.ts +++ b/src/objects/Satellite.ts @@ -46,6 +46,7 @@ import { Radians, RaeVec3, SatelliteRecord, + Seconds, TleLine1, TleLine2, } from '../types/types'; @@ -187,7 +188,7 @@ export class Satellite extends BaseObject { toRae(observer: GroundObject, date: Date = new Date()): RAE { const rae = this.rae(observer, date); const rae2 = this.rae(observer, new Date(date.getTime() + 1000)); - const epoch = new EpochUTC(date.getTime()); + const epoch = new EpochUTC(date.getTime() / 1000 as Seconds); const rangeRate = rae2.rng - rae.rng; const azimuthRate = rae2.az - rae.az; const elevationRate = rae2.el - rae.el; @@ -257,7 +258,7 @@ export class Satellite extends BaseObject { const p = pv.position as EciVec3; const v = pv.velocity as EciVec3; - const epoch = new EpochUTC(date.getTime()); + const epoch = new EpochUTC(date.getTime() / 1000 as Seconds); const pos = new Vector3D(p.x, p.y, p.z); const vel = new Vector3D(v.x, v.y, v.z); diff --git a/src/time/Epoch.ts b/src/time/Epoch.ts index d07b293..8245eee 100644 --- a/src/time/Epoch.ts +++ b/src/time/Epoch.ts @@ -21,7 +21,7 @@ * SOFTWARE. */ -import { Seconds } from 'src/main'; +import { Seconds } from '../main'; import { secondsPerDay } from '../utils/constants'; // / Base class for [Epoch] data. @@ -30,7 +30,7 @@ export class Epoch { * Create a new [Epoch] object given the number of seconds elapsed since the * [posix] epoch _(`1970-01-01T00:00:00.000`)_ in the [Epoch] time scale. */ - constructor(public posix: number) { + constructor(public posix: Seconds) { if (posix < 0) { throw new Error('Epoch cannot be negative'); } diff --git a/src/time/EpochUTC.ts b/src/time/EpochUTC.ts index 7e0b0d4..5a6dee5 100644 --- a/src/time/EpochUTC.ts +++ b/src/time/EpochUTC.ts @@ -51,7 +51,7 @@ type DateToPosixParams = { export class EpochUTC extends Epoch { static now() { - return new EpochUTC(new Date().getTime() / 1000); + return new EpochUTC(new Date().getTime() / 1000 as Seconds); } static fromDate({ year, month, day, hour = 0, minute = 0, second = 0 }: FromDateParams) { @@ -59,17 +59,17 @@ export class EpochUTC extends Epoch { } static fromDateTime(dt: Date) { - return new EpochUTC(dt.getTime() / 1000); + return new EpochUTC(dt.getTime() / 1000 as Seconds); } static fromDateTimeString(dateTimeString: string): EpochUTC { const dts = dateTimeString.trim().toUpperCase().endsWith('Z') ? dateTimeString : `${dateTimeString}Z`; - return new EpochUTC(new Date(dts).getTime() / 1000); + return new EpochUTC(new Date(dts).getTime() / 1000 as Seconds); } static fromJ2000TTSeconds(seconds: Seconds): EpochUTC { - const tInit = new EpochUTC(seconds + 946728000); + const tInit = new EpochUTC(seconds + 946728000 as Seconds); const ls = DataHandler.getInstance().getLeapSeconds(tInit.toJulianDate()); return tInit.roll(-32.184 - ls as Seconds); @@ -85,11 +85,11 @@ export class EpochUTC extends Epoch { // Add day - 1 days in milliseconds to the epoch. const dts = new Date(`${year}-01-01T${timeField}Z`).getTime() + (day - 1) * MS_PER_DAY; - return new EpochUTC(dts / 1000); + return new EpochUTC(dts / 1000 as Seconds); } roll(seconds: Seconds): EpochUTC { - return new EpochUTC(this.posix + seconds); + return new EpochUTC(this.posix + seconds as Seconds); } toMjd(): number { @@ -103,20 +103,20 @@ export class EpochUTC extends Epoch { toTAI(): EpochTAI { const ls = DataHandler.getInstance().getLeapSeconds(this.toJulianDate()); - return new EpochTAI(this.posix + ls); + return new EpochTAI(this.posix + ls as Seconds); } toTT(): EpochTT { - return new EpochTT(this.toTAI().posix + 32.184); + return new EpochTT(this.toTAI().posix + 32.184 as Seconds); } toTDB(): EpochTDB { const tt = this.toTT(); const tTT = tt.toJulianCenturies(); const mEarth = (357.5277233 + 35999.05034 * tTT) * DEG2RAD; - const seconds = 0.001658 * Math.sin(mEarth) + 0.00001385 * Math.sin(2 * mEarth); + const seconds = 0.001658 * Math.sin(mEarth) + 0.00001385 * Math.sin(2 * mEarth) as Seconds; - return new EpochTDB(tt.posix + seconds); + return new EpochTDB(tt.posix + seconds as Seconds); } toGPS(): EpochGPS { @@ -168,7 +168,7 @@ export class EpochUTC extends Epoch { return EpochUTC.dayOfYearLookup_[dex][month - 1] + day - 1; } - private static dateToPosix_({ year, month, day, hour, minute, second }: DateToPosixParams): number { + private static dateToPosix_({ year, month, day, hour, minute, second }: DateToPosixParams): Seconds { const days = EpochUTC.dayOfYear_(year, month, day); const yearMod = year - 1900; @@ -181,6 +181,6 @@ export class EpochUTC extends Epoch { Math.floor((yearMod - 1) / 100) * 86400 + Math.floor((yearMod + 299) / 400) * 86400 + second - ); + ) as Seconds; } } diff --git a/test/objects/__snapshots__/Satellite.test.ts.snap b/test/objects/__snapshots__/Satellite.test.ts.snap index 72cf2fc..5e2e7bf 100644 --- a/test/objects/__snapshots__/Satellite.test.ts.snap +++ b/test/objects/__snapshots__/Satellite.test.ts.snap @@ -25,26 +25,26 @@ Object { exports[`Satellite should calculate and return Geodetic coordinates when given a date 1`] = ` Geodetic { - "alt": 405.17244322847, - "lat": 0.1099327125671112, - "lon": 0.2809557331563047, + "alt": 409.48725329355693, + "lat": -0.48221646502840027, + "lon": 1.2198848056557416, } `; exports[`Satellite should calculate and return ITRF coordinates when called 1`] = ` ITRF { "epoch": EpochUTC { - "posix": 1705109326817, + "posix": 1705109326.817, }, "position": Vector3D { - "x": 6478.244529235784, - "y": 1869.552512878403, - "z": 739.5500168212324, + "x": 2068.607191044621, + "y": 5650.9777806539605, + "z": -3130.036328555523, }, "velocity": Vector3D { - "x": 2.366559347644857, - "y": -7.704390508005883, - "z": -1.227328372730736, + "x": -5.491548321368525, + "y": -0.6798748760128108, + "z": -4.863052489363518, }, } `; @@ -64,7 +64,7 @@ RAE { "elRad": -1.2837885129141846, "elRateRad": -0.03103994353789119, "epoch": EpochUTC { - "posix": 1705109326817, + "posix": 1705109326.817, }, "rng": 12650.301530537545, "rngRate": 1.8799097918581538,