Commit Graph

1235 Commits

Author SHA1 Message Date
Don Cross
3f71bfeb63 Kotlin: convert Observer to StateVector.
Added `Observer.toStateVector` and `Observer.toVector` for converting
an observer's geographic location to position and velocity vectors
relative to the Earth's center.

Reworked the C unit test to output a text file that can be used
as reference, to make sure the Kotlin output matches.
2022-04-09 17:00:36 -04:00
Ebrahim Byagowi
a4e662dc32 kotlin: Remove Kt suffix from file top level object 2022-04-09 04:36:38 +04:30
Ebrahim Byagowi
086a1f602d kotlin: Turn calculation functions to top level declaration 2022-04-09 03:59:12 +04:30
Don Cross
b754925e80 Merge pull request #192 from ebraminio/kotlin-sources
kotlin: Include sources artifact in the release
2022-04-08 18:49:26 -04:00
Don Cross
0d24433db3 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.
2022-04-08 16:51:09 -04:00
Ebrahim Byagowi
89a711f420 kotlin: Include sources artifact in the release 2022-04-08 17:13:11 +04:30
Don Cross
37d15e5f6a Kotlin: altitude search
Added Astronomy.searchAltitude, which enables more generic
searches for altitude events. The most common use for these
are finding civil, nautical, and astronomical twilight times.
2022-04-07 15:12:08 -04:00
Don Cross
1d491118e9 Kotlin: implemented search for rise/set, hour angle.
Implemented the following Kotlin functions:

    Astronomy.searchHourAngle
    Astronomy.searchRiseSet

The Kotlin code can now search for rise/set
times for a given Earthbound observer for the
Sun, Moon, or any planet.

It can also search for times when a given body
reaches a desired hour angle. This has its own
value (for example, culmination), but is also
used to assist finding time brackets that bound
rise/set events.

Added special case exception type:
EarthNotAllowedException.
This follows the pattern of the other languages,
and makes diagnosing a violation easier than
the more generic InvalidBodyException.

Minor simplifications to the C# function
Astronomy.InternalSearchAltitude.

Improved the comments for the C# unit test
function RiseSetTest. They make the algorithm
easier to understand.
2022-04-07 11:56:28 -04:00
Don Cross
94c7884f11 Kotlin: added moon phase and search functions.
Added the following Kotlin functions:

    equatorialToEcliptic
    pairLongitude
    moonPhase
    searchMoonPhase
    searchMoonQuarter
    nextMoonQuarter

Discovered I could tighten the tolerance for the moon phase
unit tests from 120 seconds to 90 seconds and they still pass.
2022-04-05 17:33:19 -04:00
Don Cross
fe47dad4a4 Merge branch 'master' into kotlin
Merged some C# fixes from the master branch.
2022-04-05 13:36:58 -04:00
Don Cross
94eabbd4a9 C#: Adding missing checks for unexpected search failures.
There were a few more places where C# code called
Search() but did not check for a search failure.
Throw InternalError exceptions if these ever occur,
because these particular searches should always succeed.
2022-04-05 13:22:50 -04:00
Don Cross
d7e86fae52 C#: Search cleanup, add InternalError exception.
Added an InternalError class to explicitly indicate
that an exception occurs due to an internal assertion
failure inside Astronomy Engine. Any InternalError
should be considered a bug in Astronomy Engine, not
a bug in calling code.

Upon reviewing the code for searching moon phases,
I discovered that there was inconsistent behavior
in SearchMoonPhase. It was sometimes returning null,
other times throwing an exception. Because the caller
passes in `limitDays`, it makes sense to simply
return `null` in any case where the search fails.
This is to support callers that intentionally want
to find whether or not a moon phase occurs in a given
small window of time.

Updated internal callers of SearchMoonPhase to throw
an InternalError when they know they should always
find an event.

