Commit 6aadb3f365990a5a8db8eb773c52bf7370f9e691
Committed by
Jürgen Knödlseder
1 parent
d98fb34f
Adapted contains() method to use local coordinate system.
Showing
1 changed file
with
8 additions
and
13 deletions
src/sky/GSkyRegionRect.cpp
| @@ -555,30 +555,25 @@ std::string GSkyRegionRect::print(const GChatter& chatter) const | @@ -555,30 +555,25 @@ std::string GSkyRegionRect::print(const GChatter& chatter) const | ||
| 555 | * @param[in] dir Sky direction. | 555 | * @param[in] dir Sky direction. |
| 556 | * | 556 | * |
| 557 | * A sky direction lies within a region when its distance to the region | 557 | * A sky direction lies within a region when its distance to the region |
| 558 | - * centre is not larger than the region radius. | 558 | + * centre is not larger than the region extension in both axes directions. |
| 559 | ***************************************************************************/ | 559 | ***************************************************************************/ |
| 560 | bool GSkyRegionRect::contains(const GSkyDir& dir) const | 560 | bool GSkyRegionRect::contains(const GSkyDir& dir) const |
| 561 | { | 561 | { |
| 562 | // Initialise return value | 562 | // Initialise return value |
| 563 | bool dir_is_in = false; | 563 | bool dir_is_in = false; |
| 564 | 564 | ||
| 565 | - // std::cout<<"GSkyRegionRect::contains: (1/2) dec: "<<m_centre.dec_deg()-m_halfheight<<"<="<<dir.dec_deg()<<"<="<<m_centre.dec_deg()+m_halfheight<<std::endl; | 565 | + // Compute sky direction in local coordinate system |
| 566 | + GSkyDir local_dir = transform_to_local(dir); | ||
| 566 | 567 | ||
| 567 | - // Check dec axis | ||
| 568 | - if ((dir.dec_deg()<=(m_centre.dec_deg() + m_halfheight)) && | ||
| 569 | - (dir.dec_deg()>=(m_centre.dec_deg() - m_halfheight))) { | 568 | + // Check containment: declination axis |
| 569 | + if (std::abs(local_dir.dec_deg()) <= m_halfheight) { | ||
| 570 | 570 | ||
| 571 | - // Compute width scaled for declination of queried skydir | ||
| 572 | - double scale = std::cos(dir.dec()); | ||
| 573 | - double half_width_scaled = m_halfwidth/scale; | 571 | + // Check containment: right ascension axis |
| 572 | + if (std::abs(local_dir.ra_deg()) <= m_halfwidth) { | ||
| 574 | 573 | ||
| 575 | - // Check ra axis | ||
| 576 | - if ((dir.ra_deg()<=(m_centre.ra_deg() + half_width_scaled)) && | ||
| 577 | - (dir.ra_deg()>=(m_centre.ra_deg() - half_width_scaled))) { | 574 | + // Sky direction is inside the rectangle |
| 578 | dir_is_in = true; | 575 | dir_is_in = true; |
| 579 | } | 576 | } |
| 580 | - | ||
| 581 | - // std::cout<<"GSkyRegionRect::contains: (2/2) ra: "<<m_centre.ra_deg()-half_width_scaled<<"<="<<dir.ra_deg()<<"<="<<m_centre.ra_deg()+half_width_scaled<<std::endl; | ||
| 582 | } | 577 | } |
| 583 | 578 | ||
| 584 | // Return bool | 579 | // Return bool |