Commit 0d4379fc828772cf008982a010305f50e189a016

Authored by Andreas Specovius
Committed by Jürgen Knödlseder
1 parent 84a24dfa

Implemented check for containment of rectangle in circle via the rectangle corne…

…rs (method GSkyRegionCircle::contains(GSkyRegion))
Showing 1 changed file with 21 additions and 3 deletions
src/sky/GSkyRegionCircle.cpp
... ... @@ -29,6 +29,7 @@
29 29 #include <config.h>
30 30 #endif
31 31 #include "GSkyRegionCircle.hpp"
  32 +#include "GSkyRegionRect.hpp"
32 33 #include "GTools.hpp"
33 34  
34 35 /* __ Method name definitions ____________________________________________ */
... ... @@ -538,17 +539,34 @@ bool GSkyRegionCircle::contains(const GSkyRegion&amp; reg) const
538 539 // Calculate angular distance between the centres
539 540 double ang_dist = m_centre.dist_deg(regcirc->centre());
540 541  
  542 + // Calculate angular distance between the centres
  543 + double ang_dist = m_centre.dist_deg(regcirc->centre());
  544 +
541 545 // Check if the region is contained in this
542 546 if ((ang_dist + regcirc->radius()) <= m_radius) {
543 547 fully_inside = true;
544 548 }
545   -
  549 +
  550 + }
  551 +
  552 + // If other region is rectangle check corners
  553 + else if (reg.type() == "Rect") {
  554 +
  555 + // Create rectangular region from reg
  556 + const GSkyRegionRect* regrect =
  557 + dynamic_cast<const GSkyRegionRect*>(&reg);
  558 +
  559 + // Check containment of all edges
  560 + fully_inside = contains(regrect->get_corner(0)) &
  561 + contains(regrect->get_corner(1)) &
  562 + contains(regrect->get_corner(2)) &
  563 + contains(regrect->get_corner(3));
546 564 }
547   -
  565 +
548 566 // ... otherwise throw an exception
549 567 else {
550 568 throw GException::feature_not_implemented(G_CONTAINS,
551   - "Cannot compare two different region types yet");
  569 + "Cannot compare to region type \""+reg.type()+"\" yet");
552 570 }
553 571  
554 572 // Return value
... ...