Internal function FindSeasonChange did not check to
make sure SearchSunLongitude succeeded. There is no
known case where this failure happens, but if it did,
a null AstroTime would have been stored in SeasonsInfo.
It is better to fail early with an explicit InternalError.

Other miscellaneous C# code cleanup.

In the Python code, I found a couple of `raise Error`
that needed to be changed to `raise InternalError`.
2022-04-05 12:30:13 -04:00
Don Cross
c7bc1a1fe0 Kotlin: fixed formatting of @return doc.
Dokka preserves leading whitespace in the text after
`@return` comments. This causes these fields to render
as preformatted text. Removed the leading whitespace so
this text is rendered as normal markdown.
2022-04-04 12:21:08 -04:00
Don Cross
69bc2e60fc Kotlin: Fixed documentation for return values.
I was using `@returns` in the documentation comments
in Kotlin code, instead of `@return`. Thanks to @ebraminio
for pointing this out.
2022-04-03 20:23:32 -04:00
Don Cross
10bb3f30de Kotlin: implemented seasons search.
Implemented the following related functions in Kotlin:

    sunPosition
    searchSunLongitude
    seasons

C#: fail Astronomy.Seasons with an exception if any of the
equinox/solstice searches fail. If this ever happens, it is
an internal error. It should not be the burden of the caller
to check for nulls!  Fixed mistake in documentation for
searchSunLongitude.
2022-04-03 20:02:11 -04:00
Don Cross
075a80fde8 Kotlin: Implemented Astronomy.search.
Implemented the low-level search function that will be used
to implement all the special-purpose search functions to come.

Added missing documentation to class NodeEventInfo members.

Minor cleanup in the C# function `Astronomy.Search`:
- removed an unused output parameter.
- deleted confusing sentence in documentation.
2022-04-03 10:37:12 -04:00
Don Cross
9d6294d7fe Miscellaneous documentation fixes.
While working on the Kotlin implementation, I have
found a few documentation mistakes in the other language
implementations. These have been accumulating in the
`kotlin` branch. I migrated these changes back into
the released code for now, because I don't want to wait
until Kotlin is ready.
2022-04-02 16:52:54 -04:00
Don Cross
6ea35232d8 Updated C# readme based on changes in C# docstring. 2022-04-02 15:28:05 -04:00
Don Cross
e879a67be7 Kotlin: Added constellation function. 2022-04-02 15:17:14 -04:00
Don Cross
04e7102f76 Kotlin: rotationEqjGal, rotationGalEqj. 2022-04-01 19:59:03 -04:00
Don Cross
9b11c44b9e Kotlin: rotationEclHor, rotationHorEcl. 2022-04-01 19:44:33 -04:00
Don Cross
a7e667309d Kotlin: rotationEqdEcl, rotationEclEqd. 2022-04-01 19:34:26 -04:00
Don Cross
3c2f8c0cc9 Kotlin: rotationEqjHor, rotationHorEqj.
Added two more rotation functions.

Corrected a typo in the documentation for Rotation_HOR_EQJ
in the other 4 languages.
2022-04-01 19:19:24 -04:00
Don Cross
2ee5f6f8f5 Kotlin: rotationEqdHor, rotationHorEqd.
Added two more of the rotation functions.
This is the pair for converting between of-date equatorial
coordinates and an observer's horizontal system.
2022-04-01 18:52:00 -04:00
Don Cross
cf38342f69 Kotlin: implemented rotationEqdEqj. 2022-04-01 18:27:50 -04:00
Don Cross
aeb6e90028 Kotlin: starting to add rotation functions.
Starting to add the functions that create rotation
matrices to convert from one orientation to another.
Here are the ones implemented in this commit:

    rotationEqjEcl
    rotationEclEqj
    rotationEqjEqd

