Commit Graph

2245 Commits

Author SHA1 Message Date
Ebrahim Byagowi
13f6e98866 Kotlin: Use Instant.parse instead a custom date parser
Also fixes the demo which had the same code.
2022-04-30 12:14:46 +04:30
Don Cross
3ca64f1ab2 Kotlin: fixed Java demo test for Windows.
I forgot to update the Windows batch file
for testing Java demo programs. Now it works
and correctly verifies the output of the
Java demo `MoonPhase`.
2022-04-28 21:52:33 -04:00
Don Cross
05684bafdb Kotlin: added Java demo: moonphase.
This is the first substantial demo of using
the Kotlin version of Astronomy Engine from
a Java program.

Structured the README.md so I can keep adding more and
more demos as separate Java class files.
The `demotest` script builds the code and will run
each demo one at a time, verifying each one's output.
2022-04-28 21:04:54 -04:00
Don Cross
79597c2e9c Merge branch 'ebraminio-kotlin' into kotlin 2022-04-28 11:29:42 -04:00
Ebrahim Byagowi
962b9c7c9c kotlin: Revert and use arrayOf directly
Direct use of arrayOf can be a bit more efficient than calling map and toTypedArray.

It could be faster if JupiterMoonsInfo was holding a list but better to use direct
typed array initializer for more efficiency.
2022-04-28 19:10:35 +04:30
Ebrahim Byagowi
abd48a3e2b kotlin: Use hashMapOf instead mutableMapOf
mutableMapOf guarantees order of insertion and hashMapOf don't and
as it doesn't matter here let's use that instead.
2022-04-28 18:58:39 +04:30
Don Cross
5d704f438c Merge branch 'ebraminio-kotlin' into kotlin.
Merged ebraminio's changes, but reverted `sumOf` changes
that caused inaccurate calculations.
2022-04-27 21:19:32 -04:00
Don Cross
462f172e6d Kotlin: restored original series calculations.
Changing series calculations to use `sumOf` caused
test failures for Jupiter's moons, compared to the other
languages. I don't understand why, but it is losing about
5 decimal places of accuracy:

    First  file: temp/c_check.txt
    Second file: temp/k_check.txt
    Tolerance = 6.700e-15

                lnum                 a_value                 b_value     factor       diff  name
      OK       59558 -3.7992709399390907e-04 -3.7992709399390658e-04  411.52263  1.026e-15  helio_x
      OK       70088 -1.2672603312645981e-03 -1.2672603312646005e-03  411.52263  9.816e-16  helio_y
      OK      122819  1.0937502621531685e-04  1.0937502621531790e-04  411.52263  4.294e-16  helio_z
      OK        2427  2.0269124415104024e+01  2.0269124415104031e+01    0.01730  1.229e-16  sky_j2000_ra
      OK       96711 -1.3269907232295576e+01 -1.3269907232295552e+01    0.00556  1.382e-16  sky_j2000_dec
      OK      321094  1.9426425943521761e+00  1.9426425943521755e+00    2.61780  1.744e-15  sky_j2000_dist
      OK      302748  3.5388201408771312e+02  3.5388201408771533e+02    0.00275  6.086e-15  sky_hor_az
      OK      121119 -2.2454039277279009e+01 -2.2454039277279151e+01    0.00556  7.895e-16  sky_hor_alt
    FAIL      462886  3.2838700693197847e-05  3.2838701021405780e-05  354.60993  1.164e-10  jm_x
    FAIL       18898  4.1298198258838197e-05  4.1298197961707834e-05  354.60993  1.054e-10  jm_y
    FAIL       18898  6.5401658638156675e-05  6.5401658496812707e-05  354.60993  5.012e-11  jm_z
    FAIL       18898 -1.9369714715980919e-04 -1.9369714599049137e-04  100.00000  1.169e-10  jm_vx
    FAIL      462886  2.0741129523130840e-04  2.0741129628185288e-04  100.00000  1.051e-10  jm_vy
    FAIL      462886 -7.0200557604537683e-05 -7.0200557103467577e-05  100.00000  5.011e-11  jm_vz

    Score = 1.169e-10
    ctest(Diff): EXCEEDED ERROR TOLERANCE.

