Make code easier to read by using std::pair instead of boost::tuple for position.

This commit is contained in:
Hermann Kraus 2012-01-29 17:33:43 +01:00
parent 822786e41c
commit 49a3b3c52c
11 changed files with 62 additions and 71 deletions

View file

@ -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<double,double> 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<double,double> 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)

View file

@ -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)

View file

@ -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<double,double> const& get_shield_displacement() const;
position const& get_shield_displacement() const;
private:
bool unlock_image_;
boost::tuple<double,double> shield_displacement_;
position shield_displacement_;
};
}

View file

@ -36,8 +36,6 @@
namespace mapnik {
typedef std::pair<double, double> point_type;
/** Helper object that does all the TextSymbolizer placment finding
* work except actually rendering the object. */
template <typename FaceManagerT, typename DetectorT>
@ -100,8 +98,8 @@ protected:
/* Using list instead of vector, because we delete random elements and need iterators to stay valid. */
std::list<geometry_type*> geometries_to_process_;
std::list<geometry_type*>::iterator geo_itr_;
std::list<point_type> points_;
std::list<point_type>::iterator point_itr_;
std::list<position> points_;
std::list<position>::iterator point_itr_;
double angle_;
string_info *info_;
bool placement_valid_;

View file

@ -46,7 +46,7 @@ namespace mapnik {
class text_placements;
typedef boost::tuple<double,double> position;
typedef std::pair<double,double> position;
enum label_placement_enum {
POINT_PLACEMENT,

View file

@ -291,9 +291,9 @@ void placement_finder<DetectorT>::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<DetectorT>::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<DetectorT>::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<DetectorT>::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

View file

@ -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(), "<no default>", 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);
}
}

View file

@ -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<double,double>(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<double,double>(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<double,double>(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<double,double> const& shield_symbolizer::get_shield_displacement() const
position const& shield_symbolizer::get_shield_displacement() const
{
return shield_displacement_;
}

View file

@ -63,7 +63,7 @@ text_placement_info_ptr text_symbolizer_helper<FaceManagerT, DetectorT>::get_poi
placement_finder<DetectorT> 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<point_type>::iterator current_object = point_itr_;
std::list<position>::iterator current_object = point_itr_;
point_itr_++;
if (placement_->placements.size())
{
@ -208,13 +208,13 @@ text_placement_info_ptr shield_symbolizer_helper<FaceManagerT, DetectorT>::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<DetectorT> 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<point_type>::iterator current_object = point_itr_;
std::list<position>::iterator current_object = point_itr_;
point_itr_++;
if (!placement_->placements.size())
{
@ -229,8 +229,8 @@ text_placement_info_ptr shield_symbolizer_helper<FaceManagerT, DetectorT>::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<FaceManagerT, DetectorT>::get_l
TODO: Not supported by placement_finder atm
position const& pos = placement_->properties.displacement;
text_placement.additional_boxes.push_back(
box2d<double>(-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<double>(-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<FaceManagerT, DetectorT>::get_line_placement();
}
@ -319,8 +319,8 @@ std::pair<int, int> shield_symbolizer_helper<FaceManagerT, DetectorT>::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);

View file

@ -95,9 +95,9 @@ void text_symbolizer_properties::from_xml(boost::property_tree::ptree const &sym
optional<std::string> orientation_ = get_opt_attr<std::string>(sym, "orientation");
if (orientation_) orientation = parse_expression(*orientation_, "utf8");
optional<double> dx = get_opt_attr<double>(sym, "dx");
if (dx) displacement.get<0>() = *dx;
if (dx) displacement.first = *dx;
optional<double> dy = get_opt_attr<double>(sym, "dy");
if (dy) displacement.get<1>() = *dy;
if (dy) displacement.second = *dy;
optional<double> max_char_angle_delta_ = get_opt_attr<double>(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";

View file

@ -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)