Moved geometry envelope to an impl

This commit is contained in:
Blake Thompson 2015-04-06 11:00:03 -05:00
parent 159997fe25
commit 6be658f5b5
4 changed files with 193 additions and 115 deletions

View file

@ -23,125 +23,16 @@
#ifndef MAPNIK_GEOMETRY_ENVELOPE_HPP #ifndef MAPNIK_GEOMETRY_ENVELOPE_HPP
#define MAPNIK_GEOMETRY_ENVELOPE_HPP #define MAPNIK_GEOMETRY_ENVELOPE_HPP
#include <mapnik/geometry.hpp> #include <mapnik/config.hpp>
#include <mapnik/box2d.hpp> #include <mapnik/box2d.hpp>
namespace mapnik { namespace geometry { namespace mapnik {
namespace geometry {
namespace detail {
struct geometry_envelope
{
using bbox_type = box2d<double>;
bbox_type & bbox;
geometry_envelope(bbox_type & bbox_)
: bbox(bbox_) {}
template <typename T>
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);
}
}
};
}
template <typename T> template <typename T>
inline mapnik::box2d<double> envelope(T const& geom) MAPNIK_DECL mapnik::box2d<double> envelope(T const& geom);
{
box2d<double> bbox;
detail::geometry_envelope op(bbox);
op(geom);
return bbox;
}
}} } // end ns geometry
} // end ns mapnik
#endif // MAPNIK_GEOMETRY_ENVELOPE_HPP #endif // MAPNIK_GEOMETRY_ENVELOPE_HPP

View file

@ -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 <mapnik/geometry_envelope.hpp>
#include <mapnik/geometry.hpp>
#include <mapnik/box2d.hpp>
namespace mapnik { namespace geometry {
namespace detail {
struct geometry_envelope
{
using bbox_type = box2d<double>;
bbox_type & bbox;
geometry_envelope(bbox_type & bbox_)
: bbox(bbox_) {}
template <typename T>
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 <typename T>
mapnik::box2d<double> envelope(T const& geom)
{
box2d<double> bbox;
detail::geometry_envelope op(bbox);
op(geom);
return bbox;
}
} // end ns geometry
} // end ns mapnik

View file

@ -191,6 +191,7 @@ source = Split(
palette.cpp palette.cpp
marker_helpers.cpp marker_helpers.cpp
transform_expression_grammar.cpp transform_expression_grammar.cpp
geometry_envelope.cpp
plugin.cpp plugin.cpp
rule.cpp rule.cpp
save_map.cpp save_map.cpp

41
src/geometry_envelope.cpp Normal file
View file

@ -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 <mapnik/geometry_envelope.hpp>
#include <mapnik/geometry_envelope_impl.hpp>
#include <mapnik/text/symbolizer_helpers.hpp>
namespace mapnik {
namespace geometry {
template MAPNIK_DECL mapnik::box2d<double> envelope(geometry const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(mapnik::base_symbolizer_helper::geometry_cref const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(geometry_empty const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(point const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(line_string const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(polygon const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(multi_point const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(multi_line_string const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(multi_polygon const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(geometry_collection const& geom);
} // end ns geometry
} // end ns mapnik