Commit 583acb24044a9b8e8dcc5e5d3fb6a5acc9227795

Authored by Maria Krause
1 parent 06869a15

test_GSky circle and ring overlap

include/GSkyRegionRing.hpp
@@ -94,9 +94,10 @@ protected: @@ -94,9 +94,10 @@ protected:
94 void compute_solid_angle(void); 94 void compute_solid_angle(void);
95 95
96 // Protected members 96 // Protected members
97 - GSkyDir m_centre; //!< Centre or reference point of the region  
98 - double m_radius1; //!< Radius of inner ring the region [deg]  
99 - double m_radius2; //!< Radius of outer ring the region [deg] 97 + GSkyDir m_centre; //!< Centre or reference point of the region
  98 + double m_radius1; //!< Radius of inner ring the region [deg]
  99 + double m_radius2; //!< Radius of outer ring the region [deg]
  100 +
100 }; 101 };
101 102
102 103
src/sky/GSkyRegionCircle.cpp
@@ -29,6 +29,7 @@ @@ -29,6 +29,7 @@
29 #include <config.h> 29 #include <config.h>
30 #endif 30 #endif
31 #include "GSkyRegionCircle.hpp" 31 #include "GSkyRegionCircle.hpp"
  32 +#include "GSkyRegionRing.hpp"
32 #include "GTools.hpp" 33 #include "GTools.hpp"
33 34
34 /* __ Method name definitions ____________________________________________ */ 35 /* __ Method name definitions ____________________________________________ */
@@ -522,6 +523,28 @@ bool GSkyRegionCircle::overlaps(const GSkyRegion&amp; reg) const @@ -522,6 +523,28 @@ bool GSkyRegionCircle::overlaps(const GSkyRegion&amp; reg) const
522 523
523 } 524 }
524 525
  526 + // If other region is ring use a simple way to calculate
  527 + else if (reg.type() == "Ring") {
  528 +
  529 + // Create circular region from reg
  530 + const GSkyRegionRing* regring =
  531 + dynamic_cast<const GSkyRegionRing*>(&reg);
  532 +
  533 + // Calculate angular distance between the centres
  534 + double ang_dist = m_centre.dist_deg(regring->centre());
  535 +
  536 + // Check if the distance is smaller than the sum of the outer radii and the circular radii
  537 + if (ang_dist <= (m_radius + regring->radius2())) {
  538 + overlap = true;
  539 + }
  540 +
  541 + // Check if two regions overlap
  542 + if ((ang_dist + m_radius) < regring->radius1()) {
  543 + overlap = true;
  544 + }
  545 +
  546 + }
  547 +
