Commit 99bf5feab754ec84fce94a08035e6a80f55e95f9
1 parent
4de3cefa
Convert tabs into spaces
Showing
4 changed files
with
213 additions
and
215 deletions
src/sky/GSkyRegion.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GSkyRegion.cpp - Abstract virtual sky region base class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2013 by Pierrick Martin * | |
| 4 | + * copyright (C) 2013-2020 by Pierrick Martin * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -137,7 +137,7 @@ void GSkyRegion::init_members(void) |
| 137 | 137 | { |
| 138 | 138 | // Initialise members |
| 139 | 139 | m_type.clear(); |
| 140 | - m_name.clear(); | |
| 140 | + m_name.clear(); | |
| 141 | 141 | m_solid = 0.0; |
| 142 | 142 | |
| 143 | 143 | // Return |
| ... | ... | @@ -154,7 +154,7 @@ void GSkyRegion::copy_members(const GSkyRegion& region) |
| 154 | 154 | { |
| 155 | 155 | // Copy members |
| 156 | 156 | m_type = region.m_type; |
| 157 | - m_name = region.m_name; | |
| 157 | + m_name = region.m_name; | |
| 158 | 158 | m_solid = region.m_solid; |
| 159 | 159 | |
| 160 | 160 | // Return | ... | ... |
src/sky/GSkyRegionCircle.cpp
| ... | ... | @@ -75,14 +75,14 @@ GSkyRegionCircle::GSkyRegionCircle(const GSkyDir& centre, const double& radius) |
| 75 | 75 | GSkyRegion() |
| 76 | 76 | { |
| 77 | 77 | // Initialise members |
| 78 | - init_members(); | |
| 78 | + init_members(); | |
| 79 | 79 | |
| 80 | - // Set members | |
| 81 | - this->centre(centre); | |
| 80 | + // Set members | |
| 81 | + this->centre(centre); | |
| 82 | 82 | this->radius(radius); |
| 83 | 83 | |
| 84 | - // Compute solid angle | |
| 85 | - compute_solid_angle(); | |
| 84 | + // Compute solid angle | |
| 85 | + compute_solid_angle(); | |
| 86 | 86 | |
| 87 | 87 | // Return |
| 88 | 88 | return; |
| ... | ... | @@ -100,14 +100,14 @@ GSkyRegionCircle::GSkyRegionCircle(const double& ra, const double& dec, |
| 100 | 100 | const double& radius) : GSkyRegion() |
| 101 | 101 | { |
| 102 | 102 | // Initialise members |
| 103 | - init_members(); | |
| 103 | + init_members(); | |
| 104 | 104 | |
| 105 | - // Set members | |
| 106 | - this->centre(ra, dec); | |
| 105 | + // Set members | |
| 106 | + this->centre(ra, dec); | |
| 107 | 107 | this->radius(radius); |
| 108 | 108 | |
| 109 | - // Compute solid angle | |
| 110 | - compute_solid_angle(); | |
| 109 | + // Compute solid angle | |
| 110 | + compute_solid_angle(); | |
| 111 | 111 | |
| 112 | 112 | // Return |
| 113 | 113 | return; |
| ... | ... | @@ -123,14 +123,14 @@ GSkyRegionCircle::GSkyRegionCircle(const double& ra, const double& dec, |
| 123 | 123 | ***************************************************************************/ |
| 124 | 124 | GSkyRegionCircle::GSkyRegionCircle(const std::string& line) : GSkyRegion() |
| 125 | 125 | { |
| 126 | - // Initialise members | |
| 127 | - init_members(); | |
| 126 | + // Initialise members | |
| 127 | + init_members(); | |
| 128 | 128 | |
| 129 | - // Read information from DS9 region file line | |
| 130 | - read(line); | |
| 129 | + // Read information from DS9 region file line | |
| 130 | + read(line); | |
| 131 | 131 | |
| 132 | - // Return | |
| 133 | - return; | |
| 132 | + // Return | |
| 133 | + return; | |
| 134 | 134 | |
| 135 | 135 | } |
| 136 | 136 | |
| ... | ... | @@ -252,14 +252,15 @@ GSkyRegionCircle* GSkyRegionCircle::clone(void) const |
| 252 | 252 | ***************************************************************************/ |
| 253 | 253 | void GSkyRegionCircle::radius(const double& radius) |
| 254 | 254 | { |
| 255 | - if (radius < 0.0) { | |
| 255 | + // Check if radius is valid | |
| 256 | + if (radius < 0.0) { | |
| 256 | 257 | std::string msg = |
| 257 | 258 | "A radius of "+gammalib::str(radius)+" degrees has been" |
| 258 | 259 | " specified for a circular sky region.\n" |
| 259 | 260 | "The radius of a circular sky region can't be less than 0" |
| 260 | 261 | " degrees."; |
| 261 | - throw GException::invalid_argument(G_RADIUS, msg); | |
| 262 | - } | |
| 262 | + throw GException::invalid_argument(G_RADIUS, msg); | |
| 263 | + } | |
| 263 | 264 | |
| 264 | 265 | // Set radius value |
| 265 | 266 | m_radius = radius; |
| ... | ... | @@ -282,44 +283,44 @@ void GSkyRegionCircle::radius(const double& radius) |
| 282 | 283 | ***************************************************************************/ |
| 283 | 284 | void GSkyRegionCircle::read(const std::string& line) |
| 284 | 285 | { |
| 285 | - // Clear the current instance | |
| 286 | - clear(); | |
| 286 | + // Clear the current instance | |
| 287 | + clear(); | |
| 287 | 288 | |
| 288 | - // Split the string into 2 parts seperated by # | |
| 289 | - std::vector<std::string> substrings = gammalib::split(line,"#"); | |
| 290 | - std::string region_def = (!substrings.empty()) ? substrings[0] : ""; | |
| 291 | - std::string comment = (substrings.size() > 1) ? substrings[1] : ""; | |
| 289 | + // Split the string into 2 parts seperated by # | |
| 290 | + std::vector<std::string> substrings = gammalib::split(line,"#"); | |
| 291 | + std::string region_def = (!substrings.empty()) ? substrings[0] : ""; | |
| 292 | + std::string comment = (substrings.size() > 1) ? substrings[1] : ""; | |
| 292 | 293 | |
| 293 | - // Finding the circle | |
| 294 | - if (region_def.find("circle") == std::string::npos) { | |
| 294 | + // Finding the circle | |
| 295 | + if (region_def.find("circle") == std::string::npos) { | |
| 295 | 296 | std::string msg = |
| 296 | 297 | "Unable to find the key word \"circle\" in provided string" |
| 297 | 298 | " \""+line+"\".\n" |
| 298 | 299 | "The \"circle\" key word is mandatory."; |
| 299 | - throw GException::invalid_value(G_READ, msg); | |
| 300 | - } | |
| 300 | + throw GException::invalid_value(G_READ, msg); | |
| 301 | + } | |
| 301 | 302 | |
| 302 | - // Get the the coordinate system of the values | |
| 303 | - std::string system = gammalib::split(region_def, ";")[0]; | |
| 303 | + // Get the the coordinate system of the values | |
| 304 | + std::string system = gammalib::split(region_def, ";")[0]; | |
| 304 | 305 | |
| 305 | - // Get the substring of the important values | |
| 306 | - size_t pos = region_def.find("circle("); | |
| 307 | - size_t end = region_def.find(")"); | |
| 308 | - std::string circlestring = region_def.substr(pos+7, end); | |
| 309 | - circlestring.erase(circlestring.find(")"), 1); | |
| 306 | + // Get the substring of the important values | |
| 307 | + size_t pos = region_def.find("circle("); | |
| 308 | + size_t end = region_def.find(")"); | |
| 309 | + std::string circlestring = region_def.substr(pos+7, end); | |
| 310 | + circlestring.erase(circlestring.find(")"), 1); | |
| 310 | 311 | |
| 311 | - // Get the values of the region x,y,and radius | |
| 312 | - std::vector<std::string> values = gammalib::split(circlestring,","); | |
| 313 | - if (values.size() != 3) { | |
| 312 | + // Get the values of the region x,y,and radius | |
| 313 | + std::vector<std::string> values = gammalib::split(circlestring,","); | |
| 314 | + if (values.size() != 3) { | |
| 314 | 315 | std::string msg = |
| 315 | 316 | "Invalid number of "+gammalib::str(values.size())+" arguments" |
| 316 | 317 | " after the \"circle\" key word in provided string \""+line+"\".\n" |
| 317 | 318 | "Exactly 3 arguments are expected."; |
| 318 | - throw GException::invalid_value(G_READ, msg); | |
| 319 | - } | |
| 320 | - double x = gammalib::todouble(values[0]); | |
| 321 | - double y = gammalib::todouble(values[1]); | |
| 322 | - double radius = gammalib::todouble(values[2]); | |
| 319 | + throw GException::invalid_value(G_READ, msg); | |
| 320 | + } | |
| 321 | + double x = gammalib::todouble(values[0]); | |
| 322 | + double y = gammalib::todouble(values[1]); | |
| 323 | + double radius = gammalib::todouble(values[2]); | |
| 323 | 324 | |
| 324 | 325 | // Get radius units |
| 325 | 326 | if (gammalib::contains(values[2], "'")) { |
| ... | ... | @@ -329,33 +330,33 @@ void GSkyRegionCircle::read(const std::string& line) |
| 329 | 330 | radius /= 3600.0; |
| 330 | 331 | } |
| 331 | 332 | |
| 332 | - // Initialise centre direction | |
| 333 | - GSkyDir centre = GSkyDir(); | |
| 334 | - | |
| 335 | - // Set the values in the correct system | |
| 336 | - if (system == "fk5" || system == "icrs") { | |
| 337 | - centre.radec_deg(x,y); | |
| 338 | - } | |
| 339 | - else if (system == "galactic") { | |
| 340 | - centre.lb_deg(x,y); | |
| 341 | - } | |
| 342 | - else { | |
| 333 | + // Initialise centre direction | |
| 334 | + GSkyDir centre = GSkyDir(); | |
| 335 | + | |
| 336 | + // Set the values in the correct system | |
| 337 | + if (system == "fk5" || system == "icrs") { | |
| 338 | + centre.radec_deg(x,y); | |
| 339 | + } | |
| 340 | + else if (system == "galactic") { | |
| 341 | + centre.lb_deg(x,y); | |
| 342 | + } | |
| 343 | + else { | |
| 343 | 344 | std::string msg = |
| 344 | 345 | "Unsupported coordinate system \""+system+"\" in provided string" |
| 345 | 346 | " \""+line+"\".\n" |
| 346 | 347 | "Only the following coordinate systems are supported: " |
| 347 | 348 | "\"fk5\", \"icrs\" and \"galactic\"."; |
| 348 | - throw GException::invalid_value(G_READ, msg); | |
| 349 | - } | |
| 349 | + throw GException::invalid_value(G_READ, msg); | |
| 350 | + } | |
| 350 | 351 | |
| 351 | - // Set members | |
| 352 | - this->centre(centre); | |
| 352 | + // Set members | |
| 353 | + this->centre(centre); | |
| 353 | 354 | this->radius(radius); |
| 354 | 355 | |
| 355 | - // Compute solid angle | |
| 356 | - compute_solid_angle(); | |
| 356 | + // Compute solid angle | |
| 357 | + compute_solid_angle(); | |
| 357 | 358 | |
| 358 | - // Check if there is a given name for the region and set it. Strings may | |
| 359 | + // Check if there is a given name for the region and set it. Strings may | |
| 359 | 360 | // be quoted with " or ' or {} |
| 360 | 361 | pos = comment.find("text"); |
| 361 | 362 | if (pos != std::string::npos) { |
| ... | ... | @@ -418,8 +419,8 @@ void GSkyRegionCircle::read(const std::string& line) |
| 418 | 419 | |
| 419 | 420 | } // endif: text attribute found |
| 420 | 421 | |
| 421 | - // Return | |
| 422 | - return; | |
| 422 | + // Return | |
| 423 | + return; | |
| 423 | 424 | } |
| 424 | 425 | |
| 425 | 426 | |
| ... | ... | @@ -434,16 +435,16 @@ void GSkyRegionCircle::read(const std::string& line) |
| 434 | 435 | std::string GSkyRegionCircle::write(void) const |
| 435 | 436 | { |
| 436 | 437 | // Allocate string |
| 437 | - std::string result; | |
| 438 | + std::string result; | |
| 438 | 439 | |
| 439 | 440 | // Set string |
| 440 | - result.append("fk5;circle("); | |
| 441 | - result.append(gammalib::str(m_centre.ra_deg())); | |
| 442 | - result.append(","); | |
| 443 | - result.append(gammalib::str(m_centre.dec_deg())); | |
| 444 | - result.append(","); | |
| 445 | - result.append(gammalib::str(m_radius)); | |
| 446 | - result.append(")"); | |
| 441 | + result.append("fk5;circle("); | |
| 442 | + result.append(gammalib::str(m_centre.ra_deg())); | |
| 443 | + result.append(","); | |
| 444 | + result.append(gammalib::str(m_centre.dec_deg())); | |
| 445 | + result.append(","); | |
| 446 | + result.append(gammalib::str(m_radius)); | |
| 447 | + result.append(")"); | |
| 447 | 448 | |
| 448 | 449 | // Optionally add region name |
| 449 | 450 | if (m_name.length() > 0) { |
| ... | ... | @@ -454,7 +455,7 @@ std::string GSkyRegionCircle::write(void) const |
| 454 | 455 | } |
| 455 | 456 | |
| 456 | 457 | // Return string |
| 457 | - return result; | |
| 458 | + return result; | |
| 458 | 459 | } |
| 459 | 460 | |
| 460 | 461 | |
| ... | ... | @@ -473,7 +474,7 @@ std::string GSkyRegionCircle::print(const GChatter& chatter) const |
| 473 | 474 | if (chatter != SILENT) { |
| 474 | 475 | |
| 475 | 476 | // Append header |
| 476 | - result.append("=== GSkyRegionCircle ==="); | |
| 477 | + result.append("=== GSkyRegionCircle ==="); | |
| 477 | 478 | |
| 478 | 479 | // Append sky circle information |
| 479 | 480 | result.append("\n"+gammalib::parformat("Right Ascension of centre")); |
| ... | ... | @@ -499,19 +500,19 @@ std::string GSkyRegionCircle::print(const GChatter& chatter) const |
| 499 | 500 | ***************************************************************************/ |
| 500 | 501 | bool GSkyRegionCircle::contains(const GSkyDir& dir) const |
| 501 | 502 | { |
| 502 | - // Initialise return value | |
| 503 | - bool dir_is_in = false; | |
| 503 | + // Initialise return value | |
| 504 | + bool dir_is_in = false; | |
| 504 | 505 | |
| 505 | - // calculate distance from dir to centre | |
| 506 | - double distance = dir.dist_deg(m_centre); | |
| 506 | + // calculate distance from dir to centre | |
| 507 | + double distance = dir.dist_deg(m_centre); | |
| 507 | 508 | |
| 508 | - // Check if distance < radius | |
| 509 | - if (distance <= radius()) { | |
| 510 | - dir_is_in = true; | |
| 511 | - } | |
| 509 | + // Check if distance < radius | |
| 510 | + if (distance <= radius()) { | |
| 511 | + dir_is_in = true; | |
| 512 | + } | |
| 512 | 513 | |
| 513 | - // Return bool | |
| 514 | - return dir_is_in; | |
| 514 | + // Return bool | |
| 515 | + return dir_is_in; | |
| 515 | 516 | } |
| 516 | 517 | |
| 517 | 518 | /***********************************************************************//** |
| ... | ... | @@ -524,34 +525,34 @@ bool GSkyRegionCircle::contains(const GSkyDir& dir) const |
| 524 | 525 | ***************************************************************************/ |
| 525 | 526 | bool GSkyRegionCircle::contains(const GSkyRegion& reg) const |
| 526 | 527 | { |
| 527 | - // Initialise return value | |
| 528 | - bool fully_inside = false; | |
| 528 | + // Initialise return value | |
| 529 | + bool fully_inside = false; | |
| 529 | 530 | |
| 530 | - // If other region is circle use a simple way to calculate | |
| 531 | - if (reg.type() == "Circle") { | |
| 531 | + // If other region is circle use a simple way to calculate | |
| 532 | + if (reg.type() == "Circle") { | |
| 532 | 533 | |
| 533 | - // Create circular region from reg | |
| 534 | - const GSkyRegionCircle* regcirc = | |
| 534 | + // Create circular region from reg | |
| 535 | + const GSkyRegionCircle* regcirc = | |
| 535 | 536 | dynamic_cast<const GSkyRegionCircle*>(®); |
| 536 | 537 | |
| 537 | - // Calculate angular distance between the centres | |
| 538 | - double ang_dist = m_centre.dist_deg(regcirc->centre()); | |
| 538 | + // Calculate angular distance between the centres | |
| 539 | + double ang_dist = m_centre.dist_deg(regcirc->centre()); | |
| 539 | 540 | |
| 540 | - // Check if the region is contained in this | |
| 541 | - if ((ang_dist + regcirc->radius()) <= m_radius) { | |
| 542 | - fully_inside = true; | |
| 543 | - } | |
| 541 | + // Check if the region is contained in this | |
| 542 | + if ((ang_dist + regcirc->radius()) <= m_radius) { | |
| 543 | + fully_inside = true; | |
| 544 | + } | |
| 544 | 545 | |
| 545 | - } | |
| 546 | + } | |
| 546 | 547 | |
| 547 | 548 | // ... otherwise throw an exception |
| 548 | - else { | |
| 549 | - throw GException::feature_not_implemented(G_CONTAINS, | |
| 549 | + else { | |
| 550 | + throw GException::feature_not_implemented(G_CONTAINS, | |
| 550 | 551 | "Cannot compare two different region types yet"); |
| 551 | - } | |
| 552 | - | |
| 553 | - // Return value | |
| 554 | - return fully_inside; | |
| 552 | + } | |
| 553 | + | |
| 554 | + // Return value | |
| 555 | + return fully_inside; | |
| 555 | 556 | } |
| 556 | 557 | |
| 557 | 558 | |
| ... | ... | @@ -565,34 +566,34 @@ bool GSkyRegionCircle::contains(const GSkyRegion& reg) const |
| 565 | 566 | ***************************************************************************/ |
| 566 | 567 | bool GSkyRegionCircle::overlaps(const GSkyRegion& reg) const |
| 567 | 568 | { |
| 568 | - // Initialise return value | |
| 569 | - bool overlap = false; | |
| 569 | + // Initialise return value | |
| 570 | + bool overlap = false; | |
| 570 | 571 | |
| 571 | - // If other region is circle use a simple way to calculate | |
| 572 | - if (reg.type() == "Circle") { | |
| 572 | + // If other region is circle use a simple way to calculate | |
| 573 | + if (reg.type() == "Circle") { | |
| 573 | 574 | |
| 574 | - // Create circular region from reg | |
| 575 | - const GSkyRegionCircle* regcirc = | |
| 575 | + // Create circular region from reg | |
| 576 | + const GSkyRegionCircle* regcirc = | |
| 576 | 577 | dynamic_cast<const GSkyRegionCircle*>(®); |
| 577 | 578 | |
| 578 | - // Calculate angular distance between the centres | |
| 579 | - double ang_dist = m_centre.dist_deg(regcirc->centre()); | |
| 579 | + // Calculate angular distance between the centres | |
| 580 | + double ang_dist = m_centre.dist_deg(regcirc->centre()); | |
| 580 | 581 | |
| 581 | - // Check if the distance is smaller than the sum of both radii | |
| 582 | - if (ang_dist <= (m_radius + regcirc->radius())) { | |
| 583 | - overlap = true; | |
| 584 | - } | |
| 585 | - | |
| 586 | - } | |
| 582 | + // Check if the distance is smaller than the sum of both radii | |
| 583 | + if (ang_dist <= (m_radius + regcirc->radius())) { | |
| 584 | + overlap = true; | |
| 585 | + } | |
| 586 | + | |
| 587 | + } | |
| 587 | 588 | |
| 588 | 589 | // ... otherwise throw an exception |
| 589 | - else { | |
| 590 | - throw GException::feature_not_implemented(G_OVERLAPS, | |
| 590 | + else { | |
| 591 | + throw GException::feature_not_implemented(G_OVERLAPS, | |
| 591 | 592 | "Cannot compare two different region types yet"); |
| 592 | - } | |
| 593 | + } | |
| 593 | 594 | |
| 594 | - // Return value | |
| 595 | - return overlap; | |
| 595 | + // Return value | |
| 596 | + return overlap; | |
| 596 | 597 | } |
| 597 | 598 | |
| 598 | 599 | |
| ... | ... | @@ -609,12 +610,12 @@ bool GSkyRegionCircle::overlaps(const GSkyRegion& reg) const |
| 609 | 610 | void GSkyRegionCircle::init_members(void) |
| 610 | 611 | { |
| 611 | 612 | // Initialise members |
| 612 | - m_centre = GSkyDir(); | |
| 613 | - m_radius = 0.0; | |
| 614 | - m_type = "Circle"; | |
| 613 | + m_centre = GSkyDir(); | |
| 614 | + m_radius = 0.0; | |
| 615 | + m_type = "Circle"; | |
| 615 | 616 | |
| 616 | - //Return | |
| 617 | - return; | |
| 617 | + //Return | |
| 618 | + return; | |
| 618 | 619 | } |
| 619 | 620 | |
| 620 | 621 | |
| ... | ... | @@ -625,9 +626,9 @@ void GSkyRegionCircle::init_members(void) |
| 625 | 626 | ***************************************************************************/ |
| 626 | 627 | void GSkyRegionCircle::copy_members(const GSkyRegionCircle& region) |
| 627 | 628 | { |
| 628 | - // Copy attributes | |
| 629 | - m_centre = region.m_centre; | |
| 630 | - m_radius = region.m_radius; | |
| 629 | + // Copy attributes | |
| 630 | + m_centre = region.m_centre; | |
| 631 | + m_radius = region.m_radius; | |
| 631 | 632 | |
| 632 | 633 | // Return |
| 633 | 634 | return; |
| ... | ... | @@ -649,11 +650,11 @@ void GSkyRegionCircle::free_members(void) |
| 649 | 650 | ***************************************************************************/ |
| 650 | 651 | void GSkyRegionCircle::compute_solid_angle(void) |
| 651 | 652 | { |
| 652 | - // Convert radius from degrees to radians | |
| 653 | - double radius_rad = m_radius * gammalib::deg2rad; | |
| 653 | + // Convert radius from degrees to radians | |
| 654 | + double radius_rad = m_radius * gammalib::deg2rad; | |
| 654 | 655 | |
| 655 | - // Compute solid angle | |
| 656 | - m_solid = gammalib::twopi * (1.0 - std::cos(radius_rad)); | |
| 656 | + // Compute solid angle | |
| 657 | + m_solid = gammalib::twopi * (1.0 - std::cos(radius_rad)); | |
| 657 | 658 | |
| 658 | 659 | // Return |
| 659 | 660 | return; | ... | ... |
src/sky/GSkyRegionMap.cpp
| 1 | 1 | /*************************************************************************** |
| 2 | 2 | * GSkyRegionMap.cpp - Sky region map class * |
| 3 | 3 | * ----------------------------------------------------------------------- * |
| 4 | - * copyright (C) 2017-2018 by Pierrick Martin * | |
| 4 | + * copyright (C) 2017-2020 by Pierrick Martin * | |
| 5 | 5 | * ----------------------------------------------------------------------- * |
| 6 | 6 | * * |
| 7 | 7 | * This program is free software: you can redistribute it and/or modify * |
| ... | ... | @@ -397,8 +397,8 @@ bool GSkyRegionMap::contains(const GSkyRegion& reg) const |
| 397 | 397 | // Case of a region map |
| 398 | 398 | if (reg.type() == "Map") { |
| 399 | 399 | |
| 400 | - // Cast to map type | |
| 401 | - const GSkyRegionMap* inreg = dynamic_cast<const GSkyRegionMap*>(®); | |
| 400 | + // Cast to map type | |
| 401 | + const GSkyRegionMap* inreg = dynamic_cast<const GSkyRegionMap*>(®); | |
| 402 | 402 | |
| 403 | 403 | // Retrieve map data |
| 404 | 404 | const GSkyMap& regmap = inreg->map(); |
| ... | ... | @@ -417,8 +417,8 @@ bool GSkyRegionMap::contains(const GSkyRegion& reg) const |
| 417 | 417 | // Case of a circular region |
| 418 | 418 | else if (reg.type() == "Circle") { |
| 419 | 419 | |
| 420 | - // Create circular region from reg | |
| 421 | - const GSkyRegionCircle* inreg = dynamic_cast<const GSkyRegionCircle*>(®); | |
| 420 | + // Create circular region from reg | |
| 421 | + const GSkyRegionCircle* inreg = dynamic_cast<const GSkyRegionCircle*>(®); | |
| 422 | 422 | |
| 423 | 423 | // Retrieve circle data |
| 424 | 424 | const GSkyDir& centre = inreg->centre(); | ... | ... |
src/sky/GSkyRegions.cpp
| ... | ... | @@ -422,19 +422,19 @@ void GSkyRegions::extend(const GSkyRegions& regions) |
| 422 | 422 | ***************************************************************************/ |
| 423 | 423 | bool GSkyRegions::contains(const GSkyDir& dir) const |
| 424 | 424 | { |
| 425 | - // Initialise return value | |
| 426 | - bool overlap = false; | |
| 427 | - | |
| 428 | - // Loop over regions | |
| 429 | - for (int i = 0; i < size(); ++i) { | |
| 430 | - overlap = m_regions[i]->contains(dir); | |
| 431 | - if (overlap) { | |
| 425 | + // Initialise return value | |
| 426 | + bool overlap = false; | |
| 427 | + | |
| 428 | + // Loop over regions | |
| 429 | + for (int i = 0; i < size(); ++i) { | |
| 430 | + overlap = m_regions[i]->contains(dir); | |
| 431 | + if (overlap) { | |
| 432 | 432 | break; |
| 433 | 433 | } |
| 434 | - } | |
| 435 | - | |
| 436 | - // Return result | |
| 437 | - return overlap; | |
| 434 | + } | |
| 435 | + | |
| 436 | + // Return result | |
| 437 | + return overlap; | |
| 438 | 438 | } |
| 439 | 439 | |
| 440 | 440 | |
| ... | ... | @@ -512,67 +512,67 @@ void GSkyRegions::load(const GFilename& filename) |
| 512 | 512 | // Open file. Throw an exception if opening failed. |
| 513 | 513 | std::ifstream ds9file; |
| 514 | 514 | ds9file.open(filename.url().c_str()); |
| 515 | - if (ds9file.is_open()) { | |
| 515 | + if (ds9file.is_open()) { | |
| 516 | 516 | |
| 517 | - // Loop over file lines | |
| 518 | - std::string fileline = ""; | |
| 519 | - std::string coordsys = "galactic"; | |
| 517 | + // Loop over file lines | |
| 518 | + std::string fileline = ""; | |
| 519 | + std::string coordsys = "galactic"; | |
| 520 | 520 | while (ds9file.good()) { |
| 521 | - | |
| 522 | - // Read one line | |
| 523 | - getline(ds9file,fileline); | |
| 524 | - | |
| 525 | - // If line is a comment then continue | |
| 526 | - if (fileline[0] == '#') { | |
| 521 | + | |
| 522 | + // Read one line | |
| 523 | + getline(ds9file,fileline); | |
| 524 | + | |
| 525 | + // If line is a comment then continue | |
| 526 | + if (fileline[0] == '#') { | |
| 527 | 527 | continue; |
| 528 | 528 | } |
| 529 | - | |
| 530 | - // Check for global definition of coordinate system | |
| 531 | - if (std::string::npos != fileline.find("fk5")) { | |
| 532 | - coordsys = "fk5"; | |
| 533 | - } | |
| 529 | + | |
| 530 | + // Check for global definition of coordinate system | |
| 531 | + if (std::string::npos != fileline.find("fk5")) { | |
| 532 | + coordsys = "fk5"; | |
| 533 | + } | |
| 534 | 534 | else if (std::string::npos != fileline.find("icrs")) { |
| 535 | - coordsys = "icrs"; | |
| 536 | - } | |
| 537 | - | |
| 538 | - // If region is a circle | |
| 539 | - if (std::string::npos != fileline.find("circle")) { | |
| 535 | + coordsys = "icrs"; | |
| 536 | + } | |
| 537 | + | |
| 538 | + // If region is a circle | |
| 539 | + if (std::string::npos != fileline.find("circle")) { | |
| 540 | 540 | |
| 541 | - // Create instance of GSkyRegion object | |
| 542 | - GSkyRegionCircle region; | |
| 541 | + // Create instance of GSkyRegion object | |
| 542 | + GSkyRegionCircle region; | |
| 543 | 543 | |
| 544 | - // If coordinate system and region defined on the same line | |
| 545 | - if ((std::string::npos != fileline.find("fk5")) || | |
| 544 | + // If coordinate system and region defined on the same line | |
| 545 | + if ((std::string::npos != fileline.find("fk5")) || | |
| 546 | 546 | (std::string::npos != fileline.find("icrs")) || |
| 547 | - (std::string::npos != fileline.find("galactic"))) { | |
| 548 | - region.read(fileline); | |
| 549 | - append(region); | |
| 550 | - } | |
| 547 | + (std::string::npos != fileline.find("galactic"))) { | |
| 548 | + region.read(fileline); | |
| 549 | + append(region); | |
| 550 | + } | |
| 551 | 551 | |
| 552 | - // else, prepend the coordinate system | |
| 552 | + // else, prepend the coordinate system | |
| 553 | 553 | else { |
| 554 | - std::string newfileline = coordsys; | |
| 555 | - newfileline.append("; "); | |
| 556 | - newfileline.append(fileline); | |
| 557 | - region.read(newfileline); | |
| 558 | - append(region); | |
| 559 | - } | |
| 560 | - } | |
| 561 | - } | |
| 562 | - | |
| 554 | + std::string newfileline = coordsys; | |
| 555 | + newfileline.append("; "); | |
| 556 | + newfileline.append(fileline); | |
| 557 | + region.read(newfileline); | |
| 558 | + append(region); | |
| 559 | + } | |
| 560 | + } | |
| 561 | + } | |
| 562 | + | |
| 563 | 563 | // Close file |
| 564 | 564 | ds9file.close(); |
| 565 | 565 | |
| 566 | 566 | // Store filename |
| 567 | 567 | m_filename = filename; |
| 568 | 568 | |
| 569 | - } | |
| 569 | + } | |
| 570 | 570 | |
| 571 | - // File could not be opened | |
| 571 | + // File could not be opened | |
| 572 | 572 | else { |
| 573 | 573 | throw GException::file_open_error(G_LOAD, filename.url()); |
| 574 | 574 | } |
| 575 | - | |
| 575 | + | |
| 576 | 576 | // Return |
| 577 | 577 | return; |
| 578 | 578 | } |
| ... | ... | @@ -597,34 +597,31 @@ void GSkyRegions::save(const GFilename& filename) const |
| 597 | 597 | // If file opened correctly, then save regions |
| 598 | 598 | if (ds9file.is_open()) { |
| 599 | 599 | |
| 600 | - // Write global definition | |
| 601 | - std::string fileline; | |
| 602 | - fileline.append("# Region file format: DS9 version 4.1\n"); | |
| 603 | - fileline.append("global color=green dashlist=8 3 width=1"); | |
| 604 | -// fileline.append("font=\"helvetica 10 normal\" select=1"); | |
| 605 | -// "highlite=1 dash=0 fixed=0 edit=1 move=1"+ | |
| 606 | -// "delete=1 include=1 source=1"; | |
| 607 | - ds9file << fileline << "\n"; | |
| 608 | - | |
| 609 | - // Loop over regions in container | |
| 610 | - for (int i = 0; i < size(); ++i) { | |
| 611 | - ds9file << m_regions[i]->write() << "\n"; | |
| 612 | - } | |
| 613 | - | |
| 614 | - // Close file | |
| 615 | - ds9file.close(); | |
| 600 | + // Write global definition | |
| 601 | + std::string fileline; | |
| 602 | + fileline.append("# Region file format: DS9 version 4.1\n"); | |
| 603 | + fileline.append("global color=green dashlist=8 3 width=1"); | |
| 604 | + ds9file << fileline << "\n"; | |
| 605 | + | |
| 606 | + // Loop over regions in container | |
| 607 | + for (int i = 0; i < size(); ++i) { | |
| 608 | + ds9file << m_regions[i]->write() << "\n"; | |
| 609 | + } | |
| 610 | + | |
| 611 | + // Close file | |
| 612 | + ds9file.close(); | |
| 616 | 613 | |
| 617 | 614 | // Store filename |
| 618 | 615 | m_filename = filename; |
| 619 | 616 | |
| 620 | - } | |
| 617 | + } | |
| 621 | 618 | |
| 622 | - // ... otherwise, if file could not be opened then throw an exception | |
| 619 | + // ... otherwise, if file could not be opened then throw an exception | |
| 623 | 620 | else { |
| 624 | 621 | throw GException::file_open_error(G_SAVE, filename.url()); |
| 625 | - } | |
| 626 | - | |
| 627 | - // Return | |
| 622 | + } | |
| 623 | + | |
| 624 | + // Return | |
| 628 | 625 | return; |
| 629 | 626 | } |
| 630 | 627 | ... | ... |