From 63ed3746b224ef6f130debd2a65740d154036aee Mon Sep 17 00:00:00 2001 From: Don Cross Date: Mon, 19 Jun 2023 16:28:34 -0400 Subject: [PATCH] Misc fixes for Raspberry Pi 4 build. On the Raspberry Pi 4, using latest versions of cppcheck and pylint, a few more minor fixes were needed for eliminating warnings. Also had to soften a tolerance for the Kotlin unit tests. --- .gitignore | 1 + demo/python/astronomy.py | 18 +++++++++++------- generate/codegen.c | 6 +++--- generate/generate.c | 4 ++-- generate/template/astronomy.py | 18 +++++++++++------- .../io/github/cosinekitty/astronomy/Tests.kt | 2 +- source/python/astronomy/astronomy.py | 18 +++++++++++------- 7 files changed, 40 insertions(+), 27 deletions(-) diff --git a/.gitignore b/.gitignore index 23491dcc..f02bf1ce 100644 --- a/.gitignore +++ b/.gitignore @@ -2,4 +2,5 @@ .vs .idea __pycache__ +.mypy_cache bin/ diff --git a/demo/python/astronomy.py b/demo/python/astronomy.py index b413f9ee..e5198b34 100644 --- a/demo/python/astronomy.py +++ b/demo/python/astronomy.py @@ -786,11 +786,11 @@ class _StarDef: self.dec = 0.0 self.dist = 0.0 # signals that the star has not yet been defined -_StarTable = [_StarDef() for _ in range(8)] +_StarTable:List[_StarDef] = [_StarDef() for _ in range(8)] def _GetStar(body: Body) -> Optional[_StarDef]: if Body.Star1.value <= body.value <= Body.Star8.value: - return _StarTable[body.value - Body.Star1.value] + return _StarTable[int(body.value - Body.Star1.value)] return None def _UserDefinedStar(body: Body) -> Optional[_StarDef]: @@ -867,7 +867,7 @@ def BodyCode(name: str) -> Body: def _IsSuperiorPlanet(body: Body) -> bool: return body in [Body.Mars, Body.Jupiter, Body.Saturn, Body.Uranus, Body.Neptune, Body.Pluto] -_PlanetOrbitalPeriod = [ +_PlanetOrbitalPeriod:List[float] = [ 87.969, 224.701, _EARTH_ORBITAL_PERIOD, @@ -944,7 +944,7 @@ def PlanetOrbitalPeriod(body: Body) -> float: The mean orbital period of the body in days. """ if isinstance(body, Body) and (0 <= body.value < len(_PlanetOrbitalPeriod)): - return _PlanetOrbitalPeriod[body.value] + return _PlanetOrbitalPeriod[int(body.value)] raise InvalidBodyError(body) def _SynodicPeriod(body: Body) -> float: @@ -954,7 +954,7 @@ def _SynodicPeriod(body: Body) -> float: raise InvalidBodyError(body) if body == Body.Moon: return _MEAN_SYNODIC_MONTH - return abs(_EARTH_ORBITAL_PERIOD / (_EARTH_ORBITAL_PERIOD/_PlanetOrbitalPeriod[body.value] - 1.0)) + return abs(_EARTH_ORBITAL_PERIOD / (_EARTH_ORBITAL_PERIOD/_PlanetOrbitalPeriod[int(body.value)] - 1.0)) def AngleBetween(a: Vector, b: Vector) -> float: """Calculates the angle in degrees between two vectors. @@ -6313,7 +6313,7 @@ def _altdiff(context: _altitude_context, time: Time) -> float: ofdate = Equator(context.body, time, context.observer, True, True) hor = Horizon(time, context.observer, ofdate.ra, ofdate.dec, Refraction.Airless) altitude = hor.altitude + math.degrees(math.asin(context.bodyRadiusAu / ofdate.dist)) - return context.direction.value*(altitude - context.targetAltitude) + return float(context.direction.value)*(altitude - context.targetAltitude) def _MaxAltitudeSlope(body: Body, latitude: float) -> float: # Calculate the maximum possible rate that this body's altitude @@ -8901,6 +8901,8 @@ def _LocalEclipse(shadow: _ShadowInfo, observer: Observer) -> LocalSolarEclipseI t2 = shadow.time.AddDays(+PARTIAL_WINDOW) partial_begin = _LocalEclipseTransition(observer, +1.0, _local_partial_distance, t1, shadow.time) partial_end = _LocalEclipseTransition(observer, -1.0, _local_partial_distance, shadow.time, t2) + total_begin: Optional[EclipseEvent] + total_end: Optional[EclipseEvent] if shadow.r < abs(shadow.k): # take absolute value of 'k' to handle annular eclipses too. t1 = shadow.time.AddDays(-TOTAL_WINDOW) t2 = shadow.time.AddDays(+TOTAL_WINDOW) @@ -8908,9 +8910,9 @@ def _LocalEclipse(shadow: _ShadowInfo, observer: Observer) -> LocalSolarEclipseI total_end = _LocalEclipseTransition(observer, -1.0, _local_total_distance, shadow.time, t2) kind = _EclipseKindFromUmbra(shadow.k) else: + kind = EclipseKind.Partial total_begin = None total_end = None - kind = EclipseKind.Partial obscuration = 1.0 if (kind == EclipseKind.Total) else _SolarEclipseObscuration(shadow.dir, shadow.target) return LocalSolarEclipseInfo(kind, obscuration, partial_begin, total_begin, peak, total_end, partial_end) @@ -8948,6 +8950,8 @@ def _GeoidIntersect(shadow: _ShadowInfo) -> GlobalSolarEclipseInfo: C = (e.x*e.x + e.y*e.y + e.z*e.z) - R*R radic = B*B - 4*A*C + obscuration: Optional[float] + if radic > 0.0: # Calculate the closer of the two intersection points. # This will be on the day side of the Earth. diff --git a/generate/codegen.c b/generate/codegen.c index d5cb826f..46a84aa9 100644 --- a/generate/codegen.c +++ b/generate/codegen.c @@ -672,7 +672,7 @@ double ExtrapolatedDeltaT(int year) static int ScanRealArray( - cg_context_t *context, + const cg_context_t *context, const char *filename, int lnum, char *line, @@ -727,7 +727,7 @@ static int ScanRealArray( return 0; /* successful parse */ } -static int OptimizeConst(cg_context_t *context, char *buffer, size_t size, double c, const char *v) +static int OptimizeConst(const cg_context_t *context, char *buffer, size_t size, double c, const char *v) { int nprinted; const char *op; @@ -757,7 +757,7 @@ static int OptimizeConst(cg_context_t *context, char *buffer, size_t size, doubl return 0; } -static int OptimizeLinear(cg_context_t *context, char *buffer, size_t size, double a, double b) +static int OptimizeLinear(const cg_context_t *context, char *buffer, size_t size, double a, double b) { int nprinted; diff --git a/generate/generate.c b/generate/generate.c index 11dbac83..26f09dcd 100644 --- a/generate/generate.c +++ b/generate/generate.c @@ -1750,8 +1750,8 @@ static int Diff(const char *filename1, const char *filename2, int *nlines) for(;;) { - char *r1 = fgets(line1, sizeof(line1), infile1); - char *r2 = fgets(line2, sizeof(line2), infile2); + const char *r1 = fgets(line1, sizeof(line1), infile1); + const char *r2 = fgets(line2, sizeof(line2), infile2); if (r1 == NULL && r2 == NULL) break; if (r1 == NULL) diff --git a/generate/template/astronomy.py b/generate/template/astronomy.py index baae3c15..04f157cc 100644 --- a/generate/template/astronomy.py +++ b/generate/template/astronomy.py @@ -786,11 +786,11 @@ class _StarDef: self.dec = 0.0 self.dist = 0.0 # signals that the star has not yet been defined -_StarTable = [_StarDef() for _ in range(8)] +_StarTable:List[_StarDef] = [_StarDef() for _ in range(8)] def _GetStar(body: Body) -> Optional[_StarDef]: if Body.Star1.value <= body.value <= Body.Star8.value: - return _StarTable[body.value - Body.Star1.value] + return _StarTable[int(body.value - Body.Star1.value)] return None def _UserDefinedStar(body: Body) -> Optional[_StarDef]: @@ -867,7 +867,7 @@ def BodyCode(name: str) -> Body: def _IsSuperiorPlanet(body: Body) -> bool: return body in [Body.Mars, Body.Jupiter, Body.Saturn, Body.Uranus, Body.Neptune, Body.Pluto] -_PlanetOrbitalPeriod = [ +_PlanetOrbitalPeriod:List[float] = [ 87.969, 224.701, _EARTH_ORBITAL_PERIOD, @@ -944,7 +944,7 @@ def PlanetOrbitalPeriod(body: Body) -> float: The mean orbital period of the body in days. """ if isinstance(body, Body) and (0 <= body.value < len(_PlanetOrbitalPeriod)): - return _PlanetOrbitalPeriod[body.value] + return _PlanetOrbitalPeriod[int(body.value)] raise InvalidBodyError(body) def _SynodicPeriod(body: Body) -> float: @@ -954,7 +954,7 @@ def _SynodicPeriod(body: Body) -> float: raise InvalidBodyError(body) if body == Body.Moon: return _MEAN_SYNODIC_MONTH - return abs(_EARTH_ORBITAL_PERIOD / (_EARTH_ORBITAL_PERIOD/_PlanetOrbitalPeriod[body.value] - 1.0)) + return abs(_EARTH_ORBITAL_PERIOD / (_EARTH_ORBITAL_PERIOD/_PlanetOrbitalPeriod[int(body.value)] - 1.0)) def AngleBetween(a: Vector, b: Vector) -> float: """Calculates the angle in degrees between two vectors. @@ -4807,7 +4807,7 @@ def _altdiff(context: _altitude_context, time: Time) -> float: ofdate = Equator(context.body, time, context.observer, True, True) hor = Horizon(time, context.observer, ofdate.ra, ofdate.dec, Refraction.Airless) altitude = hor.altitude + math.degrees(math.asin(context.bodyRadiusAu / ofdate.dist)) - return context.direction.value*(altitude - context.targetAltitude) + return float(context.direction.value)*(altitude - context.targetAltitude) def _MaxAltitudeSlope(body: Body, latitude: float) -> float: # Calculate the maximum possible rate that this body's altitude @@ -6944,6 +6944,8 @@ def _LocalEclipse(shadow: _ShadowInfo, observer: Observer) -> LocalSolarEclipseI t2 = shadow.time.AddDays(+PARTIAL_WINDOW) partial_begin = _LocalEclipseTransition(observer, +1.0, _local_partial_distance, t1, shadow.time) partial_end = _LocalEclipseTransition(observer, -1.0, _local_partial_distance, shadow.time, t2) + total_begin: Optional[EclipseEvent] + total_end: Optional[EclipseEvent] if shadow.r < abs(shadow.k): # take absolute value of 'k' to handle annular eclipses too. t1 = shadow.time.AddDays(-TOTAL_WINDOW) t2 = shadow.time.AddDays(+TOTAL_WINDOW) @@ -6951,9 +6953,9 @@ def _LocalEclipse(shadow: _ShadowInfo, observer: Observer) -> LocalSolarEclipseI total_end = _LocalEclipseTransition(observer, -1.0, _local_total_distance, shadow.time, t2) kind = _EclipseKindFromUmbra(shadow.k) else: + kind = EclipseKind.Partial total_begin = None total_end = None - kind = EclipseKind.Partial obscuration = 1.0 if (kind == EclipseKind.Total) else _SolarEclipseObscuration(shadow.dir, shadow.target) return LocalSolarEclipseInfo(kind, obscuration, partial_begin, total_begin, peak, total_end, partial_end) @@ -6991,6 +6993,8 @@ def _GeoidIntersect(shadow: _ShadowInfo) -> GlobalSolarEclipseInfo: C = (e.x*e.x + e.y*e.y + e.z*e.z) - R*R radic = B*B - 4*A*C + obscuration: Optional[float] + if radic > 0.0: # Calculate the closer of the two intersection points. # This will be on the day side of the Earth. diff --git a/source/kotlin/src/test/kotlin/io/github/cosinekitty/astronomy/Tests.kt b/source/kotlin/src/test/kotlin/io/github/cosinekitty/astronomy/Tests.kt index 7cce64cc..b1d4b410 100644 --- a/source/kotlin/src/test/kotlin/io/github/cosinekitty/astronomy/Tests.kt +++ b/source/kotlin/src/test/kotlin/io/github/cosinekitty/astronomy/Tests.kt @@ -532,7 +532,7 @@ class Tests { checkScalar(ofdate.dist, 0.29355004763100184, 1.0e-16, "Venus EQD distance") val hor = horizon(time, observer, ofdate.ra, ofdate.dec, Refraction.None) - checkScalar(hor.azimuth, 87.59636363753623, 1.0e-16, "Venus azimuth") + checkScalar(hor.azimuth, 87.59636363753623, 1.5e-14, "Venus azimuth") checkScalar(hor.altitude, 54.92906326370683, 7.2e-15, "Venus altitude") } diff --git a/source/python/astronomy/astronomy.py b/source/python/astronomy/astronomy.py index b413f9ee..e5198b34 100644 --- a/source/python/astronomy/astronomy.py +++ b/source/python/astronomy/astronomy.py @@ -786,11 +786,11 @@ class _StarDef: self.dec = 0.0 self.dist = 0.0 # signals that the star has not yet been defined -_StarTable = [_StarDef() for _ in range(8)] +_StarTable:List[_StarDef] = [_StarDef() for _ in range(8)] def _GetStar(body: Body) -> Optional[_StarDef]: if Body.Star1.value <= body.value <= Body.Star8.value: - return _StarTable[body.value - Body.Star1.value] + return _StarTable[int(body.value - Body.Star1.value)] return None def _UserDefinedStar(body: Body) -> Optional[_StarDef]: @@ -867,7 +867,7 @@ def BodyCode(name: str) -> Body: def _IsSuperiorPlanet(body: Body) -> bool: return body in [Body.Mars, Body.Jupiter, Body.Saturn, Body.Uranus, Body.Neptune, Body.Pluto] -_PlanetOrbitalPeriod = [ +_PlanetOrbitalPeriod:List[float] = [ 87.969, 224.701, _EARTH_ORBITAL_PERIOD, @@ -944,7 +944,7 @@ def PlanetOrbitalPeriod(body: Body) -> float: The mean orbital period of the body in days. """ if isinstance(body, Body) and (0 <= body.value < len(_PlanetOrbitalPeriod)): - return _PlanetOrbitalPeriod[body.value] + return _PlanetOrbitalPeriod[int(body.value)] raise InvalidBodyError(body) def _SynodicPeriod(body: Body) -> float: @@ -954,7 +954,7 @@ def _SynodicPeriod(body: Body) -> float: raise InvalidBodyError(body) if body == Body.Moon: return _MEAN_SYNODIC_MONTH - return abs(_EARTH_ORBITAL_PERIOD / (_EARTH_ORBITAL_PERIOD/_PlanetOrbitalPeriod[body.value] - 1.0)) + return abs(_EARTH_ORBITAL_PERIOD / (_EARTH_ORBITAL_PERIOD/_PlanetOrbitalPeriod[int(body.value)] - 1.0)) def AngleBetween(a: Vector, b: Vector) -> float: """Calculates the angle in degrees between two vectors. @@ -6313,7 +6313,7 @@ def _altdiff(context: _altitude_context, time: Time) -> float: ofdate = Equator(context.body, time, context.observer, True, True) hor = Horizon(time, context.observer, ofdate.ra, ofdate.dec, Refraction.Airless) altitude = hor.altitude + math.degrees(math.asin(context.bodyRadiusAu / ofdate.dist)) - return context.direction.value*(altitude - context.targetAltitude) + return float(context.direction.value)*(altitude - context.targetAltitude) def _MaxAltitudeSlope(body: Body, latitude: float) -> float: # Calculate the maximum possible rate that this body's altitude @@ -8901,6 +8901,8 @@ def _LocalEclipse(shadow: _ShadowInfo, observer: Observer) -> LocalSolarEclipseI t2 = shadow.time.AddDays(+PARTIAL_WINDOW) partial_begin = _LocalEclipseTransition(observer, +1.0, _local_partial_distance, t1, shadow.time) partial_end = _LocalEclipseTransition(observer, -1.0, _local_partial_distance, shadow.time, t2) + total_begin: Optional[EclipseEvent] + total_end: Optional[EclipseEvent] if shadow.r < abs(shadow.k): # take absolute value of 'k' to handle annular eclipses too. t1 = shadow.time.AddDays(-TOTAL_WINDOW) t2 = shadow.time.AddDays(+TOTAL_WINDOW) @@ -8908,9 +8910,9 @@ def _LocalEclipse(shadow: _ShadowInfo, observer: Observer) -> LocalSolarEclipseI total_end = _LocalEclipseTransition(observer, -1.0, _local_total_distance, shadow.time, t2) kind = _EclipseKindFromUmbra(shadow.k) else: + kind = EclipseKind.Partial total_begin = None total_end = None - kind = EclipseKind.Partial obscuration = 1.0 if (kind == EclipseKind.Total) else _SolarEclipseObscuration(shadow.dir, shadow.target) return LocalSolarEclipseInfo(kind, obscuration, partial_begin, total_begin, peak, total_end, partial_end) @@ -8948,6 +8950,8 @@ def _GeoidIntersect(shadow: _ShadowInfo) -> GlobalSolarEclipseInfo: C = (e.x*e.x + e.y*e.y + e.z*e.z) - R*R radic = B*B - 4*A*C + obscuration: Optional[float] + if radic > 0.0: # Calculate the closer of the two intersection points. # This will be on the day side of the Earth.