Restored the original loop logic and now it is back within tolerance:

    First  file: temp/c_check.txt
    Second file: temp/k_check.txt
    Tolerance = 6.700e-15

                lnum                 a_value                 b_value     factor       diff  name
      OK       59558 -3.7992709399390907e-04 -3.7992709399390658e-04  411.52263  1.026e-15  helio_x
      OK       70088 -1.2672603312645981e-03 -1.2672603312646005e-03  411.52263  9.816e-16  helio_y
      OK      122819  1.0937502621531685e-04  1.0937502621531790e-04  411.52263  4.294e-16  helio_z
      OK        2427  2.0269124415104024e+01  2.0269124415104031e+01    0.01730  1.229e-16  sky_j2000_ra
      OK       96711 -1.3269907232295576e+01 -1.3269907232295552e+01    0.00556  1.382e-16  sky_j2000_dec
      OK      321094  1.9426425943521761e+00  1.9426425943521755e+00    2.61780  1.744e-15  sky_j2000_dist
      OK      302748  3.5388201408771312e+02  3.5388201408771533e+02    0.00275  6.086e-15  sky_hor_az
      OK      121119 -2.2454039277279009e+01 -2.2454039277279151e+01    0.00556  7.895e-16  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.086e-15
2022-04-27 21:18:29 -04:00
Ebrahim Byagowi
7ab343e7d4 kotlin: Avoide code duplication in jupiterMoons by using map 2022-04-28 03:42:01 +04:30
Ebrahim Byagowi
474cffccac kotlin: Use sumOf where possible
As sumOf is inline in Kotlin it supposed to have the same performance.
2022-04-28 02:42:23 +04:30
Ebrahim Byagowi
6789c64343 kotlin: Use idiomatic way to create mutable objects 2022-04-28 01:57:38 +04:30
Ebrahim Byagowi
2fe4c8abf4 kotlin: Use single format instead multiple calls 2022-04-28 01:37:35 +04:30
Ebrahim Byagowi
d2485392c3 kotlin: Use getOrPut to facilitate use of cache 2022-04-28 01:19:36 +04:30
Don Cross
53f5540f09 Kotlin: cleanup of code and documentation.
Used IntelliJ IDEA's linter to perform code cleanup.
There were unused variables, `var` that could be replaced with `val`,
and other minor code style issues.

While doing this, I also discovered that a lot of documentation
links were broken. The fix is to stop intenting the text after
a `@param`.
2022-04-27 14:04:42 -04:00
Don Cross
b93719146b Set version numbers to 2.1.0.
In anticipation of releasing the Kotlin version,
I set the version numbers for the following to 2.1.0:

    Kotlin
    Node.js / npm
    Python / pip

The intention is to keep matching releases of
Astronomy Engine at a common version number.
2022-04-26 15:58:27 -04:00
Don Cross
565bac127a Kotlin docs: link to body enum values.
When documentation refers to a Body value, e.g. Body.Earth,
link to its information page. I'm not sure this is super helpful,
but it is an attempt to provide better linking.

Added more explanatory text about the SSB and EMB values.
I found that a blank line splits the extra text onto the
dedicated pages for SSB and EMB, while leaving the "brief"
description on the list of all Body enum values. That is nice.
2022-04-25 20:43:41 -04:00
Don Cross
4c34245c01 Kotlin doc cleanup: removed more 'jvm' tags.
I found that there were a bunch of lingering 'jvm'
tags in the generated markdown documentation.
Got rid of them with another change to format_kotlin_doc.py.
2022-04-25 17:16:46 -04:00
Don Cross
d130405d13 Kotlin docs: more enum cleanup.
I missed a couple of places where I want to remove
private constructor calls from enum members.
Also, discard [name] and [ordinal] links while preserving
other properties that are intentionally exposed.
2022-04-25 16:51:25 -04:00
Don Cross
b7c7733370 Kotlin docs: fixed backwards enum members.
I reported an issue to Dokka about enum members
being listed backwards in the generated markdown:

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

In the meantime, this is a workaround where I reverse the order
of the enum members in my own script format_kotlin_doc.py.
2022-04-25 16:41:19 -04:00
Don Cross
737fb01384 Kotlin docs: remove unwanted enum constructors.
This is a workaround for a Dokka GFM issue I reported:
https://github.com/Kotlin/dokka/issues/2468

