From 6be658f5b5270679b949b74bbfa973eb844e243f Mon Sep 17 00:00:00 2001 From: Blake Thompson Date: Mon, 6 Apr 2015 11:00:03 -0500 Subject: [PATCH] Moved geometry envelope to an impl --- include/mapnik/geometry_envelope.hpp | 121 +----------------- include/mapnik/geometry_envelope_impl.hpp | 145 ++++++++++++++++++++++ src/build.py | 1 + src/geometry_envelope.cpp | 41 ++++++ 4 files changed, 193 insertions(+), 115 deletions(-) create mode 100644 include/mapnik/geometry_envelope_impl.hpp create mode 100644 src/geometry_envelope.cpp diff --git a/include/mapnik/geometry_envelope.hpp b/include/mapnik/geometry_envelope.hpp index b2372eb2b..17b8fcb44 100644 --- a/include/mapnik/geometry_envelope.hpp +++ b/include/mapnik/geometry_envelope.hpp @@ -23,125 +23,16 @@ #ifndef MAPNIK_GEOMETRY_ENVELOPE_HPP #define MAPNIK_GEOMETRY_ENVELOPE_HPP -#include +#include #include -namespace mapnik { namespace geometry { - -namespace detail { - -struct geometry_envelope -{ - using bbox_type = box2d; - bbox_type & bbox; - - geometry_envelope(bbox_type & bbox_) - : bbox(bbox_) {} - - template - void operator() (T const& geom) const - { - return mapnik::util::apply_visitor(*this, geom); - } - - void operator() (mapnik::geometry::geometry_empty const&) const {} - - void operator() (mapnik::geometry::point const& pt) const - { - if (!bbox.valid()) - { - bbox.init(pt.x, pt.y, pt.x, pt.y); - } - bbox.expand_to_include(pt.x, pt.y); - } - - void operator() (mapnik::geometry::line_string const& line) const - { - bool first = true; - for (auto const& pt : line) - { - if (first && !bbox.valid()) - { - bbox.init(pt.x, pt.y, pt.x, pt.y); - first = false; - } - else - { - bbox.expand_to_include(pt.x, pt.y); - } - } - } - - void operator() (mapnik::geometry::polygon const& poly) const - { - bool first = true; - for (auto const& pt : poly.exterior_ring) - { - if (first && !bbox.valid()) - { - bbox.init(pt.x, pt.y, pt.x, pt.y); - first = false; - } - else - { - bbox.expand_to_include(pt.x, pt.y); - } - } - } - - void operator() (mapnik::geometry::multi_point const& multi_point) const - { - bool first = true; - for (auto const& pt : multi_point) - { - if (first && !bbox.valid()) - { - bbox.init(pt.x, pt.y, pt.x, pt.y); - first = false; - } - else - { - bbox.expand_to_include(pt.x, pt.y); - } - } - } - - void operator() (mapnik::geometry::multi_line_string const& multi_line) const - { - for (auto const& line : multi_line) - { - (*this)(line); - } - } - - void operator() (mapnik::geometry::multi_polygon const& multi_poly) const - { - for (auto const& poly : multi_poly) - { - (*this)(poly); - } - } - - void operator() (mapnik::geometry::geometry_collection const& collection) const - { - for (auto const& geom : collection) - { - (*this)(geom); - } - } -}; - -} +namespace mapnik { +namespace geometry { template -inline mapnik::box2d envelope(T const& geom) -{ - box2d bbox; - detail::geometry_envelope op(bbox); - op(geom); - return bbox; -} +MAPNIK_DECL mapnik::box2d envelope(T const& geom); -}} +} // end ns geometry +} // end ns mapnik #endif // MAPNIK_GEOMETRY_ENVELOPE_HPP diff --git a/include/mapnik/geometry_envelope_impl.hpp b/include/mapnik/geometry_envelope_impl.hpp new file mode 100644 index 000000000..ea0d952db --- /dev/null +++ b/include/mapnik/geometry_envelope_impl.hpp @@ -0,0 +1,145 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2015 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#include +#include +#include + +namespace mapnik { namespace geometry { + +namespace detail { + +struct geometry_envelope +{ + using bbox_type = box2d; + bbox_type & bbox; + + geometry_envelope(bbox_type & bbox_) + : bbox(bbox_) {} + + template + void operator() (T const& geom) const + { + return mapnik::util::apply_visitor(*this, geom); + } + + void operator() (mapnik::geometry::geometry_empty const&) const {} + + void operator() (mapnik::geometry::point const& pt) const + { + if (!bbox.valid()) + { + bbox.init(pt.x, pt.y, pt.x, pt.y); + } + bbox.expand_to_include(pt.x, pt.y); + } + + void operator() (mapnik::geometry::line_string const& line) const + { + bool first = true; + for (auto const& pt : line) + { + if (first && !bbox.valid()) + { + bbox.init(pt.x, pt.y, pt.x, pt.y); + first = false; + } + else + { + bbox.expand_to_include(pt.x, pt.y); + } + } + } + + void operator() (mapnik::geometry::polygon const& poly) const + { + bool first = true; + for (auto const& pt : poly.exterior_ring) + { + if (first && !bbox.valid()) + { + bbox.init(pt.x, pt.y, pt.x, pt.y); + first = false; + } + else + { + bbox.expand_to_include(pt.x, pt.y); + } + } + } + + void operator() (mapnik::geometry::multi_point const& multi_point) const + { + bool first = true; + for (auto const& pt : multi_point) + { + if (first && !bbox.valid()) + { + bbox.init(pt.x, pt.y, pt.x, pt.y); + first = false; + } + else + { + bbox.expand_to_include(pt.x, pt.y); + } + } + } + + void operator() (mapnik::geometry::multi_line_string const& multi_line) const + { + for (auto const& line : multi_line) + { + (*this)(line); + } + } + + void operator() (mapnik::geometry::multi_polygon const& multi_poly) const + { + for (auto const& poly : multi_poly) + { + (*this)(poly); + } + } + + void operator() (mapnik::geometry::geometry_collection const& collection) const + { + for (auto const& geom : collection) + { + (*this)(geom); + } + } +}; + +} // end ns detail + +template +mapnik::box2d envelope(T const& geom) +{ + box2d bbox; + detail::geometry_envelope op(bbox); + op(geom); + return bbox; +} + +} // end ns geometry +} // end ns mapnik + diff --git a/src/build.py b/src/build.py index e6179fb66..5f5aa4098 100644 --- a/src/build.py +++ b/src/build.py @@ -191,6 +191,7 @@ source = Split( palette.cpp marker_helpers.cpp transform_expression_grammar.cpp + geometry_envelope.cpp plugin.cpp rule.cpp save_map.cpp diff --git a/src/geometry_envelope.cpp b/src/geometry_envelope.cpp new file mode 100644 index 000000000..e486f75fa --- /dev/null +++ b/src/geometry_envelope.cpp @@ -0,0 +1,41 @@ +/***************************************************************************** + * + * This file is part of Mapnik (c++ mapping toolkit) + * + * Copyright (C) 2015 Artem Pavlenko + * + * This library is free software; you can redistribute it and/or + * modify it under the terms of the GNU Lesser General Public + * License as published by the Free Software Foundation; either + * version 2.1 of the License, or (at your option) any later version. + * + * This library is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU + * Lesser General Public License for more details. + * + * You should have received a copy of the GNU Lesser General Public + * License along with this library; if not, write to the Free Software + * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA + * + *****************************************************************************/ + +#include +#include +#include +namespace mapnik { +namespace geometry { + +template MAPNIK_DECL mapnik::box2d envelope(geometry const& geom); +template MAPNIK_DECL mapnik::box2d envelope(mapnik::base_symbolizer_helper::geometry_cref const& geom); +template MAPNIK_DECL mapnik::box2d envelope(geometry_empty const& geom); +template MAPNIK_DECL mapnik::box2d envelope(point const& geom); +template MAPNIK_DECL mapnik::box2d envelope(line_string const& geom); +template MAPNIK_DECL mapnik::box2d envelope(polygon const& geom); +template MAPNIK_DECL mapnik::box2d envelope(multi_point const& geom); +template MAPNIK_DECL mapnik::box2d envelope(multi_line_string const& geom); +template MAPNIK_DECL mapnik::box2d envelope(multi_polygon const& geom); +template MAPNIK_DECL mapnik::box2d envelope(geometry_collection const& geom); + +} // end ns geometry +} // end ns mapnik