Commit Graph

2245 Commits

Author SHA1 Message Date
Don Cross
1de31cf21f C#: Implemented Observer.ToString(). 2023-02-26 17:08:07 -05:00
Don Cross
2fcaf27995 Python: verify several thousand calendar dates. 2023-02-26 13:17:21 -05:00
Don Cross
ce0acf6d44 Kotlin: support calendar dates for years -999999 to +999999.
Enhanced the Time class to correctly calculate calendar
dates for the year range -999999 to +999999.

Made unit tests in C, C#, and Kotlin all exercise
the full year range, for February 28 and March 1 in each year,
to make sure we cover before and after each potential leap day.
2023-02-26 12:54:57 -05:00
Don Cross
16727b85c8 C: force use of 64-bit integers in calendar functions.
The C functions for calculating calendar dates used the
type `long` to perform calculations that require 64-bit
integers. However, in some C compilers, `long` is still
32 bits. This caused a failure in Windows for extreme
year values. So I now use the type `int64_t` to explicitly
require a 64-bit integer.
2023-02-26 10:31:27 -05:00
Don Cross
7e196a3c17 Fixed Windows batch files ignoring negative integer failure codes.
In many of my Windows batch files, I used the following
construct to detect failures:

    do_something
    if errorlevel 1 (
        echo.An error occurred in do_something
        exit /b 1
    )

I discovered that it is possible for a Windows program
to exit with a negative integer error code.
This causes the above construct to miss the failure
and the batch file blithely continues.

So I have replaced that construct with

    do_something || (
        echo.An error occurred in do_something
        exit /b 1
    )

This way, if the command exits with any nonzero error,
we correctly detect it as a failure.
2023-02-26 10:26:42 -05:00
Don Cross
503538da12 PY: Fixed calendar/time conversion functions for extreme year values.
Applying the same recent fixes to C and C# to the Python code.

I'm also changing my philosophy of representing times.
From now on, they will be truncated to the floor millisecond,
not rounded to the nearest millisecond. This means we don't reach
another calendar date until we have had 60 full seconds after
the last minute. Otherwise there is too much nasty logic for
rounding up calendar dates. I will follow suit across all languages.
2023-02-25 22:37:58 -05:00
Don Cross
e7d48c6ea7 C#: Fixed bugs with calendar dates with extreme year values.
Fixed problems converting AstroTime to calendar dates and back.
Also expose struct CalendarDateTime to outside callers,
for convenience dealing with Gregorian calendar dates.
2023-02-25 20:23:41 -05:00
Don Cross
1ac4ab2dba C: Fixed more problems with calendar date calculations.
With more rigorous testing, I discovered more bugs
in the C functions for converting calendar dates
to times and vice versa.

Astronomy_UtcFromTime():
When the year went before -4714, the value of the variable
`djd` went negative, causing the typecast `(long)djd` to
round toward zero instead of taking the true floor.
Changed this to `(long)floor(djd)`.

Astronomy_MakeTime():
Reworked the logic so that none of the integer divisions
involve negative values over the year range -999999..+999999.
2023-02-25 18:18:42 -05:00
Don Cross
7e17705801 PY: Fixed calendar calculations for extreme year values. 2023-02-25 14:20:55 -05:00
Don Cross
f537974530 C: Fixed bugs in Astronomy_UtcFromTime for extreme year values.
Addressed limitations of the logic I copied from NOVAS cal_date().
Its formulas did not work for years much before -12000 due to
integer division going negative. I figured out how to make the
formulas work for plus or minus 1 million years from the present era.
2023-02-24 20:31:55 -05:00
Don Cross
88a94b860f C#: Convert times and vectors to/from strings.
Implemented and added tests for the following methods:

    AstroTime.TryParse()
    AstroVector.TryParse()

I still need to implement StateVector.TryParse().

Fixed a bug in CalendarDateTime: the NOVAS cal_date
function worked well, except when years go below
somewhere near -12000. Then the formulas start making
negative numbers, which messes up the calculation
of the month and day.

So to fix this, I figured out that any multiple of
400 years added to any calendar date gives the exact
same calendar date. And 400 years always has the exact
same number of days in it: 146097.

Because one million years = 400 * 2500 years, I can
add 2500*146097 days at the front of the formula
and subtract 1000000 years at the back, and everything
works for the entire range of years plus or minus
one million years from the present.

Because my date format allows for no more than a 6-digit
decimal year, this is perfectly adequate.
2023-02-24 19:49:12 -05:00
Don Cross
f3c211fadb C#: Added StateVector.ToString(). 2023-02-23 22:31:47 -05:00
Don Cross
410708e8b3 C#: Added AstroVector.ToString() function. 2023-02-23 22:06:12 -05:00
Don Cross
4ab4b0bb6e Fixed #259 - JS documentation is usable for CorrectLightTravel function.
Replace the abstract class with a parameter of function type.
This allows the documentation to fully explain how to use
`CorrectLightTravel` without having to look at the code.
2023-02-23 18:01:51 -05:00
Don Cross
d321ed695c Version 2.1.15: Python type hints. v2.1.15 2023-02-21 17:24:25 -05:00
Don Cross
b686b6185c Escalated mypy to use --strict option.
Use --strict in mypy to perform maximum type checking.
Fixed the remaining errors.
2023-02-21 15:34:52 -05:00
Don Cross
8963ef9b1a Python docs: show arrow character instead of -> for return types. 2023-02-21 14:19:44 -05:00
Don Cross
102e7e7dc7 Python docs: better formatting of type hints in function signatures. 2023-02-21 14:07:55 -05:00
Don Cross
513d1f0f17 Python: reordered things to reduce forward type declarations. 2023-02-21 13:17:43 -05:00
Don Cross
cd8f9e9f4c Improved Python table for Jupiter moon models.
Updated the code generator so the Python version of
the Jupiter moon tables has better type checking
and is easier to understand.
2023-02-21 12:17:35 -05:00
Don Cross
23b45dd075 Improved Pluto state table in Python code.
The generated code for the Pluto state table in Python
now uses a class `_pstate` for better type checking.
It also makes the code easier to understand.
Moved class _TerseVector higher in the source file to
reduce the need for quoted forward type declarations.
2023-02-21 10:56:05 -05:00
Don Cross
a530069e99 Improved Python VSOP table generation.
The VSOP table generator for Python now is now
better type-checked using classes and tuples.
This also makes the code easier to understand.
2023-02-21 10:12:45 -05:00
Don Cross
f849c11258 Require type hints for all Python functions.
I added the mypy option `--disallow-untyped-defs` to fail
any function lacking complete type hints.
Then I fixed all the resulting errors.

