From d3ae404f7a37feed07f140c23130eea5738c1d94 Mon Sep 17 00:00:00 2001 From: Dan Paulat Date: Mon, 2 Dec 2024 22:38:12 -0600 Subject: [PATCH] Delta angles must be normalized before they can be scaled --- .../scwx/qt/view/level2_product_view.cpp | 31 +++++++++++++++---- 1 file changed, 25 insertions(+), 6 deletions(-) diff --git a/scwx-qt/source/scwx/qt/view/level2_product_view.cpp b/scwx-qt/source/scwx/qt/view/level2_product_view.cpp index 0254904b..c483ab28 100644 --- a/scwx-qt/source/scwx/qt/view/level2_product_view.cpp +++ b/scwx-qt/source/scwx/qt/view/level2_product_view.cpp @@ -116,6 +116,7 @@ public: static bool IsRadarDataIncomplete( const std::shared_ptr& radarData); + static units::degrees NormalizeAngle(units::degrees angle); Level2ProductView* self_; @@ -1042,10 +1043,9 @@ void Level2ProductView::Impl::ComputeCoordinates( const units::degrees prevAngle = prevRadial1->second->azimuth_angle(); - // No wrapping required since angle is only used for geodesic - // calculation + // Calculate delta angle const units::degrees deltaAngle = - currentAngle - prevAngle; + NormalizeAngle(currentAngle - prevAngle); // Delta scale is half the delta angle to reach the center of the // bin, because smoothing is enabled @@ -1076,9 +1076,9 @@ void Level2ProductView::Impl::ComputeCoordinates( const units::degrees prevAngle2 = prevRadial2->second->azimuth_angle(); - // No wrapping required since angle is only used for geodesic - // calculation - const units::degrees deltaAngle = prevAngle1 - prevAngle2; + // Calculate delta angle + const units::degrees deltaAngle = + NormalizeAngle(prevAngle1 - prevAngle2); const float deltaScale = (smoothingEnabled) ? @@ -1162,6 +1162,25 @@ bool Level2ProductView::Impl::IsRadarDataIncomplete( return angleDelta > kIncompleteDataAngleThreshold_; } +units::degrees +Level2ProductView::Impl::NormalizeAngle(units::degrees angle) +{ + constexpr auto angleLimit = units::degrees {180.0f}; + constexpr auto fullAngle = units::degrees {360.0f}; + + // Normalize angle to [-180, 180) + while (angle < -angleLimit) + { + angle += fullAngle; + } + while (angle >= angleLimit) + { + angle -= fullAngle; + } + + return angle; +} + std::optional Level2ProductView::GetBinLevel(const common::Coordinate& coordinate) const {