Also starting to add missing documentation to
resolve Dokka warnings.
2022-04-01 18:12:21 -04:00
Don Cross
12ae8291a2 Merge branch 'master' into kotlin
Bringing over Python fixes:
- Better string representations of classes.
- A few documentation fixes.
2022-03-31 23:06:58 -04:00
Don Cross
608a7a8dca Fixed #184 - repr for Python classes
Defined consistent __repr__ methods for
Astronomy Engine Python classes.
Each string representation is reversible:

eval(repr(x)) -> x

The main goal is to facilitate interactive
debugging and experimentation for developers
working directly in the Python interpreter.

Fixed documentation mistakes in the following classes:
    IlluminationInfo
    LunarEclipseInfo
2022-03-31 22:47:59 -04:00
Don Cross
41be8a2b6b Kotlin: Fixed bug calculating horizontal coordinates.
The `horizon` function was taking the sine and cosine
of the right ascension, but treating it as degrees.
This was wrong because right ascension is in sidereal hours.
Fix: multiply hours by 15 to get degrees.

Keeping the unit test that confirmed this bug.

Added comparison of C and Kotlin output to `diffcalc`
and `diffcalc.bat`. This test now passes on Linux.
This is a big milestone!
2022-03-31 14:49:35 -04:00
Don Cross
fe1cba065b Kotlin: Fixed bug in Pluto gravity simulator.
The function getPlutoSegment had a bug simulating gravity
in the forward direction. It was creating an array `seg`
that was one item too long: 202 instead of 201 elements.
This caused states from inconsistent time steps to be mixed.

I discovered this via the `diffcalc` script.
I added a new unit test that quickly reproduced this issue.
This was helpful for debugging and finding the problem.
I'm keeping the new unit test, in case it helps detect
breakage in the future.
2022-03-31 13:28:10 -04:00
Don Cross
503e31b0d9 Kotlin code style: remove semicolons, underscores. 2022-03-31 08:28:53 -04:00
Don Cross
397c259bc6 Kotlin: Jupiter's moons.
Implemented Kotlin functions and code generator
for calculating the state vectors of Jupiter's
largest 4 moons.

Added cautionary comments about needing to correct
Jupiter's moons for light travel time.

This is the first pass to get everything needed
for the AstroCheck tests. I tried comparing
C output to Kotlin output, and there are some
serious problems to debug:

    $ ./ctest diff 2.8e-16 temp/{c,k}_check.txt
    First  file: temp/c_check.txt
    Second file: temp/k_check.txt
    Tolerance = 2.800e-16

                lnum                 a_value                 b_value     factor       diff  name
    FAIL      137746  4.2937184148112564e+01  4.2944101081740065e+01    0.03364  2.327e-04  helio_x
    FAIL      373510  1.4197190315274938e+01  1.4193716564905307e+01    0.03364  1.168e-04  helio_y
    FAIL      137746 -6.5897675150466091e+00 -6.5929481589493522e+00    0.03364  1.070e-04  helio_z
    FAIL       59150  1.8035183339348251e+01  1.8035909197904104e+01    0.01730  1.255e-05  sky_j2000_ra
    FAIL      137747 -8.1222057639092533e+00 -8.1250990689970894e+00    0.00556  1.607e-05  sky_j2000_dec
    FAIL      137747  4.8436159305823310e+01  4.8441487614058218e+01    0.03481  1.855e-04  sky_j2000_dist
    FAIL      322846  8.7596368704201495e+01  2.6760770774700188e+02    0.00278  4.995e-01  sky_hor_az
    FAIL      405828 -6.5075824596574279e+01  5.6922941329250996e+01    0.00556  6.778e-01  sky_hor_alt
      OK       92717  4.1268347083494783e-03  4.1268347083494774e-03  223.21429  1.936e-16  jm_x
      OK       45091 -8.0149190392649894e-03 -8.0149190392649929e-03   79.42812  2.756e-16  jm_y
      OK      135377  1.5470777280065808e-03  1.5470777280065804e-03  223.21429  9.680e-17  jm_z
      OK      216836  4.5725777238332412e-03  4.5725777238332394e-03  126.58228  2.196e-16  jm_vx
      OK      351647  5.1351566793199944e-03  5.1351566793199962e-03  126.58228  2.196e-16  jm_vy
      OK      351647  2.5217607180929289e-03  2.5217607180929298e-03  126.58228  1.098e-16  jm_vz

    Score = 6.778e-01
    ctest(Diff): EXCEEDED ERROR TOLERANCE.

