fix #3526 GroupSymbolizer PairLayout with 3+ items

This commit is contained in:
Mickey Rose 2016-10-05 23:51:03 +02:00
parent 6364e07d71
commit cb41fc5d48
2 changed files with 23 additions and 27 deletions

View file

@ -90,30 +90,26 @@ struct process_layout
return; return;
} }
bound_box layout_box; auto max_diff = layout.get_max_difference();
int middle_ifirst = safe_cast<int>((member_boxes_.size() - 1) >> 1); auto layout_box = make_horiz_pair(0, 0.0, 0, x_margin, max_diff);
int top_i = 0; auto y_shift = 0.5 * layout_box.height();
int bottom_i = 0;
if (middle_ifirst % 2 == 0) for (size_t i = 2; i < member_boxes_.size(); i += 2)
{ {
layout_box = make_horiz_pair(0, 0.0, 0, x_margin, layout.get_max_difference()); auto y = layout_box.maxy() + y_margin;
top_i = middle_ifirst - 2; auto pair_box = make_horiz_pair(i, y, 1, x_margin, max_diff);
bottom_i = middle_ifirst + 2; layout_box.expand_to_include(pair_box);
}
else
{
top_i = middle_ifirst - 1;
bottom_i = middle_ifirst + 1;
} }
while (bottom_i >= 0 && top_i >= 0 && top_i < static_cast<int>(member_offsets_.size())) // layout_box.center corresponds to the center of the first row;
{ // shift offsets so that the whole group is centered vertically
layout_box.expand_to_include(make_horiz_pair(static_cast<std::size_t>(top_i), layout_box.miny() - y_margin, -1, x_margin, layout.get_max_difference()));
layout_box.expand_to_include(make_horiz_pair(static_cast<std::size_t>(bottom_i), layout_box.maxy() + y_margin, 1, x_margin, layout.get_max_difference()));
top_i -= 2;
bottom_i += 2;
}
y_shift -= 0.5 * layout_box.height();
for (auto & offset : member_offsets_)
{
offset.y += y_shift;
}
} }
private: private:
@ -146,12 +142,12 @@ private:
// stores corresponding offset, and returns modified bounding box // stores corresponding offset, and returns modified bounding box
bound_box box_offset_align(size_t i, double x, double y, int x_dir, int y_dir) const bound_box box_offset_align(size_t i, double x, double y, int x_dir, int y_dir) const
{ {
bound_box const& box = member_boxes_[i]; auto box = member_boxes_[i];
pixel_position offset((x_dir == 0 ? x - input_origin_.x : x - (x_dir < 0 ? box.maxx() : box.minx())), auto & offset = member_offsets_[i];
(y_dir == 0 ? y - input_origin_.y : y - (y_dir < 0 ? box.maxy() : box.miny()))); offset.x = x - (x_dir == 0 ? input_origin_.x : (x_dir < 0 ? box.maxx() : box.minx()));
offset.y = y - (y_dir == 0 ? input_origin_.y : (y_dir < 0 ? box.maxy() : box.miny()));
member_offsets_[i] = offset; box.move(offset.x, offset.y);
return bound_box(box.minx() + offset.x, box.miny() + offset.y, box.maxx() + offset.x, box.maxy() + offset.y); return box;
} }
}; };

@ -1 +1 @@
Subproject commit 941db3d00920dc7aceaa6797096a7228bc7bac14 Subproject commit f9a3c203b3657dd1748d788304f83a26efb6439f