Skip to content

Commit

Permalink
refactor: ♻️ refactor with better typing and _ suffix for private met…
Browse files Browse the repository at this point in the history
…hods
  • Loading branch information
thkruz committed Jul 23, 2023
1 parent 9c5a87d commit 4b14b64
Show file tree
Hide file tree
Showing 10 changed files with 464 additions and 492 deletions.
97 changes: 34 additions & 63 deletions src/objects/base-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,69 +57,40 @@ export class BaseObject {
return this.type;
}

// eslint-disable-next-line complexity
public getTypeString(): string {
switch (this.type) {
case SpaceObjectType.UNKNOWN:
return 'Unknown';
case SpaceObjectType.PAYLOAD:
return 'Payload';
case SpaceObjectType.ROCKET_BODY:
return 'Rocket Body';
case SpaceObjectType.DEBRIS:
return 'Debris';
case SpaceObjectType.SPECIAL:
return 'Special';
case SpaceObjectType.RADAR_MEASUREMENT:
return 'Radar Measurement';
case SpaceObjectType.RADAR_TRACK:
return 'Radar Track';
case SpaceObjectType.RADAR_OBJECT:
return 'Radar Object';
case SpaceObjectType.BALLISTIC_MISSILE:
return 'Ballistic Missile';
case SpaceObjectType.STAR:
return 'Star';
case SpaceObjectType.INTERGOVERNMENTAL_ORGANIZATION:
return 'Intergovernmental Organization';
case SpaceObjectType.SUBORBITAL_PAYLOAD_OPERATOR:
return 'Suborbital Payload Operator';
case SpaceObjectType.PAYLOAD_OWNER:
return 'Payload Owner';
case SpaceObjectType.METEOROLOGICAL_ROCKET_LAUNCH_AGENCY_OR_MANUFACTURER:
return 'Meteorological Rocket Launch Agency or Manufacturer';
case SpaceObjectType.PAYLOAD_MANUFACTURER:
return 'Payload Manufacturer';
case SpaceObjectType.LAUNCH_AGENCY:
return 'Launch Agency';
case SpaceObjectType.LAUNCH_SITE:
return 'Launch Site';
case SpaceObjectType.LAUNCH_POSITION:
return 'Launch Position';
case SpaceObjectType.LAUNCH_FACILITY:
return 'Launch Facility';
case SpaceObjectType.CONTROL_FACILITY:
return 'Control Facility';
case SpaceObjectType.GROUND_SENSOR_STATION:
return 'Ground Sensor Station';
case SpaceObjectType.OPTICAL:
return 'Optical';
case SpaceObjectType.MECHANICAL:
return 'Mechanical';
case SpaceObjectType.PHASED_ARRAY_RADAR:
return 'Phased Array Radar';
case SpaceObjectType.OBSERVER:
return 'Observer';
case SpaceObjectType.BISTATIC_RADIO_TELESCOPE:
return 'Bistatic Radio Telescope';
case SpaceObjectType.COUNTRY:
return 'Country';
case SpaceObjectType.LAUNCH_VEHICLE_MANUFACTURER:
return 'Launch Vehicle Manufacturer';
case SpaceObjectType.ENGINE_MANUFACTURER:
return 'Engine Manufacturer';
default:
return 'Unknown';
}
const typeToStringMap: { [key in SpaceObjectType]?: string } = {
[SpaceObjectType.UNKNOWN]: 'Unknown',
[SpaceObjectType.PAYLOAD]: 'Payload',
[SpaceObjectType.ROCKET_BODY]: 'Rocket Body',
[SpaceObjectType.DEBRIS]: 'Debris',
[SpaceObjectType.SPECIAL]: 'Special',
[SpaceObjectType.RADAR_MEASUREMENT]: 'Radar Measurement',
[SpaceObjectType.RADAR_TRACK]: 'Radar Track',
[SpaceObjectType.RADAR_OBJECT]: 'Radar Object',
[SpaceObjectType.BALLISTIC_MISSILE]: 'Ballistic Missile',
[SpaceObjectType.STAR]: 'Star',
[SpaceObjectType.INTERGOVERNMENTAL_ORGANIZATION]: 'Intergovernmental Organization',
[SpaceObjectType.SUBORBITAL_PAYLOAD_OPERATOR]: 'Suborbital Payload Operator',
[SpaceObjectType.PAYLOAD_OWNER]: 'Payload Owner',
[SpaceObjectType.METEOROLOGICAL_ROCKET_LAUNCH_AGENCY_OR_MANUFACTURER]:
'Meteorological Rocket Launch Agency or Manufacturer',
[SpaceObjectType.PAYLOAD_MANUFACTURER]: 'Payload Manufacturer',
[SpaceObjectType.LAUNCH_AGENCY]: 'Launch Agency',
[SpaceObjectType.LAUNCH_SITE]: 'Launch Site',
[SpaceObjectType.LAUNCH_POSITION]: 'Launch Position',
[SpaceObjectType.LAUNCH_FACILITY]: 'Launch Facility',
[SpaceObjectType.CONTROL_FACILITY]: 'Control Facility',
[SpaceObjectType.GROUND_SENSOR_STATION]: 'Ground Sensor Station',
[SpaceObjectType.OPTICAL]: 'Optical',
[SpaceObjectType.MECHANICAL]: 'Mechanical',
[SpaceObjectType.PHASED_ARRAY_RADAR]: 'Phased Array Radar',
[SpaceObjectType.OBSERVER]: 'Observer',
[SpaceObjectType.BISTATIC_RADIO_TELESCOPE]: 'Bistatic Radio Telescope',
[SpaceObjectType.COUNTRY]: 'Country',
[SpaceObjectType.LAUNCH_VEHICLE_MANUFACTURER]: 'Launch Vehicle Manufacturer',
[SpaceObjectType.ENGINE_MANUFACTURER]: 'Engine Manufacturer',
};

return typeToStringMap[this.type] || 'Unknown';
}
}
10 changes: 6 additions & 4 deletions src/objects/sat.ts
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,8 @@ import {
SatelliteRecord,
SpaceObjectType,
StateVector,
TleLine1,
TleLine2,
} from '../types/types';

