support both box2d<float> and box2d<double>
This commit is contained in:
parent
f422da8681
commit
af1b39c689
2 changed files with 28 additions and 8 deletions
|
@ -42,6 +42,9 @@ namespace mapnik { namespace json {
|
||||||
template <typename Iterator, typename Boxes>
|
template <typename Iterator, typename Boxes>
|
||||||
struct extract_positions
|
struct extract_positions
|
||||||
{
|
{
|
||||||
|
using boxes_type = Boxes;
|
||||||
|
using box_type = typename boxes_type::value_type::first_type;
|
||||||
|
|
||||||
extract_positions(Iterator start, Boxes & boxes)
|
extract_positions(Iterator start, Boxes & boxes)
|
||||||
: start_(start),
|
: start_(start),
|
||||||
boxes_(boxes) {}
|
boxes_(boxes) {}
|
||||||
|
@ -50,20 +53,25 @@ struct extract_positions
|
||||||
void operator() (T const& val) const
|
void operator() (T const& val) const
|
||||||
{
|
{
|
||||||
auto const& r = std::get<0>(val);
|
auto const& r = std::get<0>(val);
|
||||||
mapnik::box2d<float> const& bbox = std::get<1>(val);
|
auto const& b = std::get<1>(val);
|
||||||
auto offset = std::distance(start_, r.begin());
|
auto offset = std::distance(start_, r.begin());
|
||||||
auto size = std::distance(r.begin(), r.end());
|
auto size = std::distance(r.begin(), r.end());
|
||||||
boxes_.emplace_back(std::make_pair(bbox,std::make_pair(offset, size)));
|
boxes_.emplace_back(std::make_pair(box_type(b.minx(), b.miny(), b.maxx(), b.maxy()), std::make_pair(offset, size)));
|
||||||
//boxes_.emplace_back(std::make_tuple(bbox,offset, size));
|
//boxes_.emplace_back(std::make_tuple(bbox,offset, size));
|
||||||
}
|
}
|
||||||
Iterator start_;
|
Iterator start_;
|
||||||
Boxes & boxes_;
|
Boxes & boxes_;
|
||||||
};
|
};
|
||||||
|
|
||||||
using box_type = mapnik::box2d<float>;
|
using box_type = mapnik::box2d<double>;
|
||||||
using boxes_type = std::vector<std::pair<box_type, std::pair<std::size_t, std::size_t>>>;
|
using boxes_type = std::vector<std::pair<box_type, std::pair<std::size_t, std::size_t>>>;
|
||||||
using callback_type = extract_positions<grammar::iterator_type, boxes_type>;
|
using callback_type = extract_positions<grammar::iterator_type, boxes_type>;
|
||||||
|
|
||||||
|
using box_type_f = mapnik::box2d<float>;
|
||||||
|
using boxes_type_f = std::vector<std::pair<box_type_f, std::pair<std::size_t, std::size_t>>>;
|
||||||
|
using callback_type_f = extract_positions<grammar::iterator_type, boxes_type_f>;
|
||||||
|
|
||||||
|
|
||||||
namespace grammar {
|
namespace grammar {
|
||||||
|
|
||||||
struct bracket_tag;
|
struct bracket_tag;
|
||||||
|
@ -90,6 +98,17 @@ using extract_bounding_boxes_reverse_context_type =
|
||||||
phrase_parse_context_type>::type>::type>::type;
|
phrase_parse_context_type>::type>::type>::type;
|
||||||
|
|
||||||
|
|
||||||
|
using extract_bounding_boxes_context_type_f =
|
||||||
|
x3::with_context<bracket_tag, std::reference_wrapper<std::size_t> const,
|
||||||
|
x3::with_context<feature_callback_tag, std::reference_wrapper<callback_type_f> const,
|
||||||
|
context_type>::type>::type;
|
||||||
|
|
||||||
|
using extract_bounding_boxes_reverse_context_type_f =
|
||||||
|
x3::with_context<keys_tag, std::reference_wrapper<keys_map> const,
|
||||||
|
x3::with_context<feature_callback_tag, std::reference_wrapper<callback_type_f> const,
|
||||||
|
x3::with_context<bracket_tag, std::reference_wrapper<std::size_t> const,
|
||||||
|
phrase_parse_context_type>::type>::type>::type;
|
||||||
|
|
||||||
}}}
|
}}}
|
||||||
|
|
||||||
#endif // MAPNIK_JSON_EXTRACT_BOUNDING_BOXES_CONFIG_HPP
|
#endif // MAPNIK_JSON_EXTRACT_BOUNDING_BOXES_CONFIG_HPP
|
||||||
|
|
|
@ -129,14 +129,15 @@ auto assign_bbox = [](auto const& ctx)
|
||||||
|
|
||||||
auto extract_bounding_box = [](auto const& ctx)
|
auto extract_bounding_box = [](auto const& ctx)
|
||||||
{
|
{
|
||||||
mapnik::box2d<float> bbox;
|
using box_type = typename std::decay<decltype(_val(ctx))>::type;
|
||||||
calculate_bounding_box<mapnik::box2d<float>> visitor(bbox);
|
box_type bbox;
|
||||||
|
calculate_bounding_box<box_type> visitor(bbox);
|
||||||
mapnik::util::apply_visitor(visitor, _attr(ctx));
|
mapnik::util::apply_visitor(visitor, _attr(ctx));
|
||||||
_val(ctx) = std::move(bbox);
|
_val(ctx) = std::move(bbox);
|
||||||
};
|
};
|
||||||
|
|
||||||
x3::rule<struct coordinates_rule_tag, mapnik::box2d<float> > const coordinates_rule = "Coordinates";
|
x3::rule<struct coordinates_rule_tag, mapnik::box2d<double> > const coordinates_rule = "Coordinates";
|
||||||
x3::rule<struct bounding_box_rule_tag, std::tuple<boost::iterator_range<base_iterator_type>,mapnik::box2d<float>>> const bounding_box = "Bounding Box";
|
x3::rule<struct bounding_box_rule_tag, std::tuple<boost::iterator_range<base_iterator_type>, mapnik::box2d<double>>> const bounding_box = "Bounding Box";
|
||||||
x3::rule<struct feature_collection_tag> const feature_collection = "Feature Collection";
|
x3::rule<struct feature_collection_tag> const feature_collection = "Feature Collection";
|
||||||
|
|
||||||
auto const coordinates_rule_def = lit("\"coordinates\"") >> lit(':') >> positions_rule[extract_bounding_box];
|
auto const coordinates_rule_def = lit("\"coordinates\"") >> lit(':') >> positions_rule[extract_bounding_box];
|
||||||
|
@ -198,5 +199,5 @@ void extract_bounding_boxes(Iterator start, Iterator end, Boxes & boxes)
|
||||||
}
|
}
|
||||||
using base_iterator_type = char const*;
|
using base_iterator_type = char const*;
|
||||||
template void extract_bounding_boxes<base_iterator_type, boxes_type>(base_iterator_type, base_iterator_type, boxes_type&);
|
template void extract_bounding_boxes<base_iterator_type, boxes_type>(base_iterator_type, base_iterator_type, boxes_type&);
|
||||||
|
template void extract_bounding_boxes<base_iterator_type, boxes_type_f>(base_iterator_type, base_iterator_type, boxes_type_f&);
|
||||||
}}
|
}}
|
||||||
|
|
Loading…
Reference in a new issue