Commit Graph

207 Commits

Author SHA1 Message Date
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
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
Don Cross
f0c4eb05db Kotlin: Ported some more data types.
Ecliptic
Topocentric
SeasonsInfo
MoonQuarterInfo
LibrationInfo
HourAngleInfo
ElongationInfo
ApsisKind
ApsisInfo
EclipseKind
LunarEclipseInfo
2022-03-24 20:17:14 -04:00
Don Cross
a30c879262 Remove dokka step from 'rebuild' helper scripts.
During development, when I just want a quick build/test cycle,
I don't need to waste time regenerating documentation.
So I removed the dokka steps from the 'rebuild' scripts.
The dokka steps are still executed when running the full
build process before pushing to GitHub.
2022-03-24 10:32:31 -04:00
Don Cross
fa499d75cc Fixed broken unit tests due to stale Dokka output.
I didn't realize Dokka doesn't clean up its output directory
before writing documentation files. This caused stale documentation
to still exist from previous builds. The result was a failed
unit test because the generated documentation did not match
what was checked into git.

In general, I want to make sure that builds I run on my development
system exactly match what GitHub Actions does on its cloud platform.
So before running the `gradlew` build step, I delete the entire
directory source/kotlin/build. This directory is always absent
on GitHub Actions, which makes my local build better match the
remote build.
2022-03-24 09:47:22 -04:00
Don Cross
e68ba361c3 Kotlin: minor code cleanup. 2022-03-23 20:53:31 -04:00
Don Cross
53c8d7145a Publish generated Kotlin documentation to GitHub.
Merge a custom Markdown prefix with documentation
generated by dokka from Kotlin source code into
the published GitHub page. See the new script:

    generate/kotlindoc/format_kotlin_doc.py

The result is not yet quite what I want, but it
is much better than nothing.

Things to improve:

The `object Astronomy` link should not be hidden
in the middle of the other types. It should be
expanded and promoted to the top level.
2022-03-23 20:36:00 -04:00
Don Cross
40e0fb7b4f Kotlin: Another batch of functions ported.
Converting between radians and degrees.
Clamping angles to a desired range of degrees.
Converting between vector, spherical, horizontal.
Refraction and inverse refraction.
2022-03-23 17:21:37 -04:00
Don Cross
94aba0240a Kotlin: rotate a state vector.
Bootstrapped the function for rotating a vector
to rotate a state vector (position and velocity combined).
2022-03-23 14:36:42 -04:00
Don Cross
b0929b1b49 Kotlin: added rotation matrix functions and unit tests.
Implemented most of the RotationMatrix functions.
Added unit tests for combining rotation matrices, using a
rotation matrix to rotate a vector, and pivoting a rotation
matrix around its axes.

Replaced AstroVector operator '*' with infix function 'dot',
because it removes ambiguity between vector dot products
and vector cross products.
Later I will add a 'cross' infix function too.

Corrected minor typo in documentation for Python, C, C#, JavaScript.
"trasnform" -> "transform"
2022-03-23 14:25:32 -04:00
Don Cross
9e343aef8a Kotlin: Minor code cleanup.
Moved Astronomy object to bottom of source file.
This object is going to end up with a lot of functions,
so it's best to keep outer classes above it.

Removed unnecessary empty {} after classes.

Replace Array<Array<Double>> with Array<DoubleArray>.
This is more efficient because Array<Double> boxes the numbers
inside it, whereas DoubleArray is unboxed.
2022-03-23 12:31:43 -04:00
Don Cross
79d66bb00b Kotlin: added a few more type definitions.
StateVector
JupiterMoonsInfo
RotationMatrix
Spherical
Observer
EquatorEpoch
Aberration
Refraction
Direction
Visibility
Equatorial
2022-03-22 20:52:07 -04:00
Don Cross
8a9e30a888 Kotlin: Added AstroVector class. 2022-03-22 17:07:02 -04:00
Ebrahim Byagowi
a17456514e kotlin: Use Kotlin test and its asserters
It provides more idiomatic asserters to Kotlin.
2022-03-22 19:30:41 +04:30
Don Cross
887a200ac8 Cleaned up kotlin_language.svg. 2022-03-21 15:24:43 -04:00
Don Cross
6b880894e2 Added Kotlin to supported language list.
The main README.md now includes Kotlin as a supported
language.

Pivoted the table so languages are listed vertically
instead of horizontally, because this fits better on
a screen, especially using the GitHub mobile app.

There is a link to Kotlin demos, but there are no
demos implemented yet.

Likewise, there is a link to Kotlin documentation,
but the generated documentation is not stored in Git yet,
so there is no actual documentation generated from docstrings
in the code yet.
2022-03-21 15:20:55 -04:00
Don Cross
8fd8d7b624 Kotlin AstroTime: millisecond resolution, ISO 8601
Allow floating point values for seconds when initializing
an AstroTime from (year, month, ..., seconds).
AstroTime can now represent date/time to millisecond resolution.

Represent AstroTime strings in ISO 8601 format:
yyyy-mm-ddThh:mm:ss.sssZ

Minor docstring fixes.

Rename target file to 'astronomy.kt'.
2022-03-21 13:28:49 -04:00
Ebrahim Byagowi
f8771922d3 kotlin: Drop .0 where isn't needed 2022-03-21 15:25:29 +03:30
Ebrahim Byagowi
c9f4ce46e7 kotlin: Replace repetitive ifs with when 2022-03-21 15:21:47 +03:30
Ebrahim Byagowi
46e3088dd0 kotlin: Port TerseVector 2022-03-21 14:31:26 +03:30
Ebrahim Byagowi
88b2a38651 kotlin: Move AstroTime primary constructor to top level
This is more idiomatic Kotlin.
2022-03-21 14:11:04 +03:30
Ebrahim Byagowi
a4fc126a08 kotlin: Implement AstroTime.addDays 2022-03-21 13:55:18 +03:30
Ebrahim Byagowi
adf7b7a991 kotlin: Implement AstroTime toString 2022-03-21 13:48:06 +03:30
Ebrahim Byagowi
60e470b9c3 kotlin: Implement AstroTime.fromTerrestrialTime 2022-03-21 12:50:25 +03:30