From 84a24dfa2176c3bb04fc0492d33ade1ba08de9f8 Mon Sep 17 00:00:00 2001 From: Andreas Specovius Date: Tue, 16 Jun 2020 21:21:19 +0200 Subject: [PATCH] Fix in skycoord handling --- src/sky/GSkyRegionRect.cpp | 6 ++++++ 1 file changed, 6 insertions(+), 0 deletions(-) diff --git a/src/sky/GSkyRegionRect.cpp b/src/sky/GSkyRegionRect.cpp index 0dc1769..a969ab8 100644 --- a/src/sky/GSkyRegionRect.cpp +++ b/src/sky/GSkyRegionRect.cpp @@ -754,6 +754,7 @@ bool GSkyRegionRect::overlaps(const GSkyRegion& reg) const GSkyDir GSkyRegionRect::transform_to_local(const GSkyDir& skydir) const { // Get rid of negative right ascension coordinates + // to obtain angles in [0,2pi] // (Surely there is a more clever way to to this) double skydir_ra = skydir.ra(); if (skydir_ra < 0) { @@ -768,6 +769,11 @@ GSkyDir GSkyRegionRect::transform_to_local(const GSkyDir& skydir) const double dx = skydir_ra - centre_ra; double dy = skydir.dec() - m_centre.dec(); + // Make sure the closest angular separation is chosen + if (std::abs(dx) > gammalib::pi) { + dx = gammalib::twopi - std::abs(dx); + } + // Correction for spherical coordinate system dx *= std::cos(skydir.dec()); -- libgit2 0.21.4