intl/icu/source/i18n/astro.h

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

michael@0 1 /************************************************************************
michael@0 2 * Copyright (C) 1996-2008, International Business Machines Corporation *
michael@0 3 * and others. All Rights Reserved. *
michael@0 4 ************************************************************************
michael@0 5 * 2003-nov-07 srl Port from Java
michael@0 6 */
michael@0 7
michael@0 8 #ifndef ASTRO_H
michael@0 9 #define ASTRO_H
michael@0 10
michael@0 11 #include "unicode/utypes.h"
michael@0 12
michael@0 13 #if !UCONFIG_NO_FORMATTING
michael@0 14
michael@0 15 #include "gregoimp.h" // for Math
michael@0 16 #include "unicode/unistr.h"
michael@0 17
michael@0 18 U_NAMESPACE_BEGIN
michael@0 19
michael@0 20 /**
michael@0 21 * <code>CalendarAstronomer</code> is a class that can perform the calculations to
michael@0 22 * determine the positions of the sun and moon, the time of sunrise and
michael@0 23 * sunset, and other astronomy-related data. The calculations it performs
michael@0 24 * are in some cases quite complicated, and this utility class saves you
michael@0 25 * the trouble of worrying about them.
michael@0 26 * <p>
michael@0 27 * The measurement of time is a very important part of astronomy. Because
michael@0 28 * astronomical bodies are constantly in motion, observations are only valid
michael@0 29 * at a given moment in time. Accordingly, each <code>CalendarAstronomer</code>
michael@0 30 * object has a <code>time</code> property that determines the date
michael@0 31 * and time for which its calculations are performed. You can set and
michael@0 32 * retrieve this property with {@link #setDate setDate}, {@link #getDate getDate}
michael@0 33 * and related methods.
michael@0 34 * <p>
michael@0 35 * Almost all of the calculations performed by this class, or by any
michael@0 36 * astronomer, are approximations to various degrees of accuracy. The
michael@0 37 * calculations in this class are mostly modelled after those described
michael@0 38 * in the book
michael@0 39 * <a href="http://www.amazon.com/exec/obidos/ISBN=0521356997" target="_top">
michael@0 40 * Practical Astronomy With Your Calculator</a>, by Peter J.
michael@0 41 * Duffett-Smith, Cambridge University Press, 1990. This is an excellent
michael@0 42 * book, and if you want a greater understanding of how these calculations
michael@0 43 * are performed it a very good, readable starting point.
michael@0 44 * <p>
michael@0 45 * <strong>WARNING:</strong> This class is very early in its development, and
michael@0 46 * it is highly likely that its API will change to some degree in the future.
michael@0 47 * At the moment, it basically does just enough to support {@link IslamicCalendar}
michael@0 48 * and {@link ChineseCalendar}.
michael@0 49 *
michael@0 50 * @author Laura Werner
michael@0 51 * @author Alan Liu
michael@0 52 * @internal
michael@0 53 */
michael@0 54 class U_I18N_API CalendarAstronomer : public UMemory {
michael@0 55 public:
michael@0 56 // some classes
michael@0 57
michael@0 58 public:
michael@0 59 /**
michael@0 60 * Represents the position of an object in the sky relative to the ecliptic,
michael@0 61 * the plane of the earth's orbit around the Sun.
michael@0 62 * This is a spherical coordinate system in which the latitude
michael@0 63 * specifies the position north or south of the plane of the ecliptic.
michael@0 64 * The longitude specifies the position along the ecliptic plane
michael@0 65 * relative to the "First Point of Aries", which is the Sun's position in the sky
michael@0 66 * at the Vernal Equinox.
michael@0 67 * <p>
michael@0 68 * Note that Ecliptic objects are immutable and cannot be modified
michael@0 69 * once they are constructed. This allows them to be passed and returned by
michael@0 70 * value without worrying about whether other code will modify them.
michael@0 71 *
michael@0 72 * @see CalendarAstronomer.Equatorial
michael@0 73 * @see CalendarAstronomer.Horizon
michael@0 74 * @internal
michael@0 75 */
michael@0 76 class U_I18N_API Ecliptic : public UMemory {
michael@0 77 public:
michael@0 78 /**
michael@0 79 * Constructs an Ecliptic coordinate object.
michael@0 80 * <p>
michael@0 81 * @param lat The ecliptic latitude, measured in radians.
michael@0 82 * @param lon The ecliptic longitude, measured in radians.
michael@0 83 * @internal
michael@0 84 */
michael@0 85 Ecliptic(double lat = 0, double lon = 0) {
michael@0 86 latitude = lat;
michael@0 87 longitude = lon;
michael@0 88 }
michael@0 89
michael@0 90 /**
michael@0 91 * Setter for Ecliptic Coordinate object
michael@0 92 * @param lat The ecliptic latitude, measured in radians.
michael@0 93 * @param lon The ecliptic longitude, measured in radians.
michael@0 94 * @internal
michael@0 95 */
michael@0 96 void set(double lat, double lon) {
michael@0 97 latitude = lat;
michael@0 98 longitude = lon;
michael@0 99 }
michael@0 100
michael@0 101 /**
michael@0 102 * Return a string representation of this object
michael@0 103 * @internal
michael@0 104 */
michael@0 105 UnicodeString toString() const;
michael@0 106
michael@0 107 /**
michael@0 108 * The ecliptic latitude, in radians. This specifies an object's
michael@0 109 * position north or south of the plane of the ecliptic,
michael@0 110 * with positive angles representing north.
michael@0 111 * @internal
michael@0 112 */
michael@0 113 double latitude;
michael@0 114
michael@0 115 /**
michael@0 116 * The ecliptic longitude, in radians.
michael@0 117 * This specifies an object's position along the ecliptic plane
michael@0 118 * relative to the "First Point of Aries", which is the Sun's position
michael@0 119 * in the sky at the Vernal Equinox,
michael@0 120 * with positive angles representing east.
michael@0 121 * <p>
michael@0 122 * A bit of trivia: the first point of Aries is currently in the
michael@0 123 * constellation Pisces, due to the precession of the earth's axis.
michael@0 124 * @internal
michael@0 125 */
michael@0 126 double longitude;
michael@0 127 };
michael@0 128
michael@0 129 /**
michael@0 130 * Represents the position of an
michael@0 131 * object in the sky relative to the plane of the earth's equator.
michael@0 132 * The <i>Right Ascension</i> specifies the position east or west
michael@0 133 * along the equator, relative to the sun's position at the vernal
michael@0 134 * equinox. The <i>Declination</i> is the position north or south
michael@0 135 * of the equatorial plane.
michael@0 136 * <p>
michael@0 137 * Note that Equatorial objects are immutable and cannot be modified
michael@0 138 * once they are constructed. This allows them to be passed and returned by
michael@0 139 * value without worrying about whether other code will modify them.
michael@0 140 *
michael@0 141 * @see CalendarAstronomer.Ecliptic
michael@0 142 * @see CalendarAstronomer.Horizon
michael@0 143 * @internal
michael@0 144 */
michael@0 145 class U_I18N_API Equatorial : public UMemory {
michael@0 146 public:
michael@0 147 /**
michael@0 148 * Constructs an Equatorial coordinate object.
michael@0 149 * <p>
michael@0 150 * @param asc The right ascension, measured in radians.
michael@0 151 * @param dec The declination, measured in radians.
michael@0 152 * @internal
michael@0 153 */
michael@0 154 Equatorial(double asc = 0, double dec = 0)
michael@0 155 : ascension(asc), declination(dec) { }
michael@0 156
michael@0 157 /**
michael@0 158 * Setter
michael@0 159 * @param asc The right ascension, measured in radians.
michael@0 160 * @param dec The declination, measured in radians.
michael@0 161 * @internal
michael@0 162 */
michael@0 163 void set(double asc, double dec) {
michael@0 164 ascension = asc;
michael@0 165 declination = dec;
michael@0 166 }
michael@0 167
michael@0 168 /**
michael@0 169 * Return a string representation of this object, with the
michael@0 170 * angles measured in degrees.
michael@0 171 * @internal
michael@0 172 */
michael@0 173 UnicodeString toString() const;
michael@0 174
michael@0 175 /**
michael@0 176 * Return a string representation of this object with the right ascension
michael@0 177 * measured in hours, minutes, and seconds.
michael@0 178 * @internal
michael@0 179 */
michael@0 180 //String toHmsString() {
michael@0 181 //return radToHms(ascension) + "," + radToDms(declination);
michael@0 182 //}
michael@0 183
michael@0 184 /**
michael@0 185 * The right ascension, in radians.
michael@0 186 * This is the position east or west along the equator
michael@0 187 * relative to the sun's position at the vernal equinox,
michael@0 188 * with positive angles representing East.
michael@0 189 * @internal
michael@0 190 */
michael@0 191 double ascension;
michael@0 192
michael@0 193 /**
michael@0 194 * The declination, in radians.
michael@0 195 * This is the position north or south of the equatorial plane,
michael@0 196 * with positive angles representing north.
michael@0 197 * @internal
michael@0 198 */
michael@0 199 double declination;
michael@0 200 };
michael@0 201
michael@0 202 /**
michael@0 203 * Represents the position of an object in the sky relative to
michael@0 204 * the local horizon.
michael@0 205 * The <i>Altitude</i> represents the object's elevation above the horizon,
michael@0 206 * with objects below the horizon having a negative altitude.
michael@0 207 * The <i>Azimuth</i> is the geographic direction of the object from the
michael@0 208 * observer's position, with 0 representing north. The azimuth increases
michael@0 209 * clockwise from north.
michael@0 210 * <p>
michael@0 211 * Note that Horizon objects are immutable and cannot be modified
michael@0 212 * once they are constructed. This allows them to be passed and returned by
michael@0 213 * value without worrying about whether other code will modify them.
michael@0 214 *
michael@0 215 * @see CalendarAstronomer.Ecliptic
michael@0 216 * @see CalendarAstronomer.Equatorial
michael@0 217 * @internal
michael@0 218 */
michael@0 219 class U_I18N_API Horizon : public UMemory {
michael@0 220 public:
michael@0 221 /**
michael@0 222 * Constructs a Horizon coordinate object.
michael@0 223 * <p>
michael@0 224 * @param alt The altitude, measured in radians above the horizon.
michael@0 225 * @param azim The azimuth, measured in radians clockwise from north.
michael@0 226 * @internal
michael@0 227 */
michael@0 228 Horizon(double alt=0, double azim=0)
michael@0 229 : altitude(alt), azimuth(azim) { }
michael@0 230
michael@0 231 /**
michael@0 232 * Setter for Ecliptic Coordinate object
michael@0 233 * @param alt The altitude, measured in radians above the horizon.
michael@0 234 * @param azim The azimuth, measured in radians clockwise from north.
michael@0 235 * @internal
michael@0 236 */
michael@0 237 void set(double alt, double azim) {
michael@0 238 altitude = alt;
michael@0 239 azimuth = azim;
michael@0 240 }
michael@0 241
michael@0 242 /**
michael@0 243 * Return a string representation of this object, with the
michael@0 244 * angles measured in degrees.
michael@0 245 * @internal
michael@0 246 */
michael@0 247 UnicodeString toString() const;
michael@0 248
michael@0 249 /**
michael@0 250 * The object's altitude above the horizon, in radians.
michael@0 251 * @internal
michael@0 252 */
michael@0 253 double altitude;
michael@0 254
michael@0 255 /**
michael@0 256 * The object's direction, in radians clockwise from north.
michael@0 257 * @internal
michael@0 258 */
michael@0 259 double azimuth;
michael@0 260 };
michael@0 261
michael@0 262 public:
michael@0 263 //-------------------------------------------------------------------------
michael@0 264 // Assorted private data used for conversions
michael@0 265 //-------------------------------------------------------------------------
michael@0 266
michael@0 267 // My own copies of these so compilers are more likely to optimize them away
michael@0 268 static const double PI;
michael@0 269
michael@0 270 /**
michael@0 271 * The average number of solar days from one new moon to the next. This is the time
michael@0 272 * it takes for the moon to return the same ecliptic longitude as the sun.
michael@0 273 * It is longer than the sidereal month because the sun's longitude increases
michael@0 274 * during the year due to the revolution of the earth around the sun.
michael@0 275 * Approximately 29.53.
michael@0 276 *
michael@0 277 * @see #SIDEREAL_MONTH
michael@0 278 * @internal
michael@0 279 * @deprecated ICU 2.4. This class may be removed or modified.
michael@0 280 */
michael@0 281 static const double SYNODIC_MONTH;
michael@0 282
michael@0 283 //-------------------------------------------------------------------------
michael@0 284 // Constructors
michael@0 285 //-------------------------------------------------------------------------
michael@0 286
michael@0 287 /**
michael@0 288 * Construct a new <code>CalendarAstronomer</code> object that is initialized to
michael@0 289 * the current date and time.
michael@0 290 * @internal
michael@0 291 */
michael@0 292 CalendarAstronomer();
michael@0 293
michael@0 294 /**
michael@0 295 * Construct a new <code>CalendarAstronomer</code> object that is initialized to
michael@0 296 * the specified date and time.
michael@0 297 * @internal
michael@0 298 */
michael@0 299 CalendarAstronomer(UDate d);
michael@0 300
michael@0 301 /**
michael@0 302 * Construct a new <code>CalendarAstronomer</code> object with the given
michael@0 303 * latitude and longitude. The object's time is set to the current
michael@0 304 * date and time.
michael@0 305 * <p>
michael@0 306 * @param longitude The desired longitude, in <em>degrees</em> east of
michael@0 307 * the Greenwich meridian.
michael@0 308 *
michael@0 309 * @param latitude The desired latitude, in <em>degrees</em>. Positive
michael@0 310 * values signify North, negative South.
michael@0 311 *
michael@0 312 * @see java.util.Date#getTime()
michael@0 313 * @internal
michael@0 314 */
michael@0 315 CalendarAstronomer(double longitude, double latitude);
michael@0 316
michael@0 317 /**
michael@0 318 * Destructor
michael@0 319 * @internal
michael@0 320 */
michael@0 321 ~CalendarAstronomer();
michael@0 322
michael@0 323 //-------------------------------------------------------------------------
michael@0 324 // Time and date getters and setters
michael@0 325 //-------------------------------------------------------------------------
michael@0 326
michael@0 327 /**
michael@0 328 * Set the current date and time of this <code>CalendarAstronomer</code> object. All
michael@0 329 * astronomical calculations are performed based on this time setting.
michael@0 330 *
michael@0 331 * @param aTime the date and time, expressed as the number of milliseconds since
michael@0 332 * 1/1/1970 0:00 GMT (Gregorian).
michael@0 333 *
michael@0 334 * @see #setDate
michael@0 335 * @see #getTime
michael@0 336 * @internal
michael@0 337 */
michael@0 338 void setTime(UDate aTime);
michael@0 339
michael@0 340
michael@0 341 /**
michael@0 342 * Set the current date and time of this <code>CalendarAstronomer</code> object. All
michael@0 343 * astronomical calculations are performed based on this time setting.
michael@0 344 *
michael@0 345 * @param aTime the date and time, expressed as the number of milliseconds since
michael@0 346 * 1/1/1970 0:00 GMT (Gregorian).
michael@0 347 *
michael@0 348 * @see #getTime
michael@0 349 * @internal
michael@0 350 */
michael@0 351 void setDate(UDate aDate) { setTime(aDate); }
michael@0 352
michael@0 353 /**
michael@0 354 * Set the current date and time of this <code>CalendarAstronomer</code> object. All
michael@0 355 * astronomical calculations are performed based on this time setting.
michael@0 356 *
michael@0 357 * @param jdn the desired time, expressed as a "julian day number",
michael@0 358 * which is the number of elapsed days since
michael@0 359 * 1/1/4713 BC (Julian), 12:00 GMT. Note that julian day
michael@0 360 * numbers start at <em>noon</em>. To get the jdn for
michael@0 361 * the corresponding midnight, subtract 0.5.
michael@0 362 *
michael@0 363 * @see #getJulianDay
michael@0 364 * @see #JULIAN_EPOCH_MS
michael@0 365 * @internal
michael@0 366 */
michael@0 367 void setJulianDay(double jdn);
michael@0 368
michael@0 369 /**
michael@0 370 * Get the current time of this <code>CalendarAstronomer</code> object,
michael@0 371 * represented as the number of milliseconds since
michael@0 372 * 1/1/1970 AD 0:00 GMT (Gregorian).
michael@0 373 *
michael@0 374 * @see #setTime
michael@0 375 * @see #getDate
michael@0 376 * @internal
michael@0 377 */
michael@0 378 UDate getTime();
michael@0 379
michael@0 380 /**
michael@0 381 * Get the current time of this <code>CalendarAstronomer</code> object,
michael@0 382 * expressed as a "julian day number", which is the number of elapsed
michael@0 383 * days since 1/1/4713 BC (Julian), 12:00 GMT.
michael@0 384 *
michael@0 385 * @see #setJulianDay
michael@0 386 * @see #JULIAN_EPOCH_MS
michael@0 387 * @internal
michael@0 388 */
michael@0 389 double getJulianDay();
michael@0 390
michael@0 391 /**
michael@0 392 * Return this object's time expressed in julian centuries:
michael@0 393 * the number of centuries after 1/1/1900 AD, 12:00 GMT
michael@0 394 *
michael@0 395 * @see #getJulianDay
michael@0 396 * @internal
michael@0 397 */
michael@0 398 double getJulianCentury();
michael@0 399
michael@0 400 /**
michael@0 401 * Returns the current Greenwich sidereal time, measured in hours
michael@0 402 * @internal
michael@0 403 */
michael@0 404 double getGreenwichSidereal();
michael@0 405
michael@0 406 private:
michael@0 407 double getSiderealOffset();
michael@0 408 public:
michael@0 409 /**
michael@0 410 * Returns the current local sidereal time, measured in hours
michael@0 411 * @internal
michael@0 412 */
michael@0 413 double getLocalSidereal();
michael@0 414
michael@0 415 /**
michael@0 416 * Converts local sidereal time to Universal Time.
michael@0 417 *
michael@0 418 * @param lst The Local Sidereal Time, in hours since sidereal midnight
michael@0 419 * on this object's current date.
michael@0 420 *
michael@0 421 * @return The corresponding Universal Time, in milliseconds since
michael@0 422 * 1 Jan 1970, GMT.
michael@0 423 */
michael@0 424 //private:
michael@0 425 double lstToUT(double lst);
michael@0 426
michael@0 427 /**
michael@0 428 *
michael@0 429 * Convert from ecliptic to equatorial coordinates.
michael@0 430 *
michael@0 431 * @param ecliptic The ecliptic
michael@0 432 * @param result Fillin result
michael@0 433 * @return reference to result
michael@0 434 */
michael@0 435 Equatorial& eclipticToEquatorial(Equatorial& result, const Ecliptic& ecliptic);
michael@0 436
michael@0 437 /**
michael@0 438 * Convert from ecliptic to equatorial coordinates.
michael@0 439 *
michael@0 440 * @param eclipLong The ecliptic longitude
michael@0 441 * @param eclipLat The ecliptic latitude
michael@0 442 *
michael@0 443 * @return The corresponding point in equatorial coordinates.
michael@0 444 * @internal
michael@0 445 */
michael@0 446 Equatorial& eclipticToEquatorial(Equatorial& result, double eclipLong, double eclipLat);
michael@0 447
michael@0 448 /**
michael@0 449 * Convert from ecliptic longitude to equatorial coordinates.
michael@0 450 *
michael@0 451 * @param eclipLong The ecliptic longitude
michael@0 452 *
michael@0 453 * @return The corresponding point in equatorial coordinates.
michael@0 454 * @internal
michael@0 455 */
michael@0 456 Equatorial& eclipticToEquatorial(Equatorial& result, double eclipLong) ;
michael@0 457
michael@0 458 /**
michael@0 459 * @internal
michael@0 460 */
michael@0 461 Horizon& eclipticToHorizon(Horizon& result, double eclipLong) ;
michael@0 462
michael@0 463 //-------------------------------------------------------------------------
michael@0 464 // The Sun
michael@0 465 //-------------------------------------------------------------------------
michael@0 466
michael@0 467 /**
michael@0 468 * The longitude of the sun at the time specified by this object.
michael@0 469 * The longitude is measured in radians along the ecliptic
michael@0 470 * from the "first point of Aries," the point at which the ecliptic
michael@0 471 * crosses the earth's equatorial plane at the vernal equinox.
michael@0 472 * <p>
michael@0 473 * Currently, this method uses an approximation of the two-body Kepler's
michael@0 474 * equation for the earth and the sun. It does not take into account the
michael@0 475 * perturbations caused by the other planets, the moon, etc.
michael@0 476 * @internal
michael@0 477 */
michael@0 478 double getSunLongitude();
michael@0 479
michael@0 480 /**
michael@0 481 * TODO Make this public when the entire class is package-private.
michael@0 482 */
michael@0 483 /*public*/ void getSunLongitude(double julianDay, double &longitude, double &meanAnomaly);
michael@0 484
michael@0 485 /**
michael@0 486 * The position of the sun at this object's current date and time,
michael@0 487 * in equatorial coordinates.
michael@0 488 * @param result fillin for the result
michael@0 489 * @internal
michael@0 490 */
michael@0 491 Equatorial& getSunPosition(Equatorial& result);
michael@0 492
michael@0 493 public:
michael@0 494 /**
michael@0 495 * Constant representing the vernal equinox.
michael@0 496 * For use with {@link #getSunTime getSunTime}.
michael@0 497 * Note: In this case, "vernal" refers to the northern hemisphere's seasons.
michael@0 498 * @internal
michael@0 499 */
michael@0 500 // static double VERNAL_EQUINOX();
michael@0 501
michael@0 502 /**
michael@0 503 * Constant representing the summer solstice.
michael@0 504 * For use with {@link #getSunTime getSunTime}.
michael@0 505 * Note: In this case, "summer" refers to the northern hemisphere's seasons.
michael@0 506 * @internal
michael@0 507 */
michael@0 508 static double SUMMER_SOLSTICE();
michael@0 509
michael@0 510 /**
michael@0 511 * Constant representing the autumnal equinox.
michael@0 512 * For use with {@link #getSunTime getSunTime}.
michael@0 513 * Note: In this case, "autumn" refers to the northern hemisphere's seasons.
michael@0 514 * @internal
michael@0 515 */
michael@0 516 // static double AUTUMN_EQUINOX();
michael@0 517
michael@0 518 /**
michael@0 519 * Constant representing the winter solstice.
michael@0 520 * For use with {@link #getSunTime getSunTime}.
michael@0 521 * Note: In this case, "winter" refers to the northern hemisphere's seasons.
michael@0 522 * @internal
michael@0 523 */
michael@0 524 static double WINTER_SOLSTICE();
michael@0 525
michael@0 526 /**
michael@0 527 * Find the next time at which the sun's ecliptic longitude will have
michael@0 528 * the desired value.
michael@0 529 * @internal
michael@0 530 */
michael@0 531 UDate getSunTime(double desired, UBool next);
michael@0 532
michael@0 533 /**
michael@0 534 * Returns the time (GMT) of sunrise or sunset on the local date to which
michael@0 535 * this calendar is currently set.
michael@0 536 *
michael@0 537 * NOTE: This method only works well if this object is set to a
michael@0 538 * time near local noon. Because of variations between the local
michael@0 539 * official time zone and the geographic longitude, the
michael@0 540 * computation can flop over into an adjacent day if this object
michael@0 541 * is set to a time near local midnight.
michael@0 542 *
michael@0 543 * @internal
michael@0 544 */
michael@0 545 UDate getSunRiseSet(UBool rise);
michael@0 546
michael@0 547 //-------------------------------------------------------------------------
michael@0 548 // The Moon
michael@0 549 //-------------------------------------------------------------------------
michael@0 550
michael@0 551 /**
michael@0 552 * The position of the moon at the time set on this
michael@0 553 * object, in equatorial coordinates.
michael@0 554 * @internal
michael@0 555 * @return const reference to internal field of calendar astronomer. Do not use outside of the lifetime of this astronomer.
michael@0 556 */
michael@0 557 const Equatorial& getMoonPosition();
michael@0 558
michael@0 559 /**
michael@0 560 * The "age" of the moon at the time specified in this object.
michael@0 561 * This is really the angle between the
michael@0 562 * current ecliptic longitudes of the sun and the moon,
michael@0 563 * measured in radians.
michael@0 564 *
michael@0 565 * @see #getMoonPhase
michael@0 566 * @internal
michael@0 567 */
michael@0 568 double getMoonAge();
michael@0 569
michael@0 570 /**
michael@0 571 * Calculate the phase of the moon at the time set in this object.
michael@0 572 * The returned phase is a <code>double</code> in the range
michael@0 573 * <code>0 <= phase < 1</code>, interpreted as follows:
michael@0 574 * <ul>
michael@0 575 * <li>0.00: New moon
michael@0 576 * <li>0.25: First quarter
michael@0 577 * <li>0.50: Full moon
michael@0 578 * <li>0.75: Last quarter
michael@0 579 * </ul>
michael@0 580 *
michael@0 581 * @see #getMoonAge
michael@0 582 * @internal
michael@0 583 */
michael@0 584 double getMoonPhase();
michael@0 585
michael@0 586 class U_I18N_API MoonAge : public UMemory {
michael@0 587 public:
michael@0 588 MoonAge(double l)
michael@0 589 : value(l) { }
michael@0 590 void set(double l) { value = l; }
michael@0 591 double value;
michael@0 592 };
michael@0 593
michael@0 594 /**
michael@0 595 * Constant representing a new moon.
michael@0 596 * For use with {@link #getMoonTime getMoonTime}
michael@0 597 * @internal
michael@0 598 */
michael@0 599 static const MoonAge NEW_MOON();
michael@0 600
michael@0 601 /**
michael@0 602 * Constant representing the moon's first quarter.
michael@0 603 * For use with {@link #getMoonTime getMoonTime}
michael@0 604 * @internal
michael@0 605 */
michael@0 606 // static const MoonAge FIRST_QUARTER();
michael@0 607
michael@0 608 /**
michael@0 609 * Constant representing a full moon.
michael@0 610 * For use with {@link #getMoonTime getMoonTime}
michael@0 611 * @internal
michael@0 612 */
michael@0 613 static const MoonAge FULL_MOON();
michael@0 614
michael@0 615 /**
michael@0 616 * Constant representing the moon's last quarter.
michael@0 617 * For use with {@link #getMoonTime getMoonTime}
michael@0 618 * @internal
michael@0 619 */
michael@0 620 // static const MoonAge LAST_QUARTER();
michael@0 621
michael@0 622 /**
michael@0 623 * Find the next or previous time at which the Moon's ecliptic
michael@0 624 * longitude will have the desired value.
michael@0 625 * <p>
michael@0 626 * @param desired The desired longitude.
michael@0 627 * @param next <tt>true</tt> if the next occurrance of the phase
michael@0 628 * is desired, <tt>false</tt> for the previous occurrance.
michael@0 629 * @internal
michael@0 630 */
michael@0 631 UDate getMoonTime(double desired, UBool next);
michael@0 632 UDate getMoonTime(const MoonAge& desired, UBool next);
michael@0 633
michael@0 634 /**
michael@0 635 * Returns the time (GMT) of sunrise or sunset on the local date to which
michael@0 636 * this calendar is currently set.
michael@0 637 * @internal
michael@0 638 */
michael@0 639 UDate getMoonRiseSet(UBool rise);
michael@0 640
michael@0 641 //-------------------------------------------------------------------------
michael@0 642 // Interpolation methods for finding the time at which a given event occurs
michael@0 643 //-------------------------------------------------------------------------
michael@0 644
michael@0 645 // private
michael@0 646 class AngleFunc : public UMemory {
michael@0 647 public:
michael@0 648 virtual double eval(CalendarAstronomer&) = 0;
michael@0 649 virtual ~AngleFunc();
michael@0 650 };
michael@0 651 friend class AngleFunc;
michael@0 652
michael@0 653 UDate timeOfAngle(AngleFunc& func, double desired,
michael@0 654 double periodDays, double epsilon, UBool next);
michael@0 655
michael@0 656 class CoordFunc : public UMemory {
michael@0 657 public:
michael@0 658 virtual void eval(Equatorial& result, CalendarAstronomer&) = 0;
michael@0 659 virtual ~CoordFunc();
michael@0 660 };
michael@0 661 friend class CoordFunc;
michael@0 662
michael@0 663 double riseOrSet(CoordFunc& func, UBool rise,
michael@0 664 double diameter, double refraction,
michael@0 665 double epsilon);
michael@0 666
michael@0 667 //-------------------------------------------------------------------------
michael@0 668 // Other utility methods
michael@0 669 //-------------------------------------------------------------------------
michael@0 670 private:
michael@0 671
michael@0 672 /**
michael@0 673 * Return the obliquity of the ecliptic (the angle between the ecliptic
michael@0 674 * and the earth's equator) at the current time. This varies due to
michael@0 675 * the precession of the earth's axis.
michael@0 676 *
michael@0 677 * @return the obliquity of the ecliptic relative to the equator,
michael@0 678 * measured in radians.
michael@0 679 */
michael@0 680 double eclipticObliquity();
michael@0 681
michael@0 682 //-------------------------------------------------------------------------
michael@0 683 // Private data
michael@0 684 //-------------------------------------------------------------------------
michael@0 685 private:
michael@0 686 /**
michael@0 687 * Current time in milliseconds since 1/1/1970 AD
michael@0 688 * @see java.util.Date#getTime
michael@0 689 */
michael@0 690 UDate fTime;
michael@0 691
michael@0 692 /* These aren't used yet, but they'll be needed for sunset calculations
michael@0 693 * and equatorial to horizon coordinate conversions
michael@0 694 */
michael@0 695 double fLongitude;
michael@0 696 double fLatitude;
michael@0 697 double fGmtOffset;
michael@0 698
michael@0 699 //
michael@0 700 // The following fields are used to cache calculated results for improved
michael@0 701 // performance. These values all depend on the current time setting
michael@0 702 // of this object, so the clearCache method is provided.
michael@0 703 //
michael@0 704
michael@0 705 double julianDay;
michael@0 706 double julianCentury;
michael@0 707 double sunLongitude;
michael@0 708 double meanAnomalySun;
michael@0 709 double moonLongitude;
michael@0 710 double moonEclipLong;
michael@0 711 double meanAnomalyMoon;
michael@0 712 double eclipObliquity;
michael@0 713 double siderealT0;
michael@0 714 double siderealTime;
michael@0 715
michael@0 716 void clearCache();
michael@0 717
michael@0 718 Equatorial moonPosition;
michael@0 719 UBool moonPositionSet;
michael@0 720
michael@0 721 /**
michael@0 722 * @internal
michael@0 723 */
michael@0 724 // UDate local(UDate localMillis);
michael@0 725 };
michael@0 726
michael@0 727 U_NAMESPACE_END
michael@0 728
michael@0 729 struct UHashtable;
michael@0 730
michael@0 731 U_NAMESPACE_BEGIN
michael@0 732
michael@0 733 /**
michael@0 734 * Cache of month -> julian day
michael@0 735 * @internal
michael@0 736 */
michael@0 737 class CalendarCache : public UMemory {
michael@0 738 public:
michael@0 739 static int32_t get(CalendarCache** cache, int32_t key, UErrorCode &status);
michael@0 740 static void put(CalendarCache** cache, int32_t key, int32_t value, UErrorCode &status);
michael@0 741 virtual ~CalendarCache();
michael@0 742 private:
michael@0 743 CalendarCache(int32_t size, UErrorCode& status);
michael@0 744 static void createCache(CalendarCache** cache, UErrorCode& status);
michael@0 745 /**
michael@0 746 * not implemented
michael@0 747 */
michael@0 748 CalendarCache();
michael@0 749 UHashtable *fTable;
michael@0 750 };
michael@0 751
michael@0 752 U_NAMESPACE_END
michael@0 753
michael@0 754 #endif
michael@0 755 #endif

mercurial