diff --git a/include/mapnik/group/group_layout_manager.hpp b/include/mapnik/group/group_layout_manager.hpp index 38ee30b5d..548e37bb6 100644 --- a/include/mapnik/group/group_layout_manager.hpp +++ b/include/mapnik/group/group_layout_manager.hpp @@ -31,43 +31,51 @@ // stl #include -using std::vector; - namespace mapnik { -using bound_box = box2d; - struct group_layout_manager { - group_layout_manager(group_layout const& layout) + using bound_box = box2d; + + group_layout_manager() + : update_layout_(false) + {} + + explicit group_layout_manager(group_layout const& layout) : layout_(layout), - input_origin_(0, 0), - member_boxes_(vector()), - member_offsets_(vector()), - update_layout_(true) + update_layout_(false) { } group_layout_manager(group_layout const& layout, pixel_position const& input_origin) : layout_(layout), input_origin_(input_origin), - member_boxes_(vector()), - member_offsets_(vector()), - update_layout_(true) + update_layout_(false) { } group_layout_manager(group_layout const& layout, pixel_position const& input_origin, - vector const& item_boxes) + std::vector const& item_boxes) : layout_(layout), input_origin_(input_origin), member_boxes_(item_boxes), - member_offsets_(vector()), update_layout_(true) { } + void set_input_origin(double x, double y) + { + input_origin_.set(x, y); + update_layout_ = true; + } + + void set_input_origin(pixel_position const& input_origin) + { + input_origin_ = input_origin; + update_layout_ = true; + } + inline void set_layout(group_layout const& layout) { layout_ = layout; @@ -94,8 +102,8 @@ private: group_layout layout_; pixel_position input_origin_; - vector member_boxes_; - vector member_offsets_; + std::vector member_boxes_; + std::vector member_offsets_; bool update_layout_; }; diff --git a/include/mapnik/renderer_common/process_group_symbolizer.hpp b/include/mapnik/renderer_common/process_group_symbolizer.hpp index e8da8d5c6..1c9de13c2 100644 --- a/include/mapnik/renderer_common/process_group_symbolizer.hpp +++ b/include/mapnik/renderer_common/process_group_symbolizer.hpp @@ -170,7 +170,7 @@ void render_group_symbolizer(group_symbolizer const& sym, matches.emplace_back(rule, sub_feature); // construct a bounding box around all symbolizers for the matched rule - bound_box bounds; + box2d bounds; render_thunk_list thunks; render_thunk_extractor extractor(bounds, thunks, *sub_feature, common.vars_, prj_trans, virtual_renderer, clipping_extent); diff --git a/src/group/group_layout_manager.cpp b/src/group/group_layout_manager.cpp index fe00e7d02..ad9aaad7c 100644 --- a/src/group/group_layout_manager.cpp +++ b/src/group/group_layout_manager.cpp @@ -34,19 +34,21 @@ namespace mapnik // This visitor will process offsets for the given layout struct process_layout { + using bound_box = box2d; + // The vector containing the existing, centered item bounding boxes - vector const& member_boxes_; + std::vector const& member_boxes_; // The vector to populate with item offsets - vector & member_offsets_; + std::vector & member_offsets_; // The origin point of the member boxes // i.e. The member boxes are positioned around input_origin, // and the offset values should position them around (0,0) pixel_position const& input_origin_; - process_layout(vector const& member_bboxes, - vector &member_offsets, + process_layout(std::vector const& member_bboxes, + std::vector &member_offsets, pixel_position const& input_origin) : member_boxes_(member_bboxes), member_offsets_(member_offsets), @@ -54,9 +56,12 @@ struct process_layout { } - // arrange group memebers in centered, horizontal row + // arrange group members in centered, horizontal row void operator()(simple_row_layout const& layout) const { + member_offsets_.clear(); + member_offsets_.reserve(member_boxes_.size()); + double total_width = (member_boxes_.size() - 1) * layout.get_item_margin(); for (auto const& box : member_boxes_) { @@ -66,7 +71,7 @@ struct process_layout double x_offset = -(total_width / 2.0); for (auto const& box : member_boxes_) { - member_offsets_.push_back(pixel_position(x_offset - box.minx(), -input_origin_.y)); + member_offsets_.emplace_back(x_offset - box.minx(), -input_origin_.y); x_offset += box.width() + layout.get_item_margin(); } } @@ -150,7 +155,7 @@ private: } }; -bound_box group_layout_manager::offset_box_at(size_t i) +box2d group_layout_manager::offset_box_at(size_t i) { handle_update(); pixel_position const& offset = member_offsets_.at(i);