525 // ... otherwise throw an exception 548 // ... otherwise throw an exception
526 else { 549 else {
527 throw GException::feature_not_implemented(G_OVERLAPS, 550 throw GException::feature_not_implemented(G_OVERLAPS,
src/sky/GSkyRegionRing.cpp
@@ -29,6 +29,7 @@ @@ -29,6 +29,7 @@
29 #include <config.h> 29 #include <config.h>
30 #endif 30 #endif
31 #include "GSkyRegionRing.hpp" 31 #include "GSkyRegionRing.hpp"
  32 +#include "GSkyRegionCircle.hpp"
32 #include "GTools.hpp" 33 #include "GTools.hpp"
33 34
34 /* __ Method name definitions ____________________________________________ */ 35 /* __ Method name definitions ____________________________________________ */
@@ -136,7 +137,6 @@ GSkyRegionRing::GSkyRegionRing(const std::string&amp; line) @@ -136,7 +137,6 @@ GSkyRegionRing::GSkyRegionRing(const std::string&amp; line)
136 137
137 } 138 }
138 139
139 -  
140 /***********************************************************************//** 140 /***********************************************************************//**
141 * @brief Copy constructor 141 * @brief Copy constructor
142 * 142 *
@@ -498,16 +498,21 @@ bool GSkyRegionRing::contains(const GSkyRegion&amp; reg) const @@ -498,16 +498,21 @@ bool GSkyRegionRing::contains(const GSkyRegion&amp; reg) const
498 if (reg.type() == "Ring") { 498 if (reg.type() == "Ring") {
499 499
500 // Create circular region from reg 500 // Create circular region from reg
501 - const GSkyRegionRing* regcirc = 501 + const GSkyRegionRing* regring =
502 dynamic_cast<const GSkyRegionRing*>(&reg); 502 dynamic_cast<const GSkyRegionRing*>(&reg);
503 503
504 // Calculate angular distance between the centres 504 // Calculate angular distance between the centres
505 - double ang_dist = m_centre.dist_deg(regcirc->centre()); 505 + double ang_dist = m_centre.dist_deg(regring->centre());
506 506
507 // Check if the region is contained in this 507 // Check if the region is contained in this
508 - if ((ang_dist + regcirc->radius2()) <= m_radius2 && (ang_dist - regcirc->radius1()) >= m_radius1) { 508 + if ((ang_dist + regring->radius2()) <= m_radius2 && (ang_dist - regring->radius2()) >= m_radius1) {
509 fully_inside = true; 509 fully_inside = true;
510 } 510 }
  511 +
  512 + if ( (ang_dist + m_radius1) <= regring->radius1() && (ang_dist + regring->radius2()) <= m_radius2) {
  513 + fully_inside = true;
  514 + }
  515 +
511 516
512 } 517 }
513 518
@@ -539,24 +544,45 @@ bool GSkyRegionRing::overlaps(const GSkyRegion&amp; reg) const @@ -539,24 +544,45 @@ bool GSkyRegionRing::overlaps(const GSkyRegion&amp; reg) const
539 if (reg.type() == "Ring") { 544 if (reg.type() == "Ring") {
540 545
541 // Create circular region from reg 546 // Create circular region from reg
542 - const GSkyRegionRing* regcirc = 547 + const GSkyRegionRing* regring =
543 dynamic_cast<const GSkyRegionRing*>(&reg); 548 dynamic_cast<const GSkyRegionRing*>(&reg);
544 549
545 // Calculate angular distance between the centres 550 // Calculate angular distance between the centres
546 - double ang_dist = m_centre.dist_deg(regcirc->centre()); 551 + double ang_dist = m_centre.dist_deg(regring->centre());
547 552
548 // Check if the distance is smaller than the sum of both outer radii 553 // Check if the distance is smaller than the sum of both outer radii
549 - if (ang_dist <= (m_radius2 + regcirc->radius2())) { 554 + if (ang_dist <= (m_radius2 + regring->radius2())) {
550 overlap = true; 555 overlap = true;
551 } 556 }
552 557
553 // Check if the distance is smaller than the sum of both inner radii 558 // Check if the distance is smaller than the sum of both inner radii
554 - if (ang_dist <= (m_radius1 + regcirc->radius1())) { 559 + if (ang_dist <= (m_radius1 + regring->radius1())) {
555 overlap = true; 560 overlap = true;
556 } 561 }
557 562
558 // Check if two regions overlap 563 // Check if two regions overlap
559 - if (ang_dist >= (m_radius1 + regcirc->radius1()) && ang_dist <= (m_radius2 + regcirc->radius2())) { 564 + if (ang_dist >= (m_radius1 + regring->radius1()) && ang_dist <= (m_radius2 + regring->radius2())) {
  565 + overlap = true;
  566 + }
  567 +
  568 + }
  569 + // If other region is Circle use a simple way to calculate
  570 + else if (reg.type() == "Circle") {
  571 +
  572 + // Create circular region from reg
  573 + const GSkyRegionCircle* regcirc =
  574 + dynamic_cast<const GSkyRegionCircle*>(&reg);
  575 +
  576 + // Calculate angular distance between the centres
  577 + double ang_dist = m_centre.dist_deg(regcirc->centre());
  578 +
  579 + // Check if the distance is smaller than the sum of the outer radii and the circular radii
  580 + if (ang_dist <= (m_radius2 + regcirc->radius())) {
  581 + overlap = true;
  582 + }
  583 +
  584 + // Check if two regions overlap
  585 + if ((ang_dist + m_radius2) < regcirc->radius()) {
560 overlap = true; 586 overlap = true;
561 } 587 }
562 588
@@ -599,7 +625,7 @@ void GSkyRegionRing::init_members(void) @@ -599,7 +625,7 @@ void GSkyRegionRing::init_members(void)
599 /***********************************************************************//** 625 /***********************************************************************//**
600 * @brief Copy class members 626 * @brief Copy class members
601 * 627 *
602 - * @param[in] region Circular sky region. 628 + * @param[in] region ring sky region.
603 ***************************************************************************/ 629 ***************************************************************************/
604 void GSkyRegionRing::copy_members(const GSkyRegionRing& region) 630 void GSkyRegionRing::copy_members(const GSkyRegionRing& region)
605 { 631 {
@@ -637,4 +663,4 @@ void GSkyRegionRing::compute_solid_angle(void) @@ -637,4 +663,4 @@ void GSkyRegionRing::compute_solid_angle(void)
637 663
638 // Return 664 // Return
639 return; 665 return;
640 -} 666 -}
  667 +}
641 \ No newline at end of file 668 \ No newline at end of file
test/test_GSky.cpp
@@ -929,6 +929,12 @@ void TestGSky::test_GSkyRegionCircle_logic(void) @@ -929,6 +929,12 @@ void TestGSky::test_GSkyRegionCircle_logic(void)
929 GSkyRegionCircle refregion_raoffset(refdir_raoffset,10); 929 GSkyRegionCircle refregion_raoffset(refdir_raoffset,10);
930 GSkyRegionCircle refregion_rapole(refdir_rapole,3); 930 GSkyRegionCircle refregion_rapole(refdir_rapole,3);
931 GSkyRegionCircle refregion_decpole(refdir_decpole,3); 931 GSkyRegionCircle refregion_decpole(refdir_decpole,3);
  932 +
  933 + GSkyRegionRing refregion_ring_smaller(refdir_radeczerozero,6,8);
  934 + GSkyRegionRing refregion_ring_larger(refdir_radeczerozero,20,25);
  935 + GSkyRegionRing refregion_ring_raoffset(refdir_raoffset,10,20);
  936 + GSkyRegionRing refregion_ring_rapole(refdir_rapole,3,6);
  937 + GSkyRegionRing refregion_ring_decpole(refdir_decpole,3,5);
932 938
933 // Test contain dirs 939 // Test contain dirs
934 test_assert(refregion.contains(refdir_radeczerozero),"test for containment"); 940 test_assert(refregion.contains(refdir_radeczerozero),"test for containment");
@@ -949,6 +955,12 @@ void TestGSky::test_GSkyRegionCircle_logic(void) @@ -949,6 +955,12 @@ void TestGSky::test_GSkyRegionCircle_logic(void)
949 test_assert(refregion.overlaps(refregion_raoffset),"test3 for overlap"); 955 test_assert(refregion.overlaps(refregion_raoffset),"test3 for overlap");
950 test_assert(!refregion.overlaps(refregion_decpole),"test4 for overlap"); 956 test_assert(!refregion.overlaps(refregion_decpole),"test4 for overlap");
951 957
  958 + test_assert(refregion.overlaps(refregion_ring_smaller),"test5 for overlap");
  959 + test_assert(refregion.overlaps(refregion_ring_larger),"test6 for overlap");
  960 + test_assert(refregion.overlaps(refregion_ring_raoffset),"test7 for overlap");
  961 + test_assert(refregion.overlaps(refregion_ring_rapole),"test8 for overlap");
  962 + test_assert(!refregion.overlaps(refregion_ring_decpole),"test9 for overlap");
  963 +
952 // Exit test 964 // Exit test
953 return; 965 return;
954 } 966 }
@@ -1167,6 +1179,12 @@ void TestGSky::test_GSkyRegionRing_logic(void) @@ -1167,6 +1179,12 @@ void TestGSky::test_GSkyRegionRing_logic(void)
1167 GSkyRegionRing refregion_raoffset(refdir_raoffset,10,20); 1179 GSkyRegionRing refregion_raoffset(refdir_raoffset,10,20);
1168 GSkyRegionRing refregion_rapole(refdir_rapole,3,6); 1180 GSkyRegionRing refregion_rapole(refdir_rapole,3,6);
1169 GSkyRegionRing refregion_decpole(refdir_decpole,3,5); 1181 GSkyRegionRing refregion_decpole(refdir_decpole,3,5);
  1182 +
  1183 + GSkyRegionCircle refregion_circle_smaller(refdir_radeczerozero,12);
  1184 + GSkyRegionCircle refregion_circle_larger(refdir_radeczerozero,12);
  1185 + GSkyRegionCircle refregion_circle_raoffset(refdir_raoffset,12);
  1186 + GSkyRegionCircle refregion_circle_rapole(refdir_rapole,12);
  1187 + GSkyRegionCircle refregion_circle_decpole(refdir_decpole,12);
