mirror of
https://github.com/cosinekitty/astronomy.git
synced 2026-05-19 06:17:03 -04:00
Fixed #187 - Seasons() failed for distant years.
For years before 1582 or years after 3668, the Seasons functions
were unable to find many equinoxes and/or solstices.
The problem was that over time, the Earth's axis precesses
enough that the calendar dates of these events drifts outside
the fixed search ranges I had provided for them.
I expanded the search ranges so all season changes can be found
for a much wider range of years, as verified by unit tests:
C/C++: -2000..9999
C#: 1..9999
JavaScript: -2000..9999
Python: 1..9999
Kotlin: 1..9999
Note: C#, Python, and Kotlin currently do not allow
years values below +1. In fact, I discovered we were not
noticing when an invalid year was passed into the Kotlin code.
I updated that code to throw an exception when the year does
not match what was expected. It is disturbing that the
GregorianCalendar class silently ignores invalid years!
Constricted the search tolerance from 1 second to 0.01
seconds for the seasons search, to ensure more consistent
behavior.
Fixed a bug in the Kotlin search() function's
quadratic interpolation that was causing the convergence
to be slower than it should have been.
This commit is contained in:
@@ -5642,7 +5642,7 @@ def SearchSunLongitude(targetLon, startTime, limitDays):
|
||||
Time or `None`
|
||||
"""
|
||||
t2 = startTime.AddDays(limitDays)
|
||||
return Search(_sun_offset, targetLon, startTime, t2, 1.0)
|
||||
return Search(_sun_offset, targetLon, startTime, t2, 0.01)
|
||||
|
||||
def MoonPhase(time):
|
||||
"""Returns the Moon's phase as an angle from 0 to 360 degrees.
|
||||
@@ -6444,7 +6444,7 @@ class SeasonInfo:
|
||||
|
||||
def _FindSeasonChange(targetLon, year, month, day):
|
||||
startTime = Time.Make(year, month, day, 0, 0, 0)
|
||||
time = SearchSunLongitude(targetLon, startTime, 4.0)
|
||||
time = SearchSunLongitude(targetLon, startTime, 20.0)
|
||||
if time is None:
|
||||
# We should always be able to find a season change.
|
||||
raise InternalError()
|
||||
@@ -6486,10 +6486,17 @@ def Seasons(year):
|
||||
-------
|
||||
SeasonInfo
|
||||
"""
|
||||
mar_equinox = _FindSeasonChange(0, year, 3, 19)
|
||||
jun_solstice = _FindSeasonChange(90, year, 6, 19)
|
||||
sep_equinox = _FindSeasonChange(180, year, 9, 21)
|
||||
dec_solstice = _FindSeasonChange(270, year, 12, 20)
|
||||
# https://github.com/cosinekitty/astronomy/issues/187
|
||||
# Solstices and equinoxes drift over long spans of time,
|
||||
# due to precession of the Earth's axis.
|
||||
# Therefore, we have to search a wider range of time than
|
||||
# one might expect. It turns out this has very little
|
||||
# effect on efficiency, thanks to the quick convergence
|
||||
# of quadratic interpolation inside the `Search` function.
|
||||
mar_equinox = _FindSeasonChange( 0, year, 3, 10)
|
||||
jun_solstice = _FindSeasonChange( 90, year, 6, 10)
|
||||
sep_equinox = _FindSeasonChange(180, year, 9, 10)
|
||||
dec_solstice = _FindSeasonChange(270, year, 12, 10)
|
||||
return SeasonInfo(mar_equinox, jun_solstice, sep_equinox, dec_solstice)
|
||||
|
||||
def _MoonDistance(time):
|
||||
|
||||
Reference in New Issue
Block a user