I ended up changing the Python code generator to create
some tuple types instead of list, because it is possible
to write stricter type checks that way. This was in
the Pluto and Jupiter Moon tables.
I still should come back and do the same thing for the VSOP tables.

The type checking revealed a couple of places where I wasn't
checking for a search failure. I fixed those too.
2023-02-20 20:04:10 -05:00
Don Cross
afe1498917 Merge branch 'python_type_hints' 2023-02-20 11:47:59 -05:00
Don Cross
981cafd427 Node.js demo that shows how to calculate drift of the vernal point. 2023-02-20 11:38:09 -05:00
Don Cross
fa3b90678e Work around inconsistent type signatures in Python.
My custom Markdown generator for Python documentation `pydown`
was generating inconsistent function type signatures depending
on the version of Python executing it. This happened for functions
like `Search` that return either Time or None.

On older Pythons we see "Optional[astronomy.Time]".
On newer Pythons we see "Union[astronomy.Time, NoneType]".
This caused unit test failures on GitHub Actions when I check in changes.

I prefer to see Optional[x] over Union[x, NoneType], so I hacked
pydown to replace this using a regex substitution.
2023-02-20 10:32:55 -05:00
Don Cross
fc408501c5 Fix for dotnet command no longer allowing --output on solution files.
The `dotnet` command no longer allows using `--output` to specify the
output directory for building a solution file:
https://github.com/dotnet/sdk/issues/15607

This broke my GitHub Actions tests for C#.

I used the following workaround, because in my case I
know merging multiple builds into one directory is safe:
https://github.com/dotnet/sdk/issues/30624#issuecomment-1432118204
2023-02-19 17:13:05 -05:00
Don Cross
da14856a19 Pydown fix: more reliable way to extract list of imported symbols. 2023-02-19 15:47:46 -05:00
Don Cross
1040a213dc Merge branch 'omar_python_type_hints' into python_type_hints 2023-02-19 14:28:48 -05:00
ris-tlp
66c3ebbc33 Fix PR reviews 2023-02-18 15:45:06 -05:00
ris-tlp
43be952eb2 Python: Type Hints Integration - 6 2023-02-18 03:58:01 -05:00
ris-tlp
e7f8f2b8e2 Python: Type Hints Integration - 5 2023-02-18 03:26:35 -05:00
ris-tlp
0d4c438c2b Python: Type Hints Integration - 4 2023-02-18 02:46:04 -05:00
ris-tlp
f442afd342 Relaxation of test for M1 MacOS Ventura 13.2.1 2023-02-18 02:03:42 -05:00
ris-tlp
d055cb9fe8 Python: Type Hints Integration - 3 2023-02-16 01:12:09 -05:00
ris-tlp
92d266fc3a Python: Type Hints Integration - 2 2023-02-15 02:07:43 -05:00
ris-tlp
7818a6ce38 Python: Fixing multiple imports within same line bug 2023-02-15 00:56:18 -05:00
ris-tlp
6bb781146b Python: Type Hints Integration - 1 2023-02-13 22:56:10 -05:00
ris-tlp
6c1523038d Testing if setting branch upstream was successful 2023-02-13 19:33:21 -05:00
Don Cross
f87b600955 Document mypy, pylint as required contributor tools. 2023-02-13 14:18:26 -05:00
Don Cross
d73d271a4f Fixed pydown to understand imported symbols.
In order to import typing.Union into the module namespace,
I had to fix pydown to recognize Union as a defined symbol.
2023-02-13 13:19:13 -05:00
Don Cross
740ef86d31 Run mypy to verify Python data types. 2023-02-13 12:30:16 -05:00
Don Cross
54181605a0 Merge branch 'pr_python_type_hints' into python_type_hints 2023-02-13 10:23:59 -05:00
ris-tlp
4ea28c6d88 Python: Few typehints for initial review 2023-02-13 02:11:37 -05:00
Don Cross
97c4d2f8f0 Version 2.1.14: added HourAngle function. v2.1.14 2023-02-12 21:34:10 -05:00
Don Cross
42650bd341 Java: added true solar time demo 2023-02-12 20:01:05 -05:00
Don Cross
1dcdb7780f Kotlin: true solar time demo 2023-02-12 19:30:35 -05:00
Don Cross
632d059972 Kotlin: implemented hourAngle function. 2023-02-12 18:13:36 -05:00
Don Cross
5d130f0b3c Missed a change to generated astronomy.ts. 2023-02-12 16:47:10 -05:00
Don Cross
42c352f918 PY: true solar time demo 2023-02-12 16:28:37 -05:00