I updated the format_kotlin_doc.py script to
remove the internal constructor calls for members of the Body enum.
2022-04-25 16:20:18 -04:00
Don Cross
5708ae36a6 Process Kotlin documentation to fix dokka issues.
The dokkaGfm tool has a few oddities I don't like.
I updated my format_kotlin_doc.py script to work around
a couple of them:

1. Strip out all the noisy [jvm] tags it puts everywhere.

2. Remove the unhelpful and incorrect `Properties` sections
   it adds to all my enum classes and enum members.

I will come back and address other issues later.
2022-04-25 12:56:35 -04:00
Don Cross
e01235a260 Replaced another use of sha256sum with checksum.py. 2022-04-25 03:43:50 -04:00
Don Cross
105e806c4d Check download integrity on all operating systems.
The sha256sum and md5sum utilities are available by
default on Linux, but not Windows or Mac OS.
I created the script `checksum.py` that can perform
sha256 and md5 checksum verification on all 3 systems.

Got rid of the ugly checksum.bat I was using on Windows.
Deleted the md5 checksum files, since I only need sha256
for now.

Before this change, I was always skipping verification
of downloads on Mac systems.
2022-04-25 03:08:29 -04:00
Don Cross
8696241c90 Kotlin: search for planet aphelion/perihelion.
Added functions:

    searchPlanetApsis
    nextPlanetApsis

I discovered that I had an unnecessary special relaxation
of apsis error tolerance for Pluto. It turns out that currently
0.1 degrees of orbital rotation is enough for all the planets.
2022-04-24 20:55:51 -04:00
Don Cross
a6e72a2423 Kotlin: search for lunar nodes.
Search for times when the Moon ascends or descends
through the ecliptic plane. These are called
ascending and descending nodes. Added the functions:

    searchMoonNode
    nextMoonNode