1170 1188
1171 // Test contain dirs 1189 // Test contain dirs
1172 test_assert(!refregion.contains(refdir_radeczerozero),"test for containment"); 1190 test_assert(!refregion.contains(refdir_radeczerozero),"test for containment");
@@ -1175,9 +1193,9 @@ void TestGSky::test_GSkyRegionRing_logic(void) @@ -1175,9 +1193,9 @@ void TestGSky::test_GSkyRegionRing_logic(void)
1175 test_assert(!refregion.contains(refdir_outside_refregion), "test2 for containment"); 1193 test_assert(!refregion.contains(refdir_outside_refregion), "test2 for containment");
1176 1194
1177 // Test contain regions 1195 // Test contain regions
1178 - test_assert(!refregion.contains(refregion_smaller),"test for containment region"); 1196 + test_assert(refregion.contains(refregion_smaller),"test for containment region");
1179 test_assert(!refregion.contains(refregion_larger), "test for containment region2 "); 1197 test_assert(!refregion.contains(refregion_larger), "test for containment region2 ");
1180 - test_assert(!refregion.contains(refregion), "test3 for containment region"); 1198 + test_assert(refregion.contains(refregion), "test3 for containment region");
1181 1199
1182 test_assert(!refregion.contains(refdir_rapole), "rapole for containment region"); 1200 test_assert(!refregion.contains(refdir_rapole), "rapole for containment region");
1183 test_assert(!refregion_decpole.contains(refdir_ndecpole), "rapole for containment region"); 1201 test_assert(!refregion_decpole.contains(refdir_ndecpole), "rapole for containment region");
@@ -1187,6 +1205,13 @@ void TestGSky::test_GSkyRegionRing_logic(void) @@ -1187,6 +1205,13 @@ void TestGSky::test_GSkyRegionRing_logic(void)
1187 test_assert(refregion.overlaps(refregion_larger),"test2 for overlap"); 1205 test_assert(refregion.overlaps(refregion_larger),"test2 for overlap");
1188 test_assert(refregion.overlaps(refregion_raoffset),"test3 for overlap"); 1206 test_assert(refregion.overlaps(refregion_raoffset),"test3 for overlap");
1189 test_assert(!refregion.overlaps(refregion_decpole),"test4 for overlap"); 1207 test_assert(!refregion.overlaps(refregion_decpole),"test4 for overlap");
  1208 +
  1209 + test_assert(refregion.overlaps(refregion_circle_smaller),"test5 for overlap");
  1210 + test_assert(refregion.overlaps(refregion_circle_larger),"test6 for overlap");
  1211 + test_assert(refregion.overlaps(refregion_circle_raoffset),"test7 for overlap");
  1212 + test_assert(refregion.overlaps(refregion_circle_rapole),"test8 for overlap");
  1213 + test_assert(!refregion.overlaps(refregion_circle_decpole),"test9 for overlap");
  1214 +
1190 1215
1191 // Exit test 1216 // Exit test
1192 return; 1217 return;