import { Sensor } from './sensor';
Expand All @@ -46,8 +48,8 @@ interface ObjectInfo {
type?: SpaceObjectType;
rcs?: number;
vmag?: number;
tle1: string;
tle2: string;
tle1: TleLine1
tle2: TleLine2
}

export class Sat extends SpaceObject {
Expand All @@ -72,7 +74,7 @@ export class Sat extends SpaceObject {
// eslint-disable-next-line @typescript-eslint/no-explicit-any
public options: any;

constructor(info: ObjectInfo, options) {
constructor(info: ObjectInfo, options?) {
super(info);

const tleData = Tle.parseTle(info.tle1, info.tle2);
Expand All @@ -95,7 +97,7 @@ export class Sat extends SpaceObject {
// NOTE: Calculate apogee and perigee

this.satrec = Sgp4.createSatrec(info.tle1, info.tle2);
this.options = options;
this.options = options ? options : {};
}

public propagateTo(date: Date): Sat {
Expand Down
6 changes: 3 additions & 3 deletions src/objects/sensor.ts
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@

import { Degrees, Kilometers, Radians, RaeVec3, SpaceObjectType } from '../types/types';

import { BaseObject } from './base-object';
import { RAD2DEG } from '../utils/constants';
import { BaseObject } from './base-object';
import { Sat } from './sat';

interface ObjectInfo {
Expand Down Expand Up @@ -242,7 +242,7 @@ export class Sensor extends BaseObject {
isInViewLast = this.isRaeInFov(oldRae);
}

const type = Sensor.getPassType(isInView, isInViewLast);
const type = Sensor.getPassType_(isInView, isInViewLast);

maxElThisPass = <Degrees>Math.max(maxElThisPass, rae.el);

Expand Down Expand Up @@ -270,7 +270,7 @@ export class Sensor extends BaseObject {
return msnPlanPasses;
}

private static getPassType(isInView: boolean, isInViewLast: boolean) {
private static getPassType_(isInView: boolean, isInViewLast: boolean) {
let type = PassType.OUT_OF_VIEW;

if (isInView && !isInViewLast) {
Expand Down
1 change: 0 additions & 1 deletion src/objects/space-object.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,6 @@ interface ObjectInfo {

export class SpaceObject extends BaseObject {
public rcs: number;

public vmag: number;

constructor(info: ObjectInfo) {
Expand Down
23 changes: 11 additions & 12 deletions src/objects/star.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
* Orbital Object ToolKit. If not, see <http://www.gnu.org/licenses/>.
*/

import { DAY_TO_MS, DEG2RAD, RAD2DEG } from '../utils/constants';
import {
Degrees,
EciVec3,
Expand All @@ -32,29 +31,29 @@ import {
RaeVec3,
SpaceObjectType,
} from '../types/types';
import { DAY_TO_MS, DEG2RAD, RAD2DEG } from '../utils/constants';

import { Sgp4 } from '../sgp4/sgp4';
import { SpaceObject } from './space-object';
import { Transforms } from '../transforms/transforms';
import { Utils } from '../utils/utils';
import { SpaceObject } from './space-object';

interface ObjectInfo {
bf?: string;
dec: Radians;
h?: string;
name?: string;
pname?: string;
ra: Radians;
type?: SpaceObjectType;
vmag?: number;
ra: Radians;
dec: Radians;
pname?: string;
bf?: string;
h?: string;
}

export class Star extends SpaceObject {
public pname: string;
public bf: string;
public h: string;

public dec: Radians;
public h: string;
public pname: string;
public ra: Radians;

constructor(info: ObjectInfo) {
Expand Down Expand Up @@ -87,7 +86,7 @@ export class Star extends SpaceObject {
date: Date = this.time,
): EciVec3 {
const rae = this.getRae(lla, date);
const { gmst } = Star.calculateTimeVariables(date);
const { gmst } = Star.calculateTimeVariables_(date);

// Arbitrary distance to enable using ECI coordinates
return Transforms.ecf2eci(Transforms.rae2ecf(rae, { lat: <Radians>0, lon: <Radians>0, alt: <Kilometers>0 }), gmst);
Expand All @@ -108,7 +107,7 @@ export class Star extends SpaceObject {
return { az: starPos.az, el: starPos.el, rng: <Kilometers>250000 };
}

private static calculateTimeVariables(date: Date): { gmst: GreenwichMeanSiderealTime; j: number } {
private static calculateTimeVariables_(date: Date): { gmst: GreenwichMeanSiderealTime; j: number } {
const j =
Utils.jday(
date.getUTCFullYear(),
Expand Down
Loading

0 comments on commit 4b14b64

Please sign in to comment.