From 99bf5feab754ec84fce94a08035e6a80f55e95f9 Mon Sep 17 00:00:00 2001 From: Jürgen Knödlseder Date: Wed, 22 Jul 2020 11:10:07 +0200 Subject: [PATCH] Convert tabs into spaces --- src/sky/GSkyRegion.cpp | 6 +++--- src/sky/GSkyRegionCircle.cpp | 269 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++-------------------------------------------------------------------------------------------------------------------------------------- src/sky/GSkyRegionMap.cpp | 10 +++++----- src/sky/GSkyRegions.cpp | 143 ++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++------------------------------------------------------------------------- 4 files changed, 213 insertions(+), 215 deletions(-) diff --git a/src/sky/GSkyRegion.cpp b/src/sky/GSkyRegion.cpp index c51e664..4773bba 100644 --- a/src/sky/GSkyRegion.cpp +++ b/src/sky/GSkyRegion.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GSkyRegion.cpp - Abstract virtual sky region base class * * ----------------------------------------------------------------------- * - * copyright (C) 2013 by Pierrick Martin * + * copyright (C) 2013-2020 by Pierrick Martin * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -137,7 +137,7 @@ void GSkyRegion::init_members(void) { // Initialise members m_type.clear(); - m_name.clear(); + m_name.clear(); m_solid = 0.0; // Return @@ -154,7 +154,7 @@ void GSkyRegion::copy_members(const GSkyRegion& region) { // Copy members m_type = region.m_type; - m_name = region.m_name; + m_name = region.m_name; m_solid = region.m_solid; // Return diff --git a/src/sky/GSkyRegionCircle.cpp b/src/sky/GSkyRegionCircle.cpp index 46b8145..7b020d0 100644 --- a/src/sky/GSkyRegionCircle.cpp +++ b/src/sky/GSkyRegionCircle.cpp @@ -75,14 +75,14 @@ GSkyRegionCircle::GSkyRegionCircle(const GSkyDir& centre, const double& radius) GSkyRegion() { // Initialise members - init_members(); + init_members(); - // Set members - this->centre(centre); + // Set members + this->centre(centre); this->radius(radius); - // Compute solid angle - compute_solid_angle(); + // Compute solid angle + compute_solid_angle(); // Return return; @@ -100,14 +100,14 @@ GSkyRegionCircle::GSkyRegionCircle(const double& ra, const double& dec, const double& radius) : GSkyRegion() { // Initialise members - init_members(); + init_members(); - // Set members - this->centre(ra, dec); + // Set members + this->centre(ra, dec); this->radius(radius); - // Compute solid angle - compute_solid_angle(); + // Compute solid angle + compute_solid_angle(); // Return return; @@ -123,14 +123,14 @@ GSkyRegionCircle::GSkyRegionCircle(const double& ra, const double& dec, ***************************************************************************/ GSkyRegionCircle::GSkyRegionCircle(const std::string& line) : GSkyRegion() { - // Initialise members - init_members(); + // Initialise members + init_members(); - // Read information from DS9 region file line - read(line); + // Read information from DS9 region file line + read(line); - // Return - return; + // Return + return; } @@ -252,14 +252,15 @@ GSkyRegionCircle* GSkyRegionCircle::clone(void) const ***************************************************************************/ void GSkyRegionCircle::radius(const double& radius) { - if (radius < 0.0) { + // Check if radius is valid + if (radius < 0.0) { std::string msg = "A radius of "+gammalib::str(radius)+" degrees has been" " specified for a circular sky region.\n" "The radius of a circular sky region can't be less than 0" " degrees."; - throw GException::invalid_argument(G_RADIUS, msg); - } + throw GException::invalid_argument(G_RADIUS, msg); + } // Set radius value m_radius = radius; @@ -282,44 +283,44 @@ void GSkyRegionCircle::radius(const double& radius) ***************************************************************************/ void GSkyRegionCircle::read(const std::string& line) { - // Clear the current instance - clear(); + // Clear the current instance + clear(); - // Split the string into 2 parts seperated by # - std::vector substrings = gammalib::split(line,"#"); - std::string region_def = (!substrings.empty()) ? substrings[0] : ""; - std::string comment = (substrings.size() > 1) ? substrings[1] : ""; + // Split the string into 2 parts seperated by # + std::vector substrings = gammalib::split(line,"#"); + std::string region_def = (!substrings.empty()) ? substrings[0] : ""; + std::string comment = (substrings.size() > 1) ? substrings[1] : ""; - // Finding the circle - if (region_def.find("circle") == std::string::npos) { + // Finding the circle + if (region_def.find("circle") == std::string::npos) { std::string msg = "Unable to find the key word \"circle\" in provided string" " \""+line+"\".\n" "The \"circle\" key word is mandatory."; - throw GException::invalid_value(G_READ, msg); - } + throw GException::invalid_value(G_READ, msg); + } - // Get the the coordinate system of the values - std::string system = gammalib::split(region_def, ";")[0]; + // Get the the coordinate system of the values + std::string system = gammalib::split(region_def, ";")[0]; - // Get the substring of the important values - size_t pos = region_def.find("circle("); - size_t end = region_def.find(")"); - std::string circlestring = region_def.substr(pos+7, end); - circlestring.erase(circlestring.find(")"), 1); + // Get the substring of the important values + size_t pos = region_def.find("circle("); + size_t end = region_def.find(")"); + std::string circlestring = region_def.substr(pos+7, end); + circlestring.erase(circlestring.find(")"), 1); - // Get the values of the region x,y,and radius - std::vector values = gammalib::split(circlestring,","); - if (values.size() != 3) { + // Get the values of the region x,y,and radius + std::vector values = gammalib::split(circlestring,","); + if (values.size() != 3) { std::string msg = "Invalid number of "+gammalib::str(values.size())+" arguments" " after the \"circle\" key word in provided string \""+line+"\".\n" "Exactly 3 arguments are expected."; - throw GException::invalid_value(G_READ, msg); - } - double x = gammalib::todouble(values[0]); - double y = gammalib::todouble(values[1]); - double radius = gammalib::todouble(values[2]); + throw GException::invalid_value(G_READ, msg); + } + double x = gammalib::todouble(values[0]); + double y = gammalib::todouble(values[1]); + double radius = gammalib::todouble(values[2]); // Get radius units if (gammalib::contains(values[2], "'")) { @@ -329,33 +330,33 @@ void GSkyRegionCircle::read(const std::string& line) radius /= 3600.0; } - // Initialise centre direction - GSkyDir centre = GSkyDir(); - - // Set the values in the correct system - if (system == "fk5" || system == "icrs") { - centre.radec_deg(x,y); - } - else if (system == "galactic") { - centre.lb_deg(x,y); - } - else { + // Initialise centre direction + GSkyDir centre = GSkyDir(); + + // Set the values in the correct system + if (system == "fk5" || system == "icrs") { + centre.radec_deg(x,y); + } + else if (system == "galactic") { + centre.lb_deg(x,y); + } + else { std::string msg = "Unsupported coordinate system \""+system+"\" in provided string" " \""+line+"\".\n" "Only the following coordinate systems are supported: " "\"fk5\", \"icrs\" and \"galactic\"."; - throw GException::invalid_value(G_READ, msg); - } + throw GException::invalid_value(G_READ, msg); + } - // Set members - this->centre(centre); + // Set members + this->centre(centre); this->radius(radius); - // Compute solid angle - compute_solid_angle(); + // Compute solid angle + compute_solid_angle(); - // Check if there is a given name for the region and set it. Strings may + // Check if there is a given name for the region and set it. Strings may // be quoted with " or ' or {} pos = comment.find("text"); if (pos != std::string::npos) { @@ -418,8 +419,8 @@ void GSkyRegionCircle::read(const std::string& line) } // endif: text attribute found - // Return - return; + // Return + return; } @@ -434,16 +435,16 @@ void GSkyRegionCircle::read(const std::string& line) std::string GSkyRegionCircle::write(void) const { // Allocate string - std::string result; + std::string result; // Set string - result.append("fk5;circle("); - result.append(gammalib::str(m_centre.ra_deg())); - result.append(","); - result.append(gammalib::str(m_centre.dec_deg())); - result.append(","); - result.append(gammalib::str(m_radius)); - result.append(")"); + result.append("fk5;circle("); + result.append(gammalib::str(m_centre.ra_deg())); + result.append(","); + result.append(gammalib::str(m_centre.dec_deg())); + result.append(","); + result.append(gammalib::str(m_radius)); + result.append(")"); // Optionally add region name if (m_name.length() > 0) { @@ -454,7 +455,7 @@ std::string GSkyRegionCircle::write(void) const } // Return string - return result; + return result; } @@ -473,7 +474,7 @@ std::string GSkyRegionCircle::print(const GChatter& chatter) const if (chatter != SILENT) { // Append header - result.append("=== GSkyRegionCircle ==="); + result.append("=== GSkyRegionCircle ==="); // Append sky circle information result.append("\n"+gammalib::parformat("Right Ascension of centre")); @@ -499,19 +500,19 @@ std::string GSkyRegionCircle::print(const GChatter& chatter) const ***************************************************************************/ bool GSkyRegionCircle::contains(const GSkyDir& dir) const { - // Initialise return value - bool dir_is_in = false; + // Initialise return value + bool dir_is_in = false; - // calculate distance from dir to centre - double distance = dir.dist_deg(m_centre); + // calculate distance from dir to centre + double distance = dir.dist_deg(m_centre); - // Check if distance < radius - if (distance <= radius()) { - dir_is_in = true; - } + // Check if distance < radius + if (distance <= radius()) { + dir_is_in = true; + } - // Return bool - return dir_is_in; + // Return bool + return dir_is_in; } /***********************************************************************//** @@ -524,34 +525,34 @@ bool GSkyRegionCircle::contains(const GSkyDir& dir) const ***************************************************************************/ bool GSkyRegionCircle::contains(const GSkyRegion& reg) const { - // Initialise return value - bool fully_inside = false; + // Initialise return value + bool fully_inside = false; - // If other region is circle use a simple way to calculate - if (reg.type() == "Circle") { + // If other region is circle use a simple way to calculate + if (reg.type() == "Circle") { - // Create circular region from reg - const GSkyRegionCircle* regcirc = + // Create circular region from reg + const GSkyRegionCircle* regcirc = dynamic_cast(®); - // Calculate angular distance between the centres - double ang_dist = m_centre.dist_deg(regcirc->centre()); + // Calculate angular distance between the centres + double ang_dist = m_centre.dist_deg(regcirc->centre()); - // Check if the region is contained in this - if ((ang_dist + regcirc->radius()) <= m_radius) { - fully_inside = true; - } + // Check if the region is contained in this + if ((ang_dist + regcirc->radius()) <= m_radius) { + fully_inside = true; + } - } + } // ... otherwise throw an exception - else { - throw GException::feature_not_implemented(G_CONTAINS, + else { + throw GException::feature_not_implemented(G_CONTAINS, "Cannot compare two different region types yet"); - } - - // Return value - return fully_inside; + } + + // Return value + return fully_inside; } @@ -565,34 +566,34 @@ bool GSkyRegionCircle::contains(const GSkyRegion& reg) const ***************************************************************************/ bool GSkyRegionCircle::overlaps(const GSkyRegion& reg) const { - // Initialise return value - bool overlap = false; + // Initialise return value + bool overlap = false; - // If other region is circle use a simple way to calculate - if (reg.type() == "Circle") { + // If other region is circle use a simple way to calculate + if (reg.type() == "Circle") { - // Create circular region from reg - const GSkyRegionCircle* regcirc = + // Create circular region from reg + const GSkyRegionCircle* regcirc = dynamic_cast(®); - // Calculate angular distance between the centres - double ang_dist = m_centre.dist_deg(regcirc->centre()); + // Calculate angular distance between the centres + double ang_dist = m_centre.dist_deg(regcirc->centre()); - // Check if the distance is smaller than the sum of both radii - if (ang_dist <= (m_radius + regcirc->radius())) { - overlap = true; - } - - } + // Check if the distance is smaller than the sum of both radii + if (ang_dist <= (m_radius + regcirc->radius())) { + overlap = true; + } + + } // ... otherwise throw an exception - else { - throw GException::feature_not_implemented(G_OVERLAPS, + else { + throw GException::feature_not_implemented(G_OVERLAPS, "Cannot compare two different region types yet"); - } + } - // Return value - return overlap; + // Return value + return overlap; } @@ -609,12 +610,12 @@ bool GSkyRegionCircle::overlaps(const GSkyRegion& reg) const void GSkyRegionCircle::init_members(void) { // Initialise members - m_centre = GSkyDir(); - m_radius = 0.0; - m_type = "Circle"; + m_centre = GSkyDir(); + m_radius = 0.0; + m_type = "Circle"; - //Return - return; + //Return + return; } @@ -625,9 +626,9 @@ void GSkyRegionCircle::init_members(void) ***************************************************************************/ void GSkyRegionCircle::copy_members(const GSkyRegionCircle& region) { - // Copy attributes - m_centre = region.m_centre; - m_radius = region.m_radius; + // Copy attributes + m_centre = region.m_centre; + m_radius = region.m_radius; // Return return; @@ -649,11 +650,11 @@ void GSkyRegionCircle::free_members(void) ***************************************************************************/ void GSkyRegionCircle::compute_solid_angle(void) { - // Convert radius from degrees to radians - double radius_rad = m_radius * gammalib::deg2rad; + // Convert radius from degrees to radians + double radius_rad = m_radius * gammalib::deg2rad; - // Compute solid angle - m_solid = gammalib::twopi * (1.0 - std::cos(radius_rad)); + // Compute solid angle + m_solid = gammalib::twopi * (1.0 - std::cos(radius_rad)); // Return return; diff --git a/src/sky/GSkyRegionMap.cpp b/src/sky/GSkyRegionMap.cpp index 84f3414..bd7edfa 100644 --- a/src/sky/GSkyRegionMap.cpp +++ b/src/sky/GSkyRegionMap.cpp @@ -1,7 +1,7 @@ /*************************************************************************** * GSkyRegionMap.cpp - Sky region map class * * ----------------------------------------------------------------------- * - * copyright (C) 2017-2018 by Pierrick Martin * + * copyright (C) 2017-2020 by Pierrick Martin * * ----------------------------------------------------------------------- * * * * This program is free software: you can redistribute it and/or modify * @@ -397,8 +397,8 @@ bool GSkyRegionMap::contains(const GSkyRegion& reg) const // Case of a region map if (reg.type() == "Map") { - // Cast to map type - const GSkyRegionMap* inreg = dynamic_cast(®); + // Cast to map type + const GSkyRegionMap* inreg = dynamic_cast(®); // Retrieve map data const GSkyMap& regmap = inreg->map(); @@ -417,8 +417,8 @@ bool GSkyRegionMap::contains(const GSkyRegion& reg) const // Case of a circular region else if (reg.type() == "Circle") { - // Create circular region from reg - const GSkyRegionCircle* inreg = dynamic_cast(®); + // Create circular region from reg + const GSkyRegionCircle* inreg = dynamic_cast(®); // Retrieve circle data const GSkyDir& centre = inreg->centre(); diff --git a/src/sky/GSkyRegions.cpp b/src/sky/GSkyRegions.cpp index 8dfa569..896c2b9 100644 --- a/src/sky/GSkyRegions.cpp +++ b/src/sky/GSkyRegions.cpp @@ -422,19 +422,19 @@ void GSkyRegions::extend(const GSkyRegions& regions) ***************************************************************************/ bool GSkyRegions::contains(const GSkyDir& dir) const { - // Initialise return value - bool overlap = false; - - // Loop over regions - for (int i = 0; i < size(); ++i) { - overlap = m_regions[i]->contains(dir); - if (overlap) { + // Initialise return value + bool overlap = false; + + // Loop over regions + for (int i = 0; i < size(); ++i) { + overlap = m_regions[i]->contains(dir); + if (overlap) { break; } - } - - // Return result - return overlap; + } + + // Return result + return overlap; } @@ -512,67 +512,67 @@ void GSkyRegions::load(const GFilename& filename) // Open file. Throw an exception if opening failed. std::ifstream ds9file; ds9file.open(filename.url().c_str()); - if (ds9file.is_open()) { + if (ds9file.is_open()) { - // Loop over file lines - std::string fileline = ""; - std::string coordsys = "galactic"; + // Loop over file lines + std::string fileline = ""; + std::string coordsys = "galactic"; while (ds9file.good()) { - - // Read one line - getline(ds9file,fileline); - - // If line is a comment then continue - if (fileline[0] == '#') { + + // Read one line + getline(ds9file,fileline); + + // If line is a comment then continue + if (fileline[0] == '#') { continue; } - - // Check for global definition of coordinate system - if (std::string::npos != fileline.find("fk5")) { - coordsys = "fk5"; - } + + // Check for global definition of coordinate system + if (std::string::npos != fileline.find("fk5")) { + coordsys = "fk5"; + } else if (std::string::npos != fileline.find("icrs")) { - coordsys = "icrs"; - } - - // If region is a circle - if (std::string::npos != fileline.find("circle")) { + coordsys = "icrs"; + } + + // If region is a circle + if (std::string::npos != fileline.find("circle")) { - // Create instance of GSkyRegion object - GSkyRegionCircle region; + // Create instance of GSkyRegion object + GSkyRegionCircle region; - // If coordinate system and region defined on the same line - if ((std::string::npos != fileline.find("fk5")) || + // If coordinate system and region defined on the same line + if ((std::string::npos != fileline.find("fk5")) || (std::string::npos != fileline.find("icrs")) || - (std::string::npos != fileline.find("galactic"))) { - region.read(fileline); - append(region); - } + (std::string::npos != fileline.find("galactic"))) { + region.read(fileline); + append(region); + } - // else, prepend the coordinate system + // else, prepend the coordinate system else { - std::string newfileline = coordsys; - newfileline.append("; "); - newfileline.append(fileline); - region.read(newfileline); - append(region); - } - } - } - + std::string newfileline = coordsys; + newfileline.append("; "); + newfileline.append(fileline); + region.read(newfileline); + append(region); + } + } + } + // Close file ds9file.close(); // Store filename m_filename = filename; - } + } - // File could not be opened + // File could not be opened else { throw GException::file_open_error(G_LOAD, filename.url()); } - + // Return return; } @@ -597,34 +597,31 @@ void GSkyRegions::save(const GFilename& filename) const // If file opened correctly, then save regions if (ds9file.is_open()) { - // Write global definition - std::string fileline; - fileline.append("# Region file format: DS9 version 4.1\n"); - fileline.append("global color=green dashlist=8 3 width=1"); -// fileline.append("font=\"helvetica 10 normal\" select=1"); -// "highlite=1 dash=0 fixed=0 edit=1 move=1"+ -// "delete=1 include=1 source=1"; - ds9file << fileline << "\n"; - - // Loop over regions in container - for (int i = 0; i < size(); ++i) { - ds9file << m_regions[i]->write() << "\n"; - } - - // Close file - ds9file.close(); + // Write global definition + std::string fileline; + fileline.append("# Region file format: DS9 version 4.1\n"); + fileline.append("global color=green dashlist=8 3 width=1"); + ds9file << fileline << "\n"; + + // Loop over regions in container + for (int i = 0; i < size(); ++i) { + ds9file << m_regions[i]->write() << "\n"; + } + + // Close file + ds9file.close(); // Store filename m_filename = filename; - } + } - // ... otherwise, if file could not be opened then throw an exception + // ... otherwise, if file could not be opened then throw an exception else { throw GException::file_open_error(G_SAVE, filename.url()); - } - - // Return + } + + // Return return; } -- libgit2 0.21.4