Skip to content

Commit

Permalink
fix(ootk-sgp4): moved constants to local scope for speed increase des…
Browse files Browse the repository at this point in the history
…pite memory usage
  • Loading branch information
thkruz committed Jan 16, 2021
1 parent 959e37d commit 11b8c72
Showing 1 changed file with 48 additions and 77 deletions.
125 changes: 48 additions & 77 deletions src/ootk-sgp4.ts
Original file line number Diff line number Diff line change
Expand Up @@ -90,39 +90,6 @@
const PI = Math.PI;
const TAU = PI * 2;
const DEG2RAD = PI / 180.0;
const x2o3 = 2.0 / 3.0;
const xpdotp = 1440.0 / (2.0 * PI); // 229.1831180523293;
const zes = 0.01675;
const zel = 0.0549;
const c1ss = 2.9864797e-6;
const c1l = 4.7968065e-7;
const zsinis = 0.39785416;
const zcosis = 0.91744867;
const zcosgs = 0.1945905;
const zsings = -0.98088458;
const q22 = 1.7891679e-6;
const q31 = 2.1460748e-6;
const q33 = 2.2123015e-7;
const root22 = 1.7891679e-6;
const root44 = 7.3636953e-9;
const root54 = 2.1765803e-9;
const rptim = 4.37526908801129966e-3; // equates to 7.29211514668855e-5 rad/sec
const root32 = 3.7393792e-7;
const root52 = 1.1428639e-7;
const znl = 1.5835218e-4;
const zns = 1.19459e-5;
const temp4 = 1.5e-12;
const fasx2 = 0.13130908;
const fasx4 = 2.8843198;
const fasx6 = 0.37448087;
const g22 = 5.7686396;
const g32 = 0.95240898;
const g44 = 1.8014998;
const g52 = 1.050833;
const g54 = 4.4108898;
const stepp = 720.0;
const stepn = -720.0;
const step2 = 259200.0;

