From 49a3b3c52c6cbeff6b02c754fc97df90436645dd Mon Sep 17 00:00:00 2001 From: Hermann Kraus Date: Sun, 29 Jan 2012 17:33:43 +0100 Subject: [PATCH] Make code easier to read by using std::pair instead of boost::tuple for position. --- bindings/python/mapnik_shield_symbolizer.cpp | 9 ++--- bindings/python/mapnik_text_symbolizer.cpp | 4 +-- include/mapnik/shield_symbolizer.hpp | 4 +-- include/mapnik/symbolizer_helpers.hpp | 6 ++-- include/mapnik/text_placements.hpp | 2 +- src/placement_finder.cpp | 14 ++++---- src/save_map.cpp | 22 ++++++------ src/shield_symbolizer.cpp | 10 +++--- src/symbolizer_helpers.cpp | 24 ++++++------- src/text_placements.cpp | 36 ++++++++------------ src/text_symbolizer.cpp | 2 +- 11 files changed, 62 insertions(+), 71 deletions(-) diff --git a/bindings/python/mapnik_shield_symbolizer.cpp b/bindings/python/mapnik_shield_symbolizer.cpp index bb38d7a56..5da6bad6a 100644 --- a/bindings/python/mapnik_shield_symbolizer.cpp +++ b/bindings/python/mapnik_shield_symbolizer.cpp @@ -37,6 +37,7 @@ using mapnik::path_expression_ptr; using mapnik::guess_type; using mapnik::expression_ptr; using mapnik::parse_path; +using mapnik::position; namespace { @@ -44,8 +45,8 @@ using namespace boost::python; tuple get_shield_displacement(const shield_symbolizer& s) { - boost::tuple pos = s.get_shield_displacement(); - return boost::python::make_tuple(boost::get<0>(pos),boost::get<1>(pos)); + position const& pos = s.get_shield_displacement(); + return boost::python::make_tuple(pos.first, pos.second); } void set_shield_displacement(shield_symbolizer & s, boost::python::tuple arg) @@ -55,8 +56,8 @@ void set_shield_displacement(shield_symbolizer & s, boost::python::tuple arg) tuple get_text_displacement(const shield_symbolizer& t) { - boost::tuple pos = t.get_displacement(); - return boost::python::make_tuple(boost::get<0>(pos),boost::get<1>(pos)); + position const& pos = t.get_displacement(); + return boost::python::make_tuple(pos.first, pos.second); } void set_text_displacement(shield_symbolizer & t, boost::python::tuple arg) diff --git a/bindings/python/mapnik_text_symbolizer.cpp b/bindings/python/mapnik_text_symbolizer.cpp index 31515f11a..ccb5b99e0 100644 --- a/bindings/python/mapnik_text_symbolizer.cpp +++ b/bindings/python/mapnik_text_symbolizer.cpp @@ -39,8 +39,8 @@ using namespace boost::python; tuple get_text_displacement(const text_symbolizer& t) { - position pos = t.get_displacement(); - return boost::python::make_tuple(boost::get<0>(pos),boost::get<1>(pos)); + mapnik::position const& pos = t.get_displacement(); + return boost::python::make_tuple(pos.first, pos.second); } void set_text_displacement(text_symbolizer & t, boost::python::tuple arg) diff --git a/include/mapnik/shield_symbolizer.hpp b/include/mapnik/shield_symbolizer.hpp index 59ed30034..06b12fb2e 100644 --- a/include/mapnik/shield_symbolizer.hpp +++ b/include/mapnik/shield_symbolizer.hpp @@ -51,11 +51,11 @@ struct MAPNIK_DECL shield_symbolizer : public text_symbolizer, bool get_unlock_image() const; // image is not locked to the text placement void set_unlock_image(bool unlock_image); void set_shield_displacement(double shield_dx,double shield_dy); - boost::tuple const& get_shield_displacement() const; + position const& get_shield_displacement() const; private: bool unlock_image_; - boost::tuple shield_displacement_; + position shield_displacement_; }; } diff --git a/include/mapnik/symbolizer_helpers.hpp b/include/mapnik/symbolizer_helpers.hpp index 1b50931d3..4869f07eb 100644 --- a/include/mapnik/symbolizer_helpers.hpp +++ b/include/mapnik/symbolizer_helpers.hpp @@ -36,8 +36,6 @@ namespace mapnik { -typedef std::pair point_type; - /** Helper object that does all the TextSymbolizer placment finding * work except actually rendering the object. */ template @@ -100,8 +98,8 @@ protected: /* Using list instead of vector, because we delete random elements and need iterators to stay valid. */ std::list geometries_to_process_; std::list::iterator geo_itr_; - std::list points_; - std::list::iterator point_itr_; + std::list points_; + std::list::iterator point_itr_; double angle_; string_info *info_; bool placement_valid_; diff --git a/include/mapnik/text_placements.hpp b/include/mapnik/text_placements.hpp index bb6ee9df4..d4e159c55 100644 --- a/include/mapnik/text_placements.hpp +++ b/include/mapnik/text_placements.hpp @@ -46,7 +46,7 @@ namespace mapnik { class text_placements; -typedef boost::tuple position; +typedef std::pair position; enum label_placement_enum { POINT_PLACEMENT, diff --git a/src/placement_finder.cpp b/src/placement_finder.cpp index 1ab6cbd99..a2d3019b8 100644 --- a/src/placement_finder.cpp +++ b/src/placement_finder.cpp @@ -291,9 +291,9 @@ void placement_finder::init_alignment() { valign_ = p.valign; if (valign_ == V_AUTO) { - if (p.displacement.get<1>() > 0.0) + if (p.displacement.second > 0.0) valign_ = V_BOTTOM; - else if (p.displacement.get<1>() < 0.0) + else if (p.displacement.second < 0.0) valign_ = V_TOP; else valign_ = V_MIDDLE; @@ -301,9 +301,9 @@ void placement_finder::init_alignment() halign_ = p.halign; if (halign_ == H_AUTO) { - if (p.displacement.get<0>() > 0.0) + if (p.displacement.first > 0.0) halign_ = H_RIGHT; - else if (p.displacement.get<0>() < 0.0) + else if (p.displacement.first < 0.0) halign_ = H_LEFT; else halign_ = H_MIDDLE; @@ -333,8 +333,8 @@ void placement_finder::adjust_position(text_path *current_placement, current_placement->starting_x += 0.5 * string_width_; // move center right by 1/2 the string width // adjust text envelope position by user's x-y displacement (dx, dy) - current_placement->starting_x += pi.get_scale_factor() * boost::tuples::get<0>(p.displacement); - current_placement->starting_y += pi.get_scale_factor() * boost::tuples::get<1>(p.displacement); + current_placement->starting_x += pi.get_scale_factor() * p.displacement.first; + current_placement->starting_y += pi.get_scale_factor() * p.displacement.second; } @@ -537,7 +537,7 @@ void placement_finder::find_line_placements(PathT & shape_path) double distance = 0.0; - double displacement = boost::tuples::get<1>(p.displacement); // displace by dy + double displacement = p.displacement.second; // displace by dy //Calculate a target_distance that will place the labels centered evenly rather than offset from the start of the linestring if (total_distance < string_width_) //Can't place any strings diff --git a/src/save_map.cpp b/src/save_map.cpp index 551d3e341..13912a52d 100644 --- a/src/save_map.cpp +++ b/src/save_map.cpp @@ -189,8 +189,8 @@ public: ptree::value_type("ShieldSymbolizer", ptree()))->second; - add_font_attributes( sym_node, sym); - add_image_attributes( sym_node, sym); + add_font_attributes(sym_node, sym); + add_image_attributes(sym_node, sym); add_metawriter_attributes(sym_node, sym); // pseudo-default-construct a shield_symbolizer. It is used @@ -199,24 +199,24 @@ public: // maybe add a real, explicit default-ctor? - shield_symbolizer dfl(expression_ptr(), "", 0, color(0,0,0), path_expression_ptr()); + shield_symbolizer dfl; - if (sym.get_unlock_image() != dfl.get_unlock_image() || explicit_defaults_ ) + if (sym.get_unlock_image() != dfl.get_unlock_image() || explicit_defaults_) { - set_attr( sym_node, "unlock-image", sym.get_unlock_image() ); + set_attr(sym_node, "unlock-image", sym.get_unlock_image()); } - if (sym.get_text_opacity() != dfl.get_text_opacity() || explicit_defaults_ ) + if (sym.get_text_opacity() != dfl.get_text_opacity() || explicit_defaults_) { - set_attr( sym_node, "text-opacity", sym.get_text_opacity() ); + set_attr(sym_node, "text-opacity", sym.get_text_opacity()); } position displacement = sym.get_shield_displacement(); - if ( displacement.get<0>() != dfl.get_shield_displacement().get<0>() || explicit_defaults_ ) + if (displacement.first != dfl.get_shield_displacement().first || explicit_defaults_) { - set_attr( sym_node, "shield-dx", displacement.get<0>() ); + set_attr(sym_node, "shield-dx", displacement.first); } - if ( displacement.get<1>() != dfl.get_shield_displacement().get<1>() || explicit_defaults_ ) + if (displacement.second != dfl.get_shield_displacement().second || explicit_defaults_) { - set_attr( sym_node, "shield-dy", displacement.get<1>() ); + set_attr(sym_node, "shield-dy", displacement.second); } } diff --git a/src/shield_symbolizer.cpp b/src/shield_symbolizer.cpp index add50900f..c5a03a453 100644 --- a/src/shield_symbolizer.cpp +++ b/src/shield_symbolizer.cpp @@ -38,7 +38,7 @@ shield_symbolizer::shield_symbolizer(text_placements_ptr placements) : text_symbolizer(placements), symbolizer_with_image(), unlock_image_(false), - shield_displacement_(boost::make_tuple(0,0)) + shield_displacement_(0,0) { } @@ -51,7 +51,7 @@ shield_symbolizer::shield_symbolizer( : text_symbolizer(name, face_name, size, fill), symbolizer_with_image(file), unlock_image_(false), - shield_displacement_(boost::make_tuple(0,0)) + shield_displacement_(0, 0) { } @@ -63,7 +63,7 @@ shield_symbolizer::shield_symbolizer( : text_symbolizer(name, size, fill), symbolizer_with_image(file), unlock_image_(false), - shield_displacement_(boost::make_tuple(0,0)) + shield_displacement_(0, 0) { } @@ -79,10 +79,10 @@ bool shield_symbolizer::get_unlock_image() const void shield_symbolizer::set_shield_displacement(double shield_dx,double shield_dy) { - shield_displacement_ = boost::make_tuple(shield_dx,shield_dy); + shield_displacement_ = std::make_pair(shield_dx, shield_dy); } -boost::tuple const& shield_symbolizer::get_shield_displacement() const +position const& shield_symbolizer::get_shield_displacement() const { return shield_displacement_; } diff --git a/src/symbolizer_helpers.cpp b/src/symbolizer_helpers.cpp index ecf5e35dc..0ad411f9c 100644 --- a/src/symbolizer_helpers.cpp +++ b/src/symbolizer_helpers.cpp @@ -63,7 +63,7 @@ text_placement_info_ptr text_symbolizer_helper::get_poi placement_finder finder(*placement_, *info_, detector_, dims_); finder.find_point_placement(point_itr_->first, point_itr_->second, angle_); //Keep reference to current object so we can delete it. - std::list::iterator current_object = point_itr_; + std::list::iterator current_object = point_itr_; point_itr_++; if (placement_->placements.size()) { @@ -208,13 +208,13 @@ text_placement_info_ptr shield_symbolizer_helper::get_p continue; //Reexecute size check } position const& pos = placement_->properties.displacement; - double label_x = point_itr_->first + boost::get<0>(shield_pos); - double label_y = point_itr_->second + boost::get<1>(shield_pos); + double label_x = point_itr_->first + shield_pos.first; + double label_y = point_itr_->second + shield_pos.second; placement_finder finder(*placement_, *info_, detector_, dims_); finder.find_point_placement(label_x, label_y, angle_); //Keep reference to current object so we can delete it. - std::list::iterator current_object = point_itr_; + std::list::iterator current_object = point_itr_; point_itr_++; if (!placement_->placements.size()) { @@ -229,8 +229,8 @@ text_placement_info_ptr shield_symbolizer_helper::get_p { // center image at text center position // remove displacement from image label - double lx = x - boost::get<0>(pos); - double ly = y - boost::get<1>(pos); + double lx = x - pos.first; + double ly = y - pos.second; marker_x_ = int(floor(lx - (0.5 * marker_w_))) + 1; marker_y_ = int(floor(ly - (0.5 * marker_h_))) + 1; marker_ext_.re_center(lx, ly); @@ -266,10 +266,10 @@ text_placement_info_ptr shield_symbolizer_helper::get_l TODO: Not supported by placement_finder atm position const& pos = placement_->properties.displacement; text_placement.additional_boxes.push_back( - box2d(-0.5 * label_ext.width() - boost::get<0>(pos), - -0.5 * label_ext.height() - boost::get<1>(pos), - 0.5 * label_ext.width() - boost::get<0>(pos), - 0.5 * label_ext.height() - boost::get<1>(pos))); + box2d(-0.5 * label_ext.width() - pos.first, + -0.5 * label_ext.height() - pos.second, + 0.5 * label_ext.width() - pos.first, + 0.5 * label_ext.height() - pos.second)); #endif return text_symbolizer_helper::get_line_placement(); } @@ -319,8 +319,8 @@ std::pair shield_symbolizer_helper::get_marke double x = floor(p.starting_x); double y = floor(p.starting_y); - double lx = x - boost::get<0>(pos); - double ly = y - boost::get<1>(pos); + double lx = x - pos.first; + double ly = y - pos.second; int px = int(floor(lx - (0.5*marker_w_))) + 1; int py = int(floor(ly - (0.5*marker_h_))) + 1; marker_ext_.re_center(lx, ly); diff --git a/src/text_placements.cpp b/src/text_placements.cpp index 2ea18f63a..f12772ab9 100644 --- a/src/text_placements.cpp +++ b/src/text_placements.cpp @@ -95,9 +95,9 @@ void text_symbolizer_properties::from_xml(boost::property_tree::ptree const &sym optional orientation_ = get_opt_attr(sym, "orientation"); if (orientation_) orientation = parse_expression(*orientation_, "utf8"); optional dx = get_opt_attr(sym, "dx"); - if (dx) displacement.get<0>() = *dx; + if (dx) displacement.first = *dx; optional dy = get_opt_attr(sym, "dy"); - if (dy) displacement.get<1>() = *dy; + if (dy) displacement.second = *dy; optional max_char_angle_delta_ = get_opt_attr(sym, "max-char-angle-delta"); if (max_char_angle_delta_) max_char_angle_delta=(*max_char_angle_delta_)*(M_PI/180); processor.from_xml(sym, fontsets); @@ -118,13 +118,13 @@ void text_symbolizer_properties::to_xml(boost::property_tree::ptree &node, bool } } - if (displacement.get<0>() != dfl.displacement.get<0>() || explicit_defaults) + if (displacement.first != dfl.displacement.first || explicit_defaults) { - set_attr(node, "dx", displacement.get<0>()); + set_attr(node, "dx", displacement.first); } - if (displacement.get<1>() != dfl.displacement.get<1>() || explicit_defaults) + if (displacement.second != dfl.displacement.second || explicit_defaults) { - set_attr(node, "dy", displacement.get<1>()); + set_attr(node, "dy", displacement.second); } if (label_placement != dfl.label_placement || explicit_defaults) { @@ -389,36 +389,28 @@ bool text_placement_info_simple::next_position_only() displacement = pdisp; break; case NORTH: - displacement = boost::make_tuple(0, -abs(pdisp.get<1>())); + displacement = std::make_pair(0, -abs(pdisp.second)); break; case EAST: - displacement = boost::make_tuple(abs(pdisp.get<0>()), 0); + displacement = std::make_pair(abs(pdisp.first), 0); break; case SOUTH: - displacement = boost::make_tuple(0, abs(pdisp.get<1>())); + displacement = std::make_pair(0, abs(pdisp.second)); break; case WEST: - displacement = boost::make_tuple(-abs(pdisp.get<0>()), 0); + displacement = std::make_pair(-abs(pdisp.first), 0); break; case NORTHEAST: - displacement = boost::make_tuple( - abs(pdisp.get<0>()), - -abs(pdisp.get<1>())); + displacement = std::make_pair(abs(pdisp.first), -abs(pdisp.second)); break; case SOUTHEAST: - displacement = boost::make_tuple( - abs(pdisp.get<0>()), - abs(pdisp.get<1>())); + displacement = std::make_pair(abs(pdisp.first), abs(pdisp.second)); break; case NORTHWEST: - displacement = boost::make_tuple( - -abs(pdisp.get<0>()), - -abs(pdisp.get<1>())); + displacement = std::make_pair(-abs(pdisp.first), -abs(pdisp.second)); break; case SOUTHWEST: - displacement = boost::make_tuple( - -abs(pdisp.get<0>()), - abs(pdisp.get<1>())); + displacement = std::make_pair(-abs(pdisp.first), abs(pdisp.second)); break; default: std::cerr << "WARNING: Unknown placement\n"; diff --git a/src/text_symbolizer.cpp b/src/text_symbolizer.cpp index 2966e73d1..20e26ffdb 100644 --- a/src/text_symbolizer.cpp +++ b/src/text_symbolizer.cpp @@ -342,7 +342,7 @@ label_placement_e text_symbolizer::get_label_placement() const void text_symbolizer::set_displacement(double x, double y) { - placement_options_->properties.displacement = boost::make_tuple(x,y); + placement_options_->properties.displacement = std::make_pair(x,y); } void text_symbolizer::set_displacement(position const& p)