So I'm checking this in as work-in-progress.
2022-03-30 22:49:22 -04:00
Don Cross
74a1274c85 Kotlin: Implemented functions: geoVector, equator, horizon.
Implemented more of the core functions needed for
the AstroCheck tests. Most of AstroCheck is now implemented,
except for the JupiterMoons tests.

Code cleanup thanks to @ebraminio:
- Use `when { }` syntax.
- Renamed `IllumInfo` to `IlluminationInfo`.
- Other minor naming fixes.

Configured Dokka to warn about undocumented symbols.

We also configured Dokka to omit internal symbols, including
inside enums, but that does not work, despite this bug
being marked fixed in dokka:

https://github.com/Kotlin/dokka/issues/1802

We suspect they didn't really fix the bug, and that
there is a bug in their test.
2022-03-30 20:42:24 -04:00
Don Cross
f2d19c4dcc Fixed #179: Fixed Kotlin hyperlinks.
Thanks to @ebraminio for telling me how to fix the
Kotlin docstring hyperlinks. Symbols just need to be put
in brackets, not prefixed by a pound sign.
2022-03-30 14:48:20 -04:00
Don Cross
832fec5ce7 Kotlin: simplified per-body mass product and VSOP87 models.
Thanks to @ebraminio, I learned that Kotlin enum classes
allow the members to contain data properties. This greatly
simplifies code so that I no longer need such verbose
`when (body)` statements.

I also understand Kotlin enums better, and I realized
there is no need for `Body.Invalid`, because the compiler
simply does not allow invalid enum values to exist.
In any future hypothetical situation where I want to
represent an optional `Body` value, I can use the nullable type `Body?`.
2022-03-30 14:22:22 -04:00
Don Cross
e4a186aa09 Kotlin: heliocentric state vectors.
Added Astronomy.geoMoonState and Astronomy.helioState functions.
These allow calculating the position and velocity of any
solar system body.

Added sanity checks for state vectors in the unit tests.
2022-03-30 12:53:23 -04:00
Don Cross
1eeea5b46e Kotlin: calculate Solar System Barycenter position. 2022-03-29 20:54:17 -04:00
Don Cross
9d38dac2f1 Kotlin: Gravity simulator, Pluto calculation.
Added calculation of heliocentric and barycentric
state vectors for Pluto. This is done using
a gravity simulator that treats Pluto as a negligible
mass that is affected by the major masses of the
Solar System: Sun, Jupiter, Saturn, Uranus, Neptune.

Updated the code generator to write the Kotlin
version of the Pluto state table, a lookup table
of known-correct state vectors of Pluto at long
intervals, derived from the TOP2013 model.

The gravity simulator interpolates state vectors
of Pluto between these known-correct states.

Minor code style cleanup in the Kotlin source.

Fixed a possible thread-safety issue in the C# code.
2022-03-29 19:22:40 -04:00
Don Cross
044ecfb774 Kotlin: VSOP87 position, velocity vectors.
Implemented the VSOP87 calculation functions for
heliocentric position vectors, heliocentric velocity vectors,
and heliocentric distances.
Implemented Astronomy.helioVector for everything except Pluto and SSB.

Corrected small errors in C# documentation.
2022-03-28 12:33:01 -04:00
Don Cross
2d5ef05536 Kotlin: implemented geocentric Moon.
Implemented the Montenbruck/Pfleger version of the NAO1954
geocentric Moon model in Kotlin.

