Commit 354c133b85eb88247c25d43d4204aa273d4679b0
Committed by
Jürgen Knödlseder
1 parent
db5e2b95
Implemented containment check for rectangular sky regions in GSkyRegionMap::contains().
Showing
1 changed file
with
23 additions
and
1 deletions
src/sky/GSkyRegionMap.cpp
| ... | ... | @@ -446,10 +446,32 @@ bool GSkyRegionMap::contains(const GSkyRegion& reg) const |
| 446 | 446 | |
| 447 | 447 | } // endcase: circular region |
| 448 | 448 | |
| 449 | + // Case of a rectangular region | |
| 450 | + else if (reg.type() == "Rect") { | |
| 451 | + | |
| 452 | + // Create rectangular region from reg | |
| 453 | + const GSkyRegionRect* rect = dynamic_cast<const GSkyRegionRect*>(®); | |
| 454 | + | |
| 455 | + // Create region map from rectangle | |
| 456 | + GSkyRegionMap rect_map(rect); | |
| 457 | + | |
| 458 | + // Retrieve map data | |
| 459 | + const GSkyMap& regmap = rect_map.map(); | |
| 460 | + const std::vector<int>& regnzvec = rect_map.nonzero_indices(); | |
| 461 | + | |
| 462 | + // Loop over input map non-zero pixels and check if they are all in | |
| 463 | + for (int i = 0; i < regnzvec.size(); ++i) { | |
| 464 | + if (!contains(regmap.inx2dir(regnzvec[i]))) { | |
| 465 | + inside = false; | |
| 466 | + break; | |
| 467 | + } | |
| 468 | + } | |
| 469 | + } // endcase: rectangular region | |
| 470 | + | |
| 449 | 471 | // Other cases not implemented |
| 450 | 472 | else { |
| 451 | 473 | throw GException::feature_not_implemented(G_CONTAINS, |
| 452 | - "Method only implemented for cicular and map regions."); | |
| 474 | + "Method only implemented for cicular, rectangular and map regions."); | |
| 453 | 475 | } |
| 454 | 476 | |
| 455 | 477 | // Return result | ... | ... |