diff --git a/src/coordinate/RelativeState.ts b/src/coordinate/RelativeState.ts index 3c7dc21..52d6847 100644 --- a/src/coordinate/RelativeState.ts +++ b/src/coordinate/RelativeState.ts @@ -69,8 +69,8 @@ export abstract class RelativeState { * Calculates the range of the relative state. * @returns The range in kilometers. */ - range(): Kilometers { - return this.position.magnitude() as Kilometers; + get range(): Kilometers { + return this.position.magnitude(); } /** @@ -79,7 +79,7 @@ export abstract class RelativeState { * * @returns The range rate in Kilometers per second. */ - rangeRate(): number { - return this.position.dot(this.velocity) / this.range(); + get rangeRate(): number { + return this.position.dot(this.velocity) / this.range; } } diff --git a/test/coordinate/RIC.test.ts b/test/coordinate/RIC.test.ts index 9bba0d9..8d457f3 100644 --- a/test/coordinate/RIC.test.ts +++ b/test/coordinate/RIC.test.ts @@ -80,4 +80,28 @@ describe('RIC', () => { expect(name).toMatchSnapshot(); }); + + // toString + it('should return a string representation of the RIC coordinate', () => { + const ric = new RIC(stateVector.position, stateVector.velocity); + const string = ric.toString(); + + expect(string).toMatchSnapshot(); + }); + + // range + it('should return the range of the RIC coordinate', () => { + const ric = new RIC(stateVector.position, stateVector.velocity); + const range = ric.range; + + expect(range).toMatchSnapshot(); + }); + + // rangeRate + it('should return the range rate of the RIC coordinate', () => { + const ric = new RIC(stateVector.position, stateVector.velocity); + const rangeRate = ric.rangeRate; + + expect(rangeRate).toMatchSnapshot(); + }); }); diff --git a/test/coordinate/__snapshots__/RIC.test.ts.snap b/test/coordinate/__snapshots__/RIC.test.ts.snap index ac93284..d8e3935 100644 --- a/test/coordinate/__snapshots__/RIC.test.ts.snap +++ b/test/coordinate/__snapshots__/RIC.test.ts.snap @@ -32,6 +32,16 @@ RIC { exports[`RIC should get the name of the RIC coordinate system 1`] = `"RIC"`; +exports[`RIC should return a string representation of the RIC coordinate 1`] = ` +"[RIC] + Position: [1538.223336, 5102.261204, 4432.634965] km + Velocity: [-7.341518909, 0.651671845, 1.793388250] km/s" +`; + +exports[`RIC should return the range of the RIC coordinate 1`] = `6931.627020979389`; + +exports[`RIC should return the range rate of the RIC coordinate 1`] = `-0.002663194316531782`; + exports[`RIC should transform the current RIC coordinate to J2000 using the provided origin and transform matrix 1`] = ` J2000 { "epoch": EpochUTC {