Merge branch 'master' into geometry-refactor
This commit is contained in:
commit
633a2c1e07
27 changed files with 84 additions and 61 deletions
|
@ -10,7 +10,7 @@
|
|||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/vertex_adapters.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry/boost_geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_envelope.hpp>
|
||||
#include <mapnik/geometry_correct.hpp>
|
||||
#include <mapnik/geometry_is_empty.hpp>
|
||||
|
|
|
@ -38,7 +38,6 @@ subdirs = [
|
|||
'text',
|
||||
'text/placements',
|
||||
'text/formatting',
|
||||
'geometry',
|
||||
'markers_placements'
|
||||
]
|
||||
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#define MAPNIK_GEOMETRY_CENTROID_HPP
|
||||
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry/boost_geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <boost/geometry/algorithms/centroid.hpp>
|
||||
#include <mapnik/geometry_is_empty.hpp>
|
||||
#include <mapnik/geometry_remove_empty.hpp>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#define MAPNIK_GEOMETRY_CORRECT_HPP
|
||||
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry/boost_geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <mapnik/util/variant.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#if BOOST_VERSION >= 105600
|
||||
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry/boost_geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <boost/geometry/algorithms/is_simple.hpp>
|
||||
|
||||
namespace mapnik { namespace geometry {
|
||||
|
|
|
@ -29,7 +29,7 @@
|
|||
#if BOOST_VERSION >= 105800
|
||||
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry/boost_geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <boost/geometry/algorithms/is_valid.hpp>
|
||||
#include <boost/geometry/algorithms/validity_failure_type.hpp>
|
||||
|
||||
|
@ -102,7 +102,7 @@ struct geometry_is_valid
|
|||
struct geometry_is_valid_reason
|
||||
{
|
||||
using result_type = bool;
|
||||
|
||||
|
||||
boost::geometry::validity_failure_type & failure_;
|
||||
|
||||
geometry_is_valid_reason(boost::geometry::validity_failure_type & failure):
|
||||
|
@ -170,7 +170,7 @@ struct geometry_is_valid_reason
|
|||
struct geometry_is_valid_string
|
||||
{
|
||||
using result_type = bool;
|
||||
|
||||
|
||||
std::string & message_;
|
||||
|
||||
geometry_is_valid_string(std::string & message):
|
||||
|
@ -257,7 +257,7 @@ inline bool is_valid(T const& geom, boost::geometry::validity_failure_type & fai
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool is_valid(mapnik::geometry::geometry<T> const& geom,
|
||||
inline bool is_valid(mapnik::geometry::geometry<T> const& geom,
|
||||
boost::geometry::validity_failure_type & failure)
|
||||
{
|
||||
return util::apply_visitor(detail::geometry_is_valid_reason(failure), geom);
|
||||
|
@ -270,7 +270,7 @@ inline bool is_valid(T const& geom, std::string & message)
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
inline bool is_valid(mapnik::geometry::geometry<T> const& geom,
|
||||
inline bool is_valid(mapnik::geometry::geometry<T> const& geom,
|
||||
std::string & message)
|
||||
{
|
||||
return util::apply_visitor(detail::geometry_is_valid_string(message), geom);
|
||||
|
|
|
@ -23,20 +23,20 @@
|
|||
#ifndef MAPNIK_GEOMETRY_STRATEGY_HPP
|
||||
#define MAPNIK_GEOMETRY_STRATEGY_HPP
|
||||
|
||||
#include <mapnik/geometry/boost_geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <mapnik/util/rounding_cast.hpp>
|
||||
|
||||
namespace mapnik {
|
||||
namespace mapnik {
|
||||
namespace geometry {
|
||||
|
||||
namespace helper
|
||||
{
|
||||
template <std::size_t... Ts>
|
||||
struct index {};
|
||||
|
||||
|
||||
template <std::size_t N, std::size_t... Ts>
|
||||
struct gen_seq : gen_seq<N - 1, N - 1, Ts...> {};
|
||||
|
||||
|
||||
template <std::size_t... Ts>
|
||||
struct gen_seq<0, Ts...> : index<Ts...> {};
|
||||
}
|
||||
|
@ -70,7 +70,7 @@ struct strategy_group
|
|||
|
||||
template <typename P1, typename P2, typename T, typename ...Args>
|
||||
inline P2 execute(P1 const& p, bool & status, T const& strat, Args const& ... args) const
|
||||
{
|
||||
{
|
||||
return execute<P1,P2>(strat.template execute<P1,P1>(p, status), status, args...);
|
||||
}
|
||||
|
||||
|
@ -79,7 +79,7 @@ struct strategy_group
|
|||
{
|
||||
return strat.template execute<P1,P2>(p, status);
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
std::tuple<Strategies const& ...> ops_;
|
||||
|
||||
|
@ -87,7 +87,7 @@ private:
|
|||
|
||||
|
||||
// The difference between this strategy group and the previous is that the conversion from P1 to P2 happens
|
||||
// in the first strategy rather then the last strategy.
|
||||
// in the first strategy rather then the last strategy.
|
||||
template <typename... Strategies>
|
||||
struct strategy_group_first
|
||||
{
|
||||
|
@ -116,13 +116,13 @@ struct strategy_group_first
|
|||
|
||||
template <typename P1, typename P2, typename T, typename ...Args>
|
||||
inline P2 execute_first(P1 const& p, bool & status, T const& strat, Args const& ... args) const
|
||||
{
|
||||
{
|
||||
return execute<P2>(strat.template execute<P1,P2>(p, status), status, args...);
|
||||
}
|
||||
|
||||
template <typename P2, typename T, typename ...Args>
|
||||
inline P2 execute(P2 const& p, bool & status, T const& strat, Args const& ... args) const
|
||||
{
|
||||
{
|
||||
return execute<P2>(strat.template execute<P2,P2>(p, status), status, args...);
|
||||
}
|
||||
|
||||
|
@ -131,13 +131,13 @@ struct strategy_group_first
|
|||
{
|
||||
return strat.template execute<P2,P2>(p, status);
|
||||
}
|
||||
|
||||
|
||||
template <typename P2>
|
||||
inline P2 execute(P2 const& p, bool & status) const
|
||||
{
|
||||
return p;
|
||||
}
|
||||
|
||||
|
||||
private:
|
||||
std::tuple<Strategies const& ...> ops_;
|
||||
|
||||
|
@ -151,7 +151,7 @@ struct scale_strategy
|
|||
template <typename P1, typename P2>
|
||||
inline bool apply(P1 const & p1, P2 & p2) const
|
||||
{
|
||||
|
||||
|
||||
using p2_type = typename boost::geometry::coordinate_type<P2>::type;
|
||||
double x = (boost::geometry::get<0>(p1) * scale_) + offset_;
|
||||
double y = (boost::geometry::get<1>(p1) * scale_) + offset_;
|
||||
|
@ -159,7 +159,7 @@ struct scale_strategy
|
|||
boost::geometry::set<1>(p2, static_cast<p2_type>(y));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <typename P1, typename P2>
|
||||
inline P2 execute(P1 const& p1, bool & status) const
|
||||
{
|
||||
|
@ -181,7 +181,7 @@ struct scale_rounding_strategy
|
|||
template <typename P1, typename P2>
|
||||
inline bool apply(P1 const & p1, P2 & p2) const
|
||||
{
|
||||
|
||||
|
||||
using p2_type = typename boost::geometry::coordinate_type<P2>::type;
|
||||
double x = (boost::geometry::get<0>(p1) * scale_) + offset_;
|
||||
double y = (boost::geometry::get<1>(p1) * scale_) + offset_;
|
||||
|
@ -189,7 +189,7 @@ struct scale_rounding_strategy
|
|||
boost::geometry::set<1>(p2, static_cast<p2_type>(std::round(y)));
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
template <typename P1, typename P2>
|
||||
inline P2 execute(P1 const& p1, bool & status) const
|
||||
{
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#define MAPNIK_GEOMETRY_TRANSFORM_HPP
|
||||
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry/boost_geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <boost/geometry/algorithms/transform.hpp>
|
||||
|
||||
namespace mapnik { namespace geometry { namespace detail {
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/json/extract_bounding_box_grammar.hpp>
|
||||
#include <mapnik/geometry/fusion_adapted.hpp>
|
||||
#include <mapnik/geometry_fusion_adapted.hpp>
|
||||
// boost
|
||||
#include <boost/spirit/include/qi_omit.hpp>
|
||||
#include <boost/spirit/include/phoenix_object.hpp>
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <mapnik/json/geometry_generator_grammar.hpp>
|
||||
#include <mapnik/util/spirit_transform_attribute.hpp>
|
||||
#include <mapnik/geometry_types.hpp>
|
||||
#include <mapnik/geometry/fusion_adapted.hpp>
|
||||
#include <mapnik/geometry_fusion_adapted.hpp>
|
||||
|
||||
// boost
|
||||
#pragma GCC diagnostic push
|
||||
|
|
|
@ -24,7 +24,7 @@
|
|||
#include <mapnik/config.hpp>
|
||||
#include <mapnik/json/error_handler.hpp>
|
||||
#include <mapnik/json/geometry_grammar.hpp>
|
||||
#include <mapnik/geometry/fusion_adapted.hpp>
|
||||
#include <mapnik/geometry_fusion_adapted.hpp>
|
||||
// boost
|
||||
#include <boost/spirit/include/phoenix_stl.hpp>
|
||||
#include <boost/spirit/include/phoenix_function.hpp>
|
||||
|
|
|
@ -22,7 +22,7 @@
|
|||
|
||||
// mapnik
|
||||
#include <mapnik/json/positions_grammar.hpp>
|
||||
#include <mapnik/geometry/fusion_adapted.hpp>
|
||||
#include <mapnik/geometry_fusion_adapted.hpp>
|
||||
// boost
|
||||
#include <boost/spirit/include/qi_omit.hpp>
|
||||
#include <boost/spirit/include/phoenix_object.hpp>
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
BOOST_FUSION_ADAPT_STRUCT(
|
||||
mapnik::topojson::coordinate,
|
||||
(double, x)
|
||||
(double, y)
|
||||
(double, y)
|
||||
)
|
||||
|
||||
BOOST_FUSION_ADAPT_STRUCT(
|
||||
|
|
|
@ -28,7 +28,7 @@
|
|||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/json/topology.hpp>
|
||||
#include <mapnik/feature_factory.hpp>
|
||||
#include <mapnik/geometry/boost_geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_correct.hpp>
|
||||
|
||||
namespace mapnik { namespace topojson {
|
||||
|
|
|
@ -23,6 +23,8 @@
|
|||
#ifndef MAPNIK_UTIL_IS_CLOCKWISE_HPP
|
||||
#define MAPNIK_UTIL_IS_CLOCKWISE_HPP
|
||||
|
||||
#include <cassert>
|
||||
|
||||
namespace mapnik { namespace util {
|
||||
|
||||
template <typename T>
|
||||
|
@ -30,11 +32,18 @@ bool is_clockwise(T const& ring)
|
|||
{
|
||||
double area = 0.0;
|
||||
std::size_t num_points = ring.size();
|
||||
assert(num_point > 2);
|
||||
double orig_x = ring[0].x;
|
||||
double orig_y = ring[0].y;
|
||||
for (std::size_t i = 0; i < num_points; ++i)
|
||||
{
|
||||
auto const& p0 = ring[i];
|
||||
auto const& p1 = ring[(i + 1) % num_points];
|
||||
area += p0.x * p1.y - p0.y * p1.x;
|
||||
double x0 = p0.x - orig_x;
|
||||
double y0 = p0.y - orig_y;
|
||||
double x1 = p1.x - orig_x;
|
||||
double y1 = p1.y - orig_y;
|
||||
area += x0 * y1 - x1 * y0;
|
||||
}
|
||||
return (area < 0.0) ? true : false;
|
||||
}
|
||||
|
|
|
@ -23,7 +23,7 @@
|
|||
// mapnik
|
||||
#include <mapnik/wkt/wkt_generator_grammar.hpp>
|
||||
#include <mapnik/util/spirit_transform_attribute.hpp>
|
||||
#include <mapnik/geometry/fusion_adapted.hpp>
|
||||
#include <mapnik/geometry_fusion_adapted.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*****************************************************************************/
|
||||
|
||||
#include <mapnik/wkt/wkt_grammar.hpp>
|
||||
#include <mapnik/geometry/fusion_adapted.hpp>
|
||||
#include <mapnik/geometry_fusion_adapted.hpp>
|
||||
|
||||
#pragma GCC diagnostic push
|
||||
#include <mapnik/warning_ignore.hpp>
|
||||
|
|
|
@ -1,12 +1,14 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -eu
|
||||
|
||||
MASON_NAME=mapnik
|
||||
MASON_VERSION=latest
|
||||
MASON_LIB_FILE=lib/libmapnik-wkt.a
|
||||
|
||||
. ${MASON_DIR:-~/.mason}/mason.sh
|
||||
# warning: may break when https://github.com/mapbox/mason/issues/141 lands
|
||||
# hence we are pinned for now to older mason in bootstrap.sh
|
||||
. ./.mason/mason.sh
|
||||
|
||||
set -eu
|
||||
|
||||
function mason_load_source {
|
||||
export MASON_BUILD_PATH=$(pwd)
|
||||
|
|
|
@ -38,7 +38,7 @@
|
|||
#include <mapnik/boolean.hpp>
|
||||
#include <mapnik/util/trim.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry/boost_geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <mapnik/util/geometry_to_ds_type.hpp>
|
||||
#include <mapnik/value_types.hpp>
|
||||
#include <mapnik/util/fs.hpp>
|
||||
|
|
|
@ -49,7 +49,7 @@
|
|||
#include <mapnik/util/file_io.hpp>
|
||||
#include <mapnik/util/geometry_to_ds_type.hpp>
|
||||
#include <mapnik/make_unique.hpp>
|
||||
#include <mapnik/geometry/boost_geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <mapnik/json/feature_collection_grammar.hpp>
|
||||
#include <mapnik/json/extract_bounding_box_grammar_impl.hpp>
|
||||
#include <mapnik/util/fs.hpp>
|
||||
|
|
|
@ -274,7 +274,7 @@ pgraster_datasource::pgraster_datasource(parameters const& params)
|
|||
}
|
||||
else
|
||||
{
|
||||
MAPNIK_LOG_DEBUG(pgraster) << "pgraster_datasource: no response from metadata query " << s.str();
|
||||
MAPNIK_LOG_DEBUG(pgraster) << "pgraster_datasource: no response from metadata query " << s.str();
|
||||
}
|
||||
rs->close();
|
||||
}
|
||||
|
@ -291,7 +291,7 @@ pgraster_datasource::pgraster_datasource(parameters const& params)
|
|||
s.str("");
|
||||
|
||||
s << "SELECT ST_SRID(\"" << geometryColumn_ << "\") AS srid FROM "
|
||||
<< populate_tokens(table_) << " WHERE \"" << geometryColumn_ << "\" IS NOT nullptr LIMIT 1;";
|
||||
<< populate_tokens(table_) << " WHERE \"" << geometryColumn_ << "\" IS NOT NULL LIMIT 1;";
|
||||
|
||||
shared_ptr<ResultSet> rs = conn->executeQuery(s.str());
|
||||
if (rs->next())
|
||||
|
|
|
@ -33,7 +33,7 @@
|
|||
#include <mapnik/unicode.hpp>
|
||||
#include <mapnik/value_types.hpp>
|
||||
#include <mapnik/box2d.hpp>
|
||||
#include <mapnik/geometry/boost_geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <mapnik/json/topojson_grammar.hpp>
|
||||
#include <mapnik/json/topojson_utils.hpp>
|
||||
#include <mapnik/util/variant.hpp>
|
||||
|
|
|
@ -26,6 +26,7 @@
|
|||
#include <mapnik/projection.hpp>
|
||||
#include <mapnik/proj_transform.hpp>
|
||||
#include <mapnik/coord.hpp>
|
||||
#include <mapnik/util/is_clockwise.hpp>
|
||||
|
||||
#ifdef MAPNIK_USE_PROJ4
|
||||
// proj4
|
||||
|
@ -370,21 +371,6 @@ void envelope_points(std::vector< coord<double,2> > & coords, box2d<double>& env
|
|||
}
|
||||
}
|
||||
|
||||
// determine if an ordered sequence of coordinates is in clockwise order
|
||||
bool is_clockwise(const std::vector< coord<double,2> > & coords)
|
||||
{
|
||||
int n = coords.size();
|
||||
coord<double,2> c1, c2;
|
||||
double a = 0.0;
|
||||
|
||||
for (int i=0; i<n; i++) {
|
||||
c1 = coords[i];
|
||||
c2 = coords[(i + 1) % n];
|
||||
a += (c1.x * c2.y - c2.x * c1.y);
|
||||
}
|
||||
return a <= 0.0;
|
||||
}
|
||||
|
||||
box2d<double> calculate_bbox(std::vector<coord<double,2> > & points) {
|
||||
std::vector<coord<double,2> >::iterator it = points.begin();
|
||||
std::vector<coord<double,2> >::iterator it_end = points.end();
|
||||
|
@ -425,7 +411,7 @@ bool proj_transform::backward(box2d<double>& env, int points) const
|
|||
}
|
||||
|
||||
box2d<double> result = calculate_bbox(coords);
|
||||
if (is_source_longlat_ && !is_clockwise(coords))
|
||||
if (is_source_longlat_ && !util::is_clockwise(coords))
|
||||
{
|
||||
// we've gone to a geographic CS, and our clockwise envelope has
|
||||
// changed into an anticlockwise one. This means we've crossed the antimeridian, and
|
||||
|
@ -466,7 +452,7 @@ bool proj_transform::forward(box2d<double>& env, int points) const
|
|||
|
||||
box2d<double> result = calculate_bbox(coords);
|
||||
|
||||
if (is_dest_longlat_ && !is_clockwise(coords))
|
||||
if (is_dest_longlat_ && !util::is_clockwise(coords))
|
||||
{
|
||||
// we've gone to a geographic CS, and our clockwise envelope has
|
||||
// changed into an anticlockwise one. This means we've crossed the antimeridian, and
|
||||
|
|
27
test/unit/geometry/is_clockwise.cpp
Normal file
27
test/unit/geometry/is_clockwise.cpp
Normal file
|
@ -0,0 +1,27 @@
|
|||
#include "catch.hpp"
|
||||
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/util/is_clockwise.hpp>
|
||||
|
||||
TEST_CASE("Ring is_clockwise") {
|
||||
|
||||
// Input is rather thin triangle to test precision issues aren't getting in the way.
|
||||
SECTION("Clockwise")
|
||||
{
|
||||
mapnik::geometry::linear_ring<double> ring;
|
||||
ring.emplace_back(-13499697.0366658326, 4698431.85179749783);
|
||||
ring.emplace_back(-13499697.1113113686, 4698431.85179749783);
|
||||
ring.emplace_back(-13499697.0366658326, 4698431.92644303292);
|
||||
ring.emplace_back(-13499697.0366658326, 4698431.85179749783);
|
||||
REQUIRE(mapnik::util::is_clockwise(ring) == true);
|
||||
}
|
||||
SECTION("Anti-Clockwise")
|
||||
{
|
||||
mapnik::geometry::linear_ring<double> ring;
|
||||
ring.emplace_back(-13499697.0366658326, 4698431.85179749783);
|
||||
ring.emplace_back(-13499697.0366658326, 4698431.92644303292);
|
||||
ring.emplace_back(-13499697.1113113686, 4698431.85179749783);
|
||||
ring.emplace_back(-13499697.0366658326, 4698431.85179749783);
|
||||
REQUIRE(mapnik::util::is_clockwise(ring) == false);
|
||||
}
|
||||
}
|
|
@ -2,7 +2,7 @@
|
|||
// mapnik
|
||||
#include <mapnik/wkb.hpp>
|
||||
#include <mapnik/geometry.hpp>
|
||||
#include <mapnik/geometry/boost_geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_adapters.hpp>
|
||||
#include <mapnik/geometry_is_empty.hpp>
|
||||
#include <mapnik/util/geometry_to_wkt.hpp>
|
||||
// bool
|
||||
|
|
Loading…
Reference in a new issue