From 9384ce69b356856c1bd7cca95381ea0d7f26d416 Mon Sep 17 00:00:00 2001 From: Don Cross Date: Mon, 8 Jul 2019 15:59:24 -0400 Subject: [PATCH] Python: rework apsis kind as an IntEnum called ApsisKind. --- generate/template/astronomy.py | 14 ++++++++------ pydown/pydown.py | 2 +- source/python/astronomy.py | 14 ++++++++------ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/generate/template/astronomy.py b/generate/template/astronomy.py index 6912db59..e2d81330 100644 --- a/generate/template/astronomy.py +++ b/generate/template/astronomy.py @@ -1755,9 +1755,11 @@ def _distance_slope(direction, time): dist2 = _MoonDistance(t2) return direction * (dist2 - dist1) / dt -APSIS_PERICENTER = 0 -APSIS_APOCENTER = 1 -APSIS_INVALID = 2 +@unique +class ApsisKind(IntEnum): + Pericenter = 0 + Apocenter = 1 + Invalid = 2 class Apsis: def __init__(self, time, kind, dist_au): @@ -1782,12 +1784,12 @@ def SearchLunarApsis(startTime): # We found a minimum-distance event: perigee. # Search the time range for the time when the slope goes from negative to positive. apsis_time = Search(_distance_slope, +1, t1, t2, 1.0) - kind = APSIS_PERICENTER + kind = ApsisKind.Pericenter elif m1 > 0.0 or m2 < 0.0: # We found a maximum-distance event: apogee. # Search the time range for the time when the slope goes from positive to negative. apsis_time = Search(_distance_slope, -1, t1, t2, 1.0) - kind = APSIS_APOCENTER + kind = ApsisKind.Apocenter else: # This should never happen. It should not be possible for both slopes to be zero. raise InternalError() @@ -1813,7 +1815,7 @@ def NextLunarApsis(apsis): time = apsis.time.AddDays(skip) next = SearchLunarApsis(time) # Verify that we found the opposite apsis from the previous one. - if apsis.kind not in [APSIS_APOCENTER, APSIS_PERICENTER]: + if apsis.kind not in [ApsisKind.Apocenter, ApsisKind.Pericenter]: raise Error('Parameter "apsis" contains an invalid "kind" value.') if next.kind + apsis.kind != 1: raise InternalError() diff --git a/pydown/pydown.py b/pydown/pydown.py index 5e17d61b..6ecb97dc 100755 --- a/pydown/pydown.py +++ b/pydown/pydown.py @@ -33,7 +33,7 @@ def Markdown(module): elif inspect.ismodule(obj): pass # ignore other modules pulled in else: - print('other', name) + print('pydown.py WARNING: ignoring', name) return '' def main(): diff --git a/source/python/astronomy.py b/source/python/astronomy.py index 676f4be9..828b3e22 100644 --- a/source/python/astronomy.py +++ b/source/python/astronomy.py @@ -3816,9 +3816,11 @@ def _distance_slope(direction, time): dist2 = _MoonDistance(t2) return direction * (dist2 - dist1) / dt -APSIS_PERICENTER = 0 -APSIS_APOCENTER = 1 -APSIS_INVALID = 2 +@unique +class ApsisKind(IntEnum): + Pericenter = 0 + Apocenter = 1 + Invalid = 2 class Apsis: def __init__(self, time, kind, dist_au): @@ -3843,12 +3845,12 @@ def SearchLunarApsis(startTime): # We found a minimum-distance event: perigee. # Search the time range for the time when the slope goes from negative to positive. apsis_time = Search(_distance_slope, +1, t1, t2, 1.0) - kind = APSIS_PERICENTER + kind = ApsisKind.Pericenter elif m1 > 0.0 or m2 < 0.0: # We found a maximum-distance event: apogee. # Search the time range for the time when the slope goes from positive to negative. apsis_time = Search(_distance_slope, -1, t1, t2, 1.0) - kind = APSIS_APOCENTER + kind = ApsisKind.Apocenter else: # This should never happen. It should not be possible for both slopes to be zero. raise InternalError() @@ -3874,7 +3876,7 @@ def NextLunarApsis(apsis): time = apsis.time.AddDays(skip) next = SearchLunarApsis(time) # Verify that we found the opposite apsis from the previous one. - if apsis.kind not in [APSIS_APOCENTER, APSIS_PERICENTER]: + if apsis.kind not in [ApsisKind.Apocenter, ApsisKind.Pericenter]: raise Error('Parameter "apsis" contains an invalid "kind" value.') if next.kind + apsis.kind != 1: raise InternalError()