Commit 84a24dfa2176c3bb04fc0492d33ade1ba08de9f8

Authored by Andreas Specovius
Committed by Jürgen Knödlseder
1 parent 13c8995b

Fix in skycoord handling

Showing 1 changed file with 6 additions and 0 deletions
src/sky/GSkyRegionRect.cpp
@@ -754,6 +754,7 @@ bool GSkyRegionRect::overlaps(const GSkyRegion& reg) const @@ -754,6 +754,7 @@ bool GSkyRegionRect::overlaps(const GSkyRegion& reg) const
754 GSkyDir GSkyRegionRect::transform_to_local(const GSkyDir& skydir) const 754 GSkyDir GSkyRegionRect::transform_to_local(const GSkyDir& skydir) const
755 { 755 {
756 // Get rid of negative right ascension coordinates 756 // Get rid of negative right ascension coordinates
  757 + // to obtain angles in [0,2pi]
757 // (Surely there is a more clever way to to this) 758 // (Surely there is a more clever way to to this)
758 double skydir_ra = skydir.ra(); 759 double skydir_ra = skydir.ra();
759 if (skydir_ra < 0) { 760 if (skydir_ra < 0) {
@@ -768,6 +769,11 @@ GSkyDir GSkyRegionRect::transform_to_local(const GSkyDir&amp; skydir) const @@ -768,6 +769,11 @@ GSkyDir GSkyRegionRect::transform_to_local(const GSkyDir&amp; skydir) const
768 double dx = skydir_ra - centre_ra; 769 double dx = skydir_ra - centre_ra;
769 double dy = skydir.dec() - m_centre.dec(); 770 double dy = skydir.dec() - m_centre.dec();
770 771
  772 + // Make sure the closest angular separation is chosen
  773 + if (std::abs(dx) > gammalib::pi) {
  774 + dx = gammalib::twopi - std::abs(dx);
  775 + }
  776 +
771 // Correction for spherical coordinate system 777 // Correction for spherical coordinate system
772 dx *= std::cos(skydir.dec()); 778 dx *= std::cos(skydir.dec());
773 779