Skip to content

Commit

Permalink
More d_light() tweaks and initializers in test_error.c
Browse files Browse the repository at this point in the history
  • Loading branch information
attipaci committed May 31, 2024
1 parent f74a67c commit 044dee9
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 42 deletions.
10 changes: 5 additions & 5 deletions src/novas.c
Original file line number Diff line number Diff line change
Expand Up @@ -3946,7 +3946,7 @@ short light_time(double jd_tdb, const object *body, const double *pos_obs, doubl
* </ol>
*
* @param pos_src Position vector towards observed object, with respect to the SSB
* (<i>Usage A</i>), relative to the observer / geocenter (<i>Usage B</i>).
* (<i>Usage A</i>), or relative to the observer / geocenter (<i>Usage B</i>).
* @param pos_body [AU] Position of observer relative to SSB (<i>Usage A</i>), or position of
* intermediate solar-system body with respect to the observer / geocenter
* (<i>Usage B</i>).
Expand All @@ -3957,18 +3957,18 @@ short light_time(double jd_tdb, const object *body, const double *pos_obs, doubl
* @sa place()
*/
double d_light(const double *pos_src, const double *pos_body) {
double d;
double d_src;

if(!pos_src || !pos_body) {
novas_set_errno(EINVAL, "d_light", "NULL input 3-vector: pos_src=%p, pos_body=%p [=> NAN]", pos_src, pos_body);
return NAN;
}

d = vlen(pos_src);
d_src = vlen(pos_src);

// Light-time returned is the projection of vector 'pos_obs' onto the
// unit vector 'u1' (formed from 'pos1'), divided by the speed of light.
return d > 1e-30 ? vdot(pos_body, pos_src) / vlen(pos_src) / C_AUDAY : 0.0;
// unit vector 'u1' (formed from 'pos_body'), divided by the speed of light.
return d_src > 1e-30 ? vdot(pos_body, pos_src) / d_src / C_AUDAY : 0.0;
}

/**
Expand Down
70 changes: 33 additions & 37 deletions test/src/test-errors.c
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ static int test_make_on_surface() {
}

static int test_make_in_space() {
double p[3], v[3];
double p[3] = {1.0}, v[3] = {};
in_space sp;
int n = 0;

Expand Down Expand Up @@ -113,7 +113,7 @@ static int test_make_object() {
}

static int test_refract() {
on_surface o;
on_surface o = {};
int n = 0;

novas_debug(NOVAS_DEBUG_ON);
Expand Down Expand Up @@ -155,7 +155,7 @@ static int test_limb_angle() {


static int test_transform_cat() {
cat_entry c, c1;
cat_entry c = {}, c1;
int n = 0;

char longname[SIZE_OF_OBJ_NAME + 1];
Expand All @@ -171,7 +171,7 @@ static int test_transform_cat() {
}

static int test_transform_hip() {
cat_entry c;
cat_entry c = {};
int n = 0;

if(check("transform_hip:in", -1, transform_hip(NULL, &c))) n++;
Expand Down Expand Up @@ -208,7 +208,7 @@ static int test_j2000_to_tod() {
}

static int test_tod_to_j2000() {
double p[3];
double p[3] = {1.0};
int n = 0;

if(check("tod_to_j2000:in", -1, tod_to_j2000(0.0, NOVAS_FULL_ACCURACY, NULL, p))) n++;
Expand All @@ -219,7 +219,7 @@ static int test_tod_to_j2000() {
}

static int test_gcrs_to_cirs() {
double p[3];
double p[3] = {1.0};
int n = 0;

if(check("gcrs_to_cirs:in", -1, gcrs_to_cirs(0.0, NOVAS_FULL_ACCURACY, NULL, p))) n++;
Expand Down Expand Up @@ -251,8 +251,8 @@ static int test_set_planet_provider_hp() {
}

static int test_place_star() {
cat_entry c;
observer loc;
cat_entry c = {};
observer loc = {};
sky_pos pos;
int n = 0;

Expand All @@ -263,8 +263,8 @@ static int test_place_star() {
}

static int test_place() {
object o;
observer loc;
object o = {};
observer loc = {};
sky_pos pos;
int n = 0;

Expand All @@ -277,7 +277,7 @@ static int test_place() {
}

static int test_radec_planet() {
object o;
object o = {};
observer loc = {};
double ra, dec, dis, rv;

Expand Down Expand Up @@ -339,7 +339,7 @@ static int test_ecl2equ() {
}

static int test_equ2ecl_vec() {
double p[3];
double p[3] = {1.0};
int n = 0;

if(check("equ2ecl_vec:in", -1, equ2ecl_vec(0.0, NOVAS_MEAN_EQUATOR, NOVAS_FULL_ACCURACY, NULL, p))) n++;
Expand All @@ -351,7 +351,7 @@ static int test_equ2ecl_vec() {
}

static int test_ecl2equ_vec() {
double p[3];
double p[3] = {1.0};
int n = 0;

if(check("ecl2equ_vec:in", -1, ecl2equ_vec(0.0, NOVAS_MEAN_EQUATOR, NOVAS_FULL_ACCURACY, NULL, p))) n++;
Expand All @@ -364,7 +364,7 @@ static int test_ecl2equ_vec() {


static int test_itrs_to_hor() {
on_surface loc;
on_surface loc = {};
double p[3], az, za;
int n = 0;

Expand All @@ -375,7 +375,7 @@ static int test_itrs_to_hor() {
}

static int test_hor_to_itrs() {
on_surface loc;
on_surface loc = {};
double p[3];
int n = 0;

Expand All @@ -387,7 +387,7 @@ static int test_hor_to_itrs() {

static int test_equ2hor() {
on_surface loc;
double p[3], az, za, rar, decr;
double az, za, rar, decr;
int n = 0;

if(check("equ2hor:loc", -1, equ2hor(0.0, 0.0, NOVAS_FULL_ACCURACY, 0.0, 0.0, NULL, 0.0, 0.0, NOVAS_STANDARD_ATMOSPHERE, &az, &za, &rar, &decr))) n++;
Expand Down Expand Up @@ -420,7 +420,7 @@ static int test_sidereal_time() {
}

static int test_ter2cel() {
double p[3];
double p[3] = {1.0};
int n = 0;

if(check("ter2cel:in", -1, ter2cel(0.0, 0.0, 0.0, EROT_GST, NOVAS_FULL_ACCURACY, NOVAS_DYNAMICAL_CLASS, 0.0, 0.0, NULL, p))) n++;
Expand All @@ -432,7 +432,7 @@ static int test_ter2cel() {
}

static int test_cel2ter() {
double p[3];
double p[3] = {1.0};
int n = 0;

if(check("cel2ter:in", -1, cel2ter(0.0, 0.0, 0.0, EROT_GST, NOVAS_FULL_ACCURACY, NOVAS_DYNAMICAL_CLASS, 0.0, 0.0, NULL, p))) n++;
Expand All @@ -445,7 +445,7 @@ static int test_cel2ter() {


static int test_spin() {
double p[3];
double p[3] = {1.0};
int n = 0;

if(check("spin:in", -1, spin(0.0, NULL, p))) n++;
Expand All @@ -455,7 +455,7 @@ static int test_spin() {
}

static int test_wobble() {
double p[3];
double p[3] = {1.0};
int n = 0;

if(check("wobble:in", -1, wobble(0.0, WOBBLE_ITRS_TO_PEF, 0.0, 0.0, NULL, p))) n++;
Expand All @@ -465,7 +465,7 @@ static int test_wobble() {
}

static int test_terra() {
on_surface loc;
on_surface loc = {};
double p[3], v[3];
int n = 0;

Expand All @@ -476,8 +476,6 @@ static int test_terra() {
}

static int test_e_tilt() {
on_surface loc;
double p[3], v[3];
int n = 0;

if(check("e_tilt:accuracy", -1, e_tilt(0.0, -1, NULL, NULL, NULL, NULL, NULL))) n++;
Expand All @@ -488,8 +486,6 @@ static int test_e_tilt() {


static int test_cel_pole() {
on_surface loc;
double p[3], v[3];
int n = 0;

if(check("cel_pole:type", 1, cel_pole(0.0, -1, 0.0, 0.0))) n++;
Expand All @@ -498,7 +494,7 @@ static int test_cel_pole() {
}

static int test_frame_tie() {
double p[3];
double p[3] = {1.0};
int n = 0;

if(check("frame_tie:in", -1, frame_tie(NULL, 0, p))) n++;
Expand All @@ -509,7 +505,7 @@ static int test_frame_tie() {


static int test_proper_motion() {
double p[3], v[3];
double p[3] = {1.0}, v[3] = {1.0};
int n = 0;

if(check("frame_tie:p", -1, proper_motion(0.0, NULL, v, 1.0, p))) n++;
Expand All @@ -520,7 +516,7 @@ static int test_proper_motion() {
}

static int test_bary2obs() {
double p[3], po[3], out[3], lt;
double p[3] = {}, po[3] = {}, out[3], lt;
int n = 0;

if(check("bary2obs:pos", -1, bary2obs(NULL, po, out, &lt))) n++;
Expand Down Expand Up @@ -548,7 +544,7 @@ static int test_geo_posvel() {

static int test_light_time2() {
object o;
double pos[3], p[3], v[3], t;
double pos[3] = {1.0}, p[3], v[3], t;
int n = 0;

if(check("light_time2:tout", -1, light_time2(0.0, &o, pos, 0.0, NOVAS_FULL_ACCURACY, p, v, NULL))) n++;
Expand All @@ -562,7 +558,7 @@ static int test_light_time2() {
}

static int test_d_light() {
double p[3];
double p[3] = {1.0};
int n = 0;

if(check("d_light:1", 1, isnan(d_light(NULL, p)))) n++;
Expand Down Expand Up @@ -649,7 +645,7 @@ static int test_radec2vector() {
}

static int test_vector2radec() {
double p[3] = { }, ra, dec;
double p[3] = {}, ra, dec;
int n = 0;

if(check("vector2radec:vec", -1, vector2radec(NULL, &ra, &dec))) n++;
Expand Down Expand Up @@ -701,7 +697,7 @@ static int test_set_nutation_lp_provider() {
}

static int test_nutation() {
double p[3];
double p[3] = {1.0};
int n = 0;

if(check("nutation:in", -1, nutation(0.0, NUTATE_MEAN_TO_TRUE, NOVAS_FULL_ACCURACY, NULL, p))) n++;
Expand All @@ -711,7 +707,7 @@ static int test_nutation() {
}

static int test_precession() {
double p[3];
double p[3] = {1.0};
int n = 0;

if(check("precesion:in", -1, precession(0.0, NULL, 1.0, p))) n++;
Expand All @@ -722,7 +718,7 @@ static int test_precession() {

static int test_rad_vel() {
object o;
double p[3], v[3], vo[3], rv;
double p[3] = {}, v[3] = {}, vo[3] = {}, rv;
int n = 0;

o.type = NOVAS_PLANET;
Expand All @@ -740,7 +736,7 @@ static int test_rad_vel() {
}

static int test_aberration() {
double p[3], v[3] = {};
double p[3] = {1.0}, v[3] = {};
int n = 0;

if(check("aberration:pos", -1, aberration(NULL, v, 0.0, p))) n++;
Expand All @@ -751,7 +747,7 @@ static int test_aberration() {
}

static int test_grav_vec() {
double p[3], po[3], pb[3];
double p[3] = {2.0}, po[3] = {0.0, 1.0}, pb[3] = {};
int n = 0;

if(check("grav_vec:pos", -1, grav_vec(NULL, po, pb, 1.0, p))) n++;
Expand All @@ -763,7 +759,7 @@ static int test_grav_vec() {
}

static int test_grav_def() {
double p[3], po[3], pb[3];
double p[3] = {2.0}, po[3] = {0.0, 1.0}, pb[3] = {};
int n = 0;

if(check("grav_def:pos", -1, grav_def(NOVAS_JD_J2000, NOVAS_OBSERVER_AT_GEOCENTER, NOVAS_FULL_ACCURACY, NULL, po, p))) n++;
Expand Down

0 comments on commit 044dee9

Please sign in to comment.