In the process, code review helped simplify parts of the C# code.
I may want to go back and see if I can simplify the CalcMoon
code in the other languages too.
2022-03-27 20:39:43 -04:00
Don Cross
490b5dee5c Kotlin: Generating VSOP87 model source code.
Added code generator for VSOP87 major planet models in Kotlin.
Added a lookup function for VSOP87 models to Kotlin template.
Moved IAU2000b delcaration outside class Astronomy.
2022-03-27 06:02:21 -04:00
Don Cross
a96c8358b9 Kotlin: Added Astronomy.rotationAxis().
Added the rotationAxis, which calculates dynamic orientation
of planet, Sun, and Moon rotation axes. Added the first
unit test that verifies against JPL Horizons data.

Eliminated more redundant time parameters in precession functions.

More cleanup of C# code: I realized the private function
vector2radec was redundant with the public function EquatorFromVector.
Deleted vector2radec.
2022-03-26 20:42:14 -04:00
Don Cross
bec202ba37 Kotlin: added nutation matrix/vector functions.
Added functions for generating rotation matrices,
rotating position vectors, and rotating state vectors,
for the Earth's axial nutation.

Simplified gyration functions in C#:
it turns out the `time` parameters were redundant,
because time is included in the `t` field of the vector
passed in. I reworked the C# code to eliminate those time
parameters.

The Kotlin code follows suit.
2022-03-26 13:40:52 -04:00
Don Cross
62405be175 Kotlin: Convert observer <==> state vector.
Implemented the functions `terra` and `inverseTerra`.

`terra` converts geographic coordinates and time into
a geocentric state vector.

`inverseTerra` converts a position vector and time
into geographic coordinates.

I realized the C# function `inverse_terra` could be
simplified. It does not need to be passed a separate
time, because the sidereal time can be derived
from, or has already been stored inside, the vector's
time field `ovec.t`.

There were a couple of other minor cleanups to the C# code.
2022-03-26 11:51:36 -04:00
Don Cross
9b4223193b Kotlin: sidereal time
Implemented Astronomy.siderealTime() in Kotlin.

Updated all languages' unit tests for sidereal time
to verify exact conformity between them, rather than
to an externally derived value. I wanted to make
sure all languages, including Kotlin, are calculating
the exact same value.

I don't need an external authoritative test for
sidereal time, because it will be indirectly tested
through its involvement in thousands of other calculations
that depend on it. I just need a quick sanity check
before implementing those other things that depend on it.
2022-03-26 02:07:15 -04:00
Don Cross
9772ea9f47 Kotlin: starting precession and nutation.
Implemented the iau2000b nutation formula.
Implemented calculation of the precession
rotation matrix.

This is the very first use of a code generator
macro for the Kotlin code.  I am going to try
keeping all these macros toward the bottom
of the source tepmlate, so that as I look at
line numbers for compiler errors, they will match
between the target code and the template code.

I may go back and rework the other languges to
do this also. I'm not sure why I didn't think
of this before!
2022-03-25 21:00:11 -04:00
Don Cross
6cb7ab7cce Kotlin: added constants and massProduct function. 2022-03-25 18:28:51 -04:00
Don Cross
8c923d49d6 Kotlin: added more data types.
Ported the following types to the Kotlin code:

    GlobalSolarEclipseInfo
    EclipseEvent
    LocalSolarEclipseInfo
    TransitInfo
    ShadowInfo
    IllumInfo
    AxisInfo
    NodeEventKind
    NodeEventInfo

Made some wording fixes in the documentation for the
other languages.
2022-03-25 15:52:27 -04:00
Don Cross
29472cded9 Kotlin code style.
Bringing Kotlin source code into closer alignment with
the style guide at:

https://kotlinlang.org/docs/coding-conventions.html
2022-03-25 14:22:40 -04:00
Don Cross
bdf49c4487 Kotlin: Treat warnings as errors. Fixed warnings. 2022-03-24 21:19:44 -04:00