@@ -290,15 +290,23 @@ const StarList = [
290
290
] ;
291
291
;
292
292
const StarTable = [
293
- { ra : 0 , dec : 0 , dist : exports . AU_PER_LY } ,
294
- { ra : 0 , dec : 0 , dist : exports . AU_PER_LY } ,
295
- { ra : 0 , dec : 0 , dist : exports . AU_PER_LY } ,
296
- { ra : 0 , dec : 0 , dist : exports . AU_PER_LY } ,
297
- { ra : 0 , dec : 0 , dist : exports . AU_PER_LY } ,
298
- { ra : 0 , dec : 0 , dist : exports . AU_PER_LY } ,
299
- { ra : 0 , dec : 0 , dist : exports . AU_PER_LY } ,
300
- { ra : 0 , dec : 0 , dist : exports . AU_PER_LY } ,
293
+ { ra : 0 , dec : 0 , dist : 0 } ,
294
+ { ra : 0 , dec : 0 , dist : 0 } ,
295
+ { ra : 0 , dec : 0 , dist : 0 } ,
296
+ { ra : 0 , dec : 0 , dist : 0 } ,
297
+ { ra : 0 , dec : 0 , dist : 0 } ,
298
+ { ra : 0 , dec : 0 , dist : 0 } ,
299
+ { ra : 0 , dec : 0 , dist : 0 } ,
300
+ { ra : 0 , dec : 0 , dist : 0 } ,
301
301
] ;
302
+ function GetStar ( body ) {
303
+ const index = StarList . indexOf ( body ) ;
304
+ return ( index >= 0 ) ? StarTable [ index ] : null ;
305
+ }
306
+ function UserDefinedStar ( body ) {
307
+ const star = GetStar ( body ) ;
308
+ return ( star && star . dist > 0 ) ? star : null ;
309
+ }
302
310
/**
303
311
* @brief Assign equatorial coordinates to a user-defined star.
304
312
*
@@ -307,10 +315,8 @@ const StarTable = [
307
315
* This function assigns a right ascension, declination, and distance
308
316
* to one of the eight user-defined stars `Star1`..`Star8`.
309
317
*
310
- * A star that has not been defined through a call to `DefineStar`
311
- * defaults to the coordinates RA=0, DEC=0 and a heliocentric distance of 1 light-year.
312
- * Once defined, the star keeps the given coordinates until
313
- * a subsequent call to `DefineStar` replaces the coordinates with new values.
318
+ * Stars are not valid until defined. Once defined, they retain their
319
+ * definition until re-defined by another call to `DefineStar`.
314
320
*
315
321
* @param {Body } body
316
322
* One of the eight user-defined star identifiers:
@@ -332,8 +338,8 @@ const StarTable = [
332
338
* The minimum allowed distance is 1 light-year, which is required to provide certain internal optimizations.
333
339
*/
334
340
function DefineStar ( body , ra , dec , distanceLightYears ) {
335
- const index = StarList . indexOf ( body ) ;
336
- if ( index < 0 )
341
+ const star = GetStar ( body ) ;
342
+ if ( ! star )
337
343
throw `Invalid star body: ${ body } ` ;
338
344
VerifyNumber ( ra ) ;
339
345
VerifyNumber ( dec ) ;
@@ -344,7 +350,9 @@ function DefineStar(body, ra, dec, distanceLightYears) {
344
350
throw `Invalid declination for star: ${ dec } ` ;
345
351
if ( distanceLightYears < 1 )
346
352
throw `Invalid star distance: ${ distanceLightYears } ` ;
347
- StarTable [ index ] = { ra : ra , dec : dec , dist : distanceLightYears * exports . AU_PER_LY } ;
353
+ star . ra = ra ;
354
+ star . dec = dec ;
355
+ star . dist = distanceLightYears * exports . AU_PER_LY ;
348
356
}
349
357
exports . DefineStar = DefineStar ;
350
358
var PrecessDirection ;
@@ -2483,7 +2491,7 @@ function Horizon(date, observer, ra, dec, refraction) {
2483
2491
const coszd = Math . cos ( zd * exports . DEG2RAD ) ;
2484
2492
const sinzd0 = Math . sin ( zd0 * exports . DEG2RAD ) ;
2485
2493
const coszd0 = Math . cos ( zd0 * exports . DEG2RAD ) ;
2486
- var pr = [ ] ;
2494
+ const pr = [ ] ;
2487
2495
for ( let j = 0 ; j < 3 ; ++ j ) {
2488
2496
pr . push ( ( ( p [ j ] - coszd0 * uz [ j ] ) / sinzd0 ) * sinzd + uz [ j ] * coszd ) ;
2489
2497
}
@@ -3662,12 +3670,6 @@ exports.JupiterMoons = JupiterMoons;
3662
3670
*/
3663
3671
function HelioVector ( body , date ) {
3664
3672
var time = MakeTime ( date ) ;
3665
- const starIndex = StarList . indexOf ( body ) ;
3666
- if ( starIndex >= 0 ) {
3667
- const star = StarTable [ starIndex ] ;
3668
- const sphere = new Spherical ( star . dec , 15 * star . ra , star . dist ) ;
3669
- return VectorFromSphere ( sphere , time ) ;
3670
- }
3671
3673
if ( body in vsop )
3672
3674
return CalcVsop ( vsop [ body ] , time ) ;
3673
3675
if ( body === Body . Pluto ) {
@@ -3689,6 +3691,11 @@ function HelioVector(body, date) {
3689
3691
}
3690
3692
if ( body === Body . SSB )
3691
3693
return CalcSolarSystemBarycenter ( time ) ;
3694
+ const star = UserDefinedStar ( body ) ;
3695
+ if ( star ) {
3696
+ const sphere = new Spherical ( star . dec , 15 * star . ra , star . dist ) ;
3697
+ return VectorFromSphere ( sphere , time ) ;
3698
+ }
3692
3699
throw `HelioVector: Unknown body "${ body } "` ;
3693
3700
}
3694
3701
exports . HelioVector = HelioVector ;
@@ -3704,7 +3711,7 @@ exports.HelioVector = HelioVector;
3704
3711
*
3705
3712
* @param {Body } body
3706
3713
* A body for which to calculate a heliocentric distance:
3707
- * the Sun, Moon, or any of the planets.
3714
+ * the Sun, Moon, any of the planets, or a user-defined star .
3708
3715
*
3709
3716
* @param {FlexibleDateTime } date
3710
3717
* The date and time for which to calculate the heliocentric distance.
@@ -3713,6 +3720,9 @@ exports.HelioVector = HelioVector;
3713
3720
* The heliocentric distance in AU.
3714
3721
*/
3715
3722
function HelioDistance ( body , date ) {
3723
+ const star = UserDefinedStar ( body ) ;
3724
+ if ( star )
3725
+ return star . dist ;
3716
3726
const time = MakeTime ( date ) ;
3717
3727
if ( body in vsop )
3718
3728
return VsopFormula ( vsop [ body ] [ RAD_INDEX ] , time . tt / DAYS_PER_MILLENNIUM , false ) ;
@@ -3860,7 +3870,7 @@ class BodyPosition extends PositionFunction {
3860
3870
function BackdatePosition ( date , observerBody , targetBody , aberration ) {
3861
3871
VerifyBoolean ( aberration ) ;
3862
3872
const time = MakeTime ( date ) ;
3863
- if ( StarList . indexOf ( targetBody ) >= 0 ) {
3873
+ if ( UserDefinedStar ( targetBody ) ) {
3864
3874
// This is a user-defined star, which must be treated as a special case.
3865
3875
// First, we assume its heliocentric position does not change with time.
3866
3876
// Second, we assume its heliocentric position has already been corrected
0 commit comments