/** @interface SatelliteRecord contains all of the orbital parameters necessary for running SGP4. It is generated by Sgp4.createSatrec.*/
interface SatelliteRecord {
Expand Down Expand Up @@ -385,10 +352,10 @@ class Sgp4 {

// ---------------------- constants -----------------------------
/** Ootk -- Declared outside the class at the top */
// zns = 1.19459e-5;
// zes = 0.01675;
// znl = 1.5835218e-4;
// zel = 0.0549;
const zns = 1.19459e-5;
const zes = 0.01675;
const znl = 1.5835218e-4;
const zel = 0.0549;

// --------------- calculate time varying periodics -----------
let zm = zmos + zns * t;
Expand Down Expand Up @@ -662,15 +629,15 @@ class Sgp4 {

// -------------------------- constants -------------------------
/** Ootk -- These are declared outside the class at the top of the file */
// zes = 0.01675;
// zel = 0.0549;
// c1ss = 2.9864797e-6;
// c1l = 4.7968065e-7;
// zsinis = 0.39785416;
// zcosis = 0.91744867;
// zcosgs = 0.1945905;
// zsings = -0.98088458;
// TAU = 2.0 * Math.PI;
const zes = 0.01675;
const zel = 0.0549;
const c1ss = 2.9864797e-6;
const c1l = 4.7968065e-7;
const zsinis = 0.39785416;
const zcosis = 0.91744867;
const zcosgs = 0.1945905;
const zsings = -0.98088458;
const TAU = 2.0 * Math.PI;

// --------------------- local variables ------------------------
let s1,
Expand Down Expand Up @@ -1222,18 +1189,18 @@ class Sgp4 {
/* --------------------- local variables ------------------------ */
/** Ootk -- these are declared at the top instead */

// q22 = 1.7891679e-6;
// q31 = 2.1460748e-6;
// q33 = 2.2123015e-7;
// root22 = 1.7891679e-6;
// root44 = 7.3636953e-9;
// root54 = 2.1765803e-9;
// rptim = 4.37526908801129966e-3; // equates to 7.29211514668855e-5 rad/sec
// root32 = 3.7393792e-7;
// root52 = 1.1428639e-7;
// x2o3 = 2.0 / 3.0;
// znl = 1.5835218e-4;
// zns = 1.19459e-5;
const q22 = 1.7891679e-6;
const q31 = 2.1460748e-6;
const q33 = 2.2123015e-7;
const root22 = 1.7891679e-6;
const root44 = 7.3636953e-9;
const root54 = 2.1765803e-9;
const rptim = 4.37526908801129966e-3; // equates to 7.29211514668855e-5 rad/sec
const root32 = 3.7393792e-7;
const root52 = 1.1428639e-7;
const x2o3 = 2.0 / 3.0;
const znl = 1.5835218e-4;
const zns = 1.19459e-5;

// sgp4fix identify constants and allow alternate values
// just xke is used here so pass it in rather than have multiple calls
Expand Down Expand Up @@ -1604,18 +1571,18 @@ class Sgp4 {
let { atime, em, argpm, inclm, xli, mm, xni, nodem, nm } = options;

/** Ootk -- Declared at the top of the file instead */
// fasx2 = 0.13130908;
// fasx4 = 2.8843198;
// fasx6 = 0.37448087;
// g22 = 5.7686396;
// g32 = 0.95240898;
// g44 = 1.8014998;
// g52 = 1.050833;
// g54 = 4.4108898;
// rptim = 4.37526908801129966e-3; // equates to 7.29211514668855e-5 rad/sec
// stepp = 720.0;
// stepn = -720.0;
// step2 = 259200.0;
const fasx2 = 0.13130908;
const fasx4 = 2.8843198;
const fasx6 = 0.37448087;
const g22 = 5.7686396;
const g32 = 0.95240898;
const g44 = 1.8014998;
const g52 = 1.050833;
const g54 = 4.4108898;
const rptim = 4.37526908801129966e-3; // equates to 7.29211514668855e-5 rad/sec
const stepp = 720.0;
const stepn = -720.0;
const step2 = 259200.0;

// ----------- calculate deep space resonance effects -----------
let dndt = 0.0;
Expand Down Expand Up @@ -1835,7 +1802,9 @@ class Sgp4 {
let no = options.no;

/* --------------------- local variables ------------------------ */
/** Ootk -- Declared at the top of the file */
const PI = Math.PI;
const TAU = PI * 2;
const x2o3 = 2.0 / 3.0;

// sgp4fix use old way of finding gst
/** Ootk -- Declared at the top of the file */
Expand Down Expand Up @@ -2032,13 +2001,15 @@ class Sgp4 {
} = options;

/* --------------------- local variables ------------------------ */
/** Ootk -- Declared at the top of the file */
const PI = Math.PI;
const TAU = PI * 2;
const x2o3 = 2.0 / 3.0;

/* ------------------------ initialization --------------------- */
// sgp4fix divisor for divide by zero check on inclination
// the old check used 1.0 + Math.cos(PI-1.0e-9), but then compared it to
// 1.5 e-12, so the threshold was changed to 1.5e-12 for consistency
// temp4 = 1.5e-12;
const temp4 = 1.5e-12;

// ----------- set all near earth variables to zero ------------
satrec.isimp = 0;
Expand Down Expand Up @@ -2684,8 +2655,8 @@ class Sgp4 {
// the old check used 1.0 + cos(PI-1.0e-9), but then compared it to
// 1.5 e-12, so the threshold was changed to 1.5e-12 for consistency

/** Ootk -- Declared at the top of the page */
// temp4 = 1.5e-12;
const x2o3 = 2.0 / 3.0;
const temp4 = 1.5e-12;

// sgp4fix identify constants and allow alternate values
// getgravconst( whichconst, tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2 );
Expand Down Expand Up @@ -3125,8 +3096,7 @@ class Sgp4 {
tleLine2: string,
whichconst = 'wgs72',
opsmode = 'i',
): SatelliteRecord {
// xpdotp = 1440.0 / (2.0 * PI); // 229.1831180523293;
): SatelliteRecord {
let year = 0;

let satrec = {
Expand Down Expand Up @@ -3251,6 +3221,7 @@ class Sgp4 {

// sgp4fix no longer needed
// getgravconst( whichconst, tumin, mu, radiusearthkm, xke, j2, j3, j4, j3oj2 );
const xpdotp = 1440.0 / (2.0 * PI); // 229.1831180523293;

satrec.error = 0;

Expand Down

0 comments on commit 11b8c72

Please sign in to comment.