diff --git a/src/objects/BaseObject.ts b/src/objects/BaseObject.ts index 4cf9c45..6da279a 100644 --- a/src/objects/BaseObject.ts +++ b/src/objects/BaseObject.ts @@ -39,17 +39,19 @@ export class BaseObject { this.id = info.id; this.active = info.active ?? true; + // Default to the center of the earth until position is calculated this.position = info.position ?? { x: 0, y: 0, z: 0, - }; // Default to the center of the earth until position is calculated + }; + // Default to 0 velocity until velocity is calculated this.velocity = info.velocity ?? { x: 0, y: 0, z: 0, - }; // Default to 0 velocity until velocity is calculated + }; this.totalVelocity = Math.sqrt(this.velocity.x ** 2 + this.velocity.y ** 2 + this.velocity.z ** 2); } @@ -62,25 +64,11 @@ export class BaseObject { } /** - * Checks if the object is a land object. - * @returns True if the object is a land object, false otherwise. + * Checks if the object is a ground object. + * @returns True if the object is a ground object, false otherwise. */ - isLandObject(): boolean { - switch (this.type) { - case SpaceObjectType.INTERGOVERNMENTAL_ORGANIZATION: - case SpaceObjectType.SUBORBITAL_PAYLOAD_OPERATOR: - case SpaceObjectType.PAYLOAD_OWNER: - case SpaceObjectType.METEOROLOGICAL_ROCKET_LAUNCH_AGENCY_OR_MANUFACTURER: - case SpaceObjectType.PAYLOAD_MANUFACTURER: - case SpaceObjectType.LAUNCH_VEHICLE_MANUFACTURER: - case SpaceObjectType.ENGINE_MANUFACTURER: - case SpaceObjectType.LAUNCH_AGENCY: - case SpaceObjectType.LAUNCH_SITE: - case SpaceObjectType.LAUNCH_POSITION: - return true; - default: - return false; - } + isGroundObject(): boolean { + return false; } /** @@ -104,7 +92,7 @@ export class BaseObject { * @returns True if the object is static, false otherwise. */ isStatic(): boolean { - return true; + return this.velocity.x === 0 && this.velocity.y === 0 && this.velocity.z === 0; } isPayload(): boolean { diff --git a/src/objects/GroundObject.ts b/src/objects/GroundObject.ts index 0663266..2d42845 100644 --- a/src/objects/GroundObject.ts +++ b/src/objects/GroundObject.ts @@ -36,6 +36,7 @@ import { DEG2RAD, Geodetic, BaseObjectParams, + SpaceObjectType, } from '../main'; import { BaseObject } from './BaseObject'; @@ -133,4 +134,22 @@ export class GroundObject extends BaseObject { this.validateParameter(info.lon, -180, 180, 'Invalid longitude - must be between -180 and 180'); this.validateParameter(info.alt, 0, null, 'Invalid altitude - must be greater than 0'); } + + isGroundObject(): boolean { + switch (this.type) { + case SpaceObjectType.INTERGOVERNMENTAL_ORGANIZATION: + case SpaceObjectType.SUBORBITAL_PAYLOAD_OPERATOR: + case SpaceObjectType.PAYLOAD_OWNER: + case SpaceObjectType.METEOROLOGICAL_ROCKET_LAUNCH_AGENCY_OR_MANUFACTURER: + case SpaceObjectType.PAYLOAD_MANUFACTURER: + case SpaceObjectType.LAUNCH_VEHICLE_MANUFACTURER: + case SpaceObjectType.ENGINE_MANUFACTURER: + case SpaceObjectType.LAUNCH_AGENCY: + case SpaceObjectType.LAUNCH_SITE: + case SpaceObjectType.LAUNCH_POSITION: + return true; + default: + return false; + } + } } diff --git a/test/objects/BaseObject.test.ts b/test/objects/BaseObject.test.ts index 197b442..5f674cf 100644 --- a/test/objects/BaseObject.test.ts +++ b/test/objects/BaseObject.test.ts @@ -1,4 +1,4 @@ -import { BaseObject, BaseObjectParams, EciVec3, SpaceObjectType } from '../../src/main'; +import { BaseObject, BaseObjectParams, EciVec3, Kilometers, SpaceObjectType } from '../../src/main'; const mockVelocity = { x: 8000, y: 0, @@ -18,7 +18,7 @@ describe('BaseObject', () => { name: 'Satellite', position: mockPosition, velocity: mockVelocity, - time: new Date(), + active: true, }; @@ -69,7 +69,6 @@ describe('BaseObject', () => { name: 'Satellite', position: mockPosition, velocity: mockVelocity, - time: new Date(), active: true, }; @@ -87,7 +86,6 @@ describe('BaseObject', () => { name: 'Rocket', position: mockPosition, velocity: mockVelocity, - time: new Date(), active: true, }; @@ -105,7 +103,6 @@ describe('BaseObject', () => { name: 'Debris', position: mockPosition, velocity: mockVelocity, - time: new Date(), active: true, }; @@ -123,7 +120,6 @@ describe('BaseObject', () => { name: 'Star Object', position: mockPosition, velocity: mockVelocity, - time: new Date(), active: true, }; @@ -141,7 +137,6 @@ describe('BaseObject', () => { name: 'Missile', position: mockPosition, velocity: mockVelocity, - time: new Date(), active: true, }; @@ -157,7 +152,6 @@ describe('BaseObject', () => { name: 'Notional Object', position: mockPosition, velocity: mockVelocity, - time: new Date(), active: true, }; @@ -173,7 +167,6 @@ describe('BaseObject', () => { name: 'Satellite', position: mockPosition, velocity: mockVelocity, - time: new Date(), active: true, }; @@ -191,7 +184,6 @@ describe('BaseObject', () => { name: 'Satellite', position: mockPosition, velocity: mockVelocity, - time: new Date(), active: true, }; @@ -209,7 +201,6 @@ describe('BaseObject', () => { name: 'Satellite', position: mockPosition, velocity: mockVelocity, - time: new Date(), active: true, }; @@ -221,21 +212,28 @@ describe('BaseObject', () => { }); // check if BaseObject is static - it('should return true when calling isStatic() method', () => { - const info: BaseObjectParams = { + it('should return coorect value when calling isStatic() method', () => { + const movingObject = new BaseObject({ type: SpaceObjectType.PAYLOAD, name: 'Satellite', position: mockPosition, velocity: mockVelocity, - time: new Date(), active: true, - }; - - const baseObject = new BaseObject(info); - - const result = baseObject.isStatic(); + }); + const staticObject = new BaseObject({ + type: SpaceObjectType.PAYLOAD, + name: 'Satellite', + position: mockPosition, + velocity: { + x: 0 as Kilometers, + y: 0 as Kilometers, + z: 0 as Kilometers, + }, + active: true, + }); - expect(result).toBe(true); + expect(movingObject.isStatic()).toBe(false); + expect(staticObject.isStatic()).toBe(true); }); // check if BaseObject is a land object @@ -245,13 +243,12 @@ describe('BaseObject', () => { name: 'Ground Sensor Station', position: mockPosition, velocity: mockVelocity, - time: new Date(), active: true, }; const baseObject = new BaseObject(info); - const result = baseObject.isLandObject(); + const result = baseObject.isGroundObject(); expect(result).toBe(false); }); diff --git a/test/utils/__snapshots__/functions.test.ts.snap b/test/utils/__snapshots__/functions.test.ts.snap index c8d1faa..18f1e3a 100644 --- a/test/utils/__snapshots__/functions.test.ts.snap +++ b/test/utils/__snapshots__/functions.test.ts.snap @@ -44,6 +44,8 @@ Array [ exports[`functions should be calculate csch 1`] = `0.8509181282393216`; +exports[`functions should be calculate deg2rad 1`] = `0.017453292519943295`; + exports[`functions should be calculate derivative 1`] = `[Function]`; exports[`functions should be calculate gamma 1`] = `1`; @@ -68,6 +70,8 @@ exports[`functions should be calculate log10 1`] = `2`; exports[`functions should be calculate mean 1`] = `2`; +exports[`functions should be calculate rad2deg 1`] = `57.29577951308232`; + exports[`functions should be calculate sech 1`] = `0.6480542736638855`; exports[`functions should be calculate sign 1`] = `1`;