Also corrected comments in the unit tests that
incorrectly stated nodes occur when the ecliptic
longitude is zero. They should have said the
ecliptic latitude is zero.
2022-04-23 20:34:52 -04:00
Don Cross
c22b70de3c Libration fix: Moon lat/lon in degrees.
While working on the Kotlin version of lunar libration,
I discovered the other languages were reporting
the Moon's ecliptic latitude and longitude in radians,
which was not the intended units. Pulled changes
from the `kotlin` branch where these angles are
reported in degrees instead of radians.
2022-04-22 19:49:26 -04:00
Don Cross
3ce32f8819 Kotlin: lunar libration. Fixes for other languages.
The existing lunar libration functions in the
other languages (C, C#, Python, JavaScript) were
calculating the Moon's ecliptic latitude and longitude
in radians, not degrees as intended. They have been fixed.

Implemented the libration function for Kotlin.
2022-04-22 16:36:14 -04:00
Don Cross
554bbf1b00 Kotlin: calculate Lagrange points.
Calculate the position and velocity of any
of the five Lagrange points for a pair of
Solar System bodies. Added the functions:

    lagrangePoint
    lagrangePointFast
2022-04-21 21:11:44 -04:00
Don Cross
e545677d67 Kotlin: observerGravity function. 2022-04-21 16:04:53 -04:00
Don Cross
567376255c Kotlin: visual magnitude, peak magnitude search.
Implemented the `illumination` function, which calculates
visual magnitude, illuminated phase angle/fraction, and
ring tilt for Saturn.

Implemented `searchPeakMagnitude` for finding when
Venus appears brightest in the sky.
2022-04-20 19:47:21 -04:00
Don Cross
ef6af40b0d Kotlin: added maximum elongation search.
Added searchMaxElongation function, which finds the
next time Mercury or Venus reaches is maximum angular
separation from the Sun.
2022-04-18 13:03:08 -04:00
Don Cross
0af17074f2 Kotlin: elongation function.
This function calculates how easy it is to see a given planet
with respect to the Sun: how far apart they are in the sky,
and whether the planet is easier to see in the morning or evening.
This function is especially helpful for spotting Mercury,
but it works with any body.
2022-04-18 11:41:46 -04:00
Don Cross
17fbf34a71 Kotlin: search lunar perigee, apogee.
Added functions to find a series of consecutive
lunar apsides:

    searchLunarApsis
    nextLunarApsis
2022-04-17 21:29:12 -04:00
Don Cross
f64d22c1c2 Kotlin: search for transits of Mercury and Venus.
Implemented functions searchTransit and nextTransit.
2022-04-17 14:40:59 -04:00
Don Cross
23ed1cda5a Kotlin: added more planet longitude tests.
Generate longitude output files that are tested by
the `generate` program.

Discovered that Windows `run.bat` was not correctly testing
the longitude output test files generated by the JavaScript
code. Fixed that.
2022-04-17 13:30:09 -04:00
Don Cross
16578935ad Kotlin: implemented relative longitude search.
Implemented searchRelativeLongitude, which finds
planetary conjunctions and oppositions.
Discovered I can make all languages' unit tests
more strict: 6.8 minute error tolerance instead of 15.

Fixed documentation mistake in C# function SearchRelativeLongitude:
the function cannot return null. It either finds a solution time
or throws an exception.

Simplified Kotlin unit tests: use a more compact pattern of
scanning space-delimited tokens in lines.
2022-04-17 12:22:07 -04:00
Don Cross
bca0b09bac Merge branch 'ebraminio-kotlin' into kotlin 2022-04-16 17:14:49 -04:00
Don Cross
a36d31b75e Merge branch 'kotlin' of https://github.com/ebraminio/astronomy into ebraminio-kotlin 2022-04-16 17:02:05 -04:00
Don Cross
4f387e5fda Kotlin: added heliocentric/topocentric state vector tests. 2022-04-16 16:23:35 -04:00
Ebrahim Byagowi
9cb3a50901 kotlin: Take advantage of functional interface syntax 2022-04-17 00:40:32 +04:30
Don Cross
0ed52f3cea Kotlin: barycentric states, geocentric moon/EMB
Added geoEmbState: calculates the geocentric
state vector of the Earth/Moon Barycenter (EMB).

Added baryState: calculates the barycentric
state vector of a body.

Unit tests now support parsing JPL Horizons
state vector text files.
2022-04-16 15:31:25 -04:00
Don Cross
d5fc878a6a Kotlin: calculate heliocentric ecliptic longitude
Added function: eclipticLongitude.
Verified its calculations against the same function
in the Python version of Astronomy Engine.
2022-04-16 12:59:48 -04:00
Don Cross
b1bc4ccc9b Kotlin: another test for local solar eclipses. 2022-04-16 11:16:44 -04:00
Don Cross
f0b0113806 Kotlin: added local solar eclipse prediction.
Added functions to predict solar eclipses seen
from a specified geographic location on the Earth:

    searchLocalSolarEclipse
    nextLocalSolarEclipse
2022-04-16 10:25:22 -04:00
Don Cross
896df1ad19 Removed Kotlin Native tests for now.
We are having difficulty getting Kotlin code to build for
both JVM and Native. For now, the priority is to support JVM,
so I am turning off installation of the Kotlin Native compiler.
2022-04-15 13:04:52 -04:00
Ebrahim Byagowi
f395ac4868 js: Revive moon radar demo
Apparently caller could send undefined as a value, this just makes it
regardless.
2022-04-15 14:17:28 +04:30
Don Cross
ad439c6d97 Kotlin Native work in progress: build errors.
Checking in with the Kotlin Native tests turned off,
because the code does not build yet. Seeking help.
2022-04-14 13:16:09 -04:00
Don Cross
61e398b592 Kotlin: removed all dependencies on JVM.
The Kotlin version of Astronomy Engine was using Java
classes like `Date` and `GregorianCalendar`.

Reworked the code to use a completely self-contained
representation of calendar date/time, just like the C version does.
Now Astronomy Engine does not depend on anything outside of
the Kotlin standard library. This should allow us to use
Astronomy Engine for Kotlin Native apps, Web Assembly, etc.

Updated Java demo to use the new method Time.fromMillisecondsSince1970.
2022-04-14 10:55:22 -04:00
Don Cross
6b2304c5c6 Download Kotlin Native tarball without all the verbosity. 2022-04-13 20:59:17 -04:00
Don Cross
30ee194e72 Trying my own Kotlin Native installer.
I kept running into problems trying to create
a GitHub Action to install the Kotlin Native compiler.
So I am rolling my own using a bash script.
2022-04-13 20:33:04 -04:00