Added template to geometries

This commit is contained in:
Blake Thompson 2015-04-09 15:22:51 -05:00
parent 938709955e
commit 87fb41907a
80 changed files with 1171 additions and 1088 deletions

View file

@ -33,7 +33,7 @@
#include <iostream>
#include <cstdlib>
void render(mapnik::geometry::multi_polygon const& geom,
void render(mapnik::geometry::multi_polygon<double> const& geom,
mapnik::box2d<double> const& extent,
std::string const& name)
{
@ -79,7 +79,7 @@ public:
expected_("./benchmark/data/polygon_clipping_agg") {}
bool validate() const
{
mapnik::geometry::geometry geom;
mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom))
{
throw std::runtime_error("Failed to parse WKT");
@ -89,12 +89,12 @@ public:
std::clog << "empty geom!\n";
return false;
}
if (!geom.is<mapnik::geometry::polygon>())
if (!geom.is<mapnik::geometry::polygon<double>>())
{
std::clog << "not a polygon!\n";
return false;
}
mapnik::geometry::polygon const& poly = mapnik::util::get<mapnik::geometry::polygon>(geom);
mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
mapnik::geometry::polygon_vertex_adapter va(poly);
@ -107,8 +107,8 @@ public:
clipped.rewind(0);
mapnik::geometry::polygon poly2;
mapnik::geometry::linear_ring ring;
mapnik::geometry::polygon<double> poly2;
mapnik::geometry::linear_ring<double> ring;
// exterior ring
unsigned cmd;
double x, y, x0, y0;
@ -147,7 +147,7 @@ public:
std::string expect = expected_+".png";
std::string actual = expected_+"_actual.png";
mapnik::geometry::multi_polygon mp;
mapnik::geometry::multi_polygon<double> mp;
mp.emplace_back(poly2);
auto env = mapnik::geometry::envelope(mp);
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
@ -160,7 +160,7 @@ public:
}
bool operator()() const
{
mapnik::geometry::geometry geom;
mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom))
{
throw std::runtime_error("Failed to parse WKT");
@ -170,7 +170,7 @@ public:
std::clog << "empty geom!\n";
return false;
}
if (!geom.is<mapnik::geometry::polygon>())
if (!geom.is<mapnik::geometry::polygon<double>>())
{
std::clog << "not a polygon!\n";
return false;
@ -179,7 +179,7 @@ public:
for (unsigned i=0;i<iterations_;++i)
{
unsigned count = 0;
mapnik::geometry::polygon const& poly = mapnik::util::get<mapnik::geometry::polygon>(geom);
mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
mapnik::geometry::polygon_vertex_adapter va(poly);
conv_clip clipped(va);
clipped.clip_box(
@ -222,7 +222,7 @@ public:
expected_("./benchmark/data/polygon_clipping_clipper") {}
bool validate() const
{
mapnik::geometry::geometry geom;
mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom))
{
throw std::runtime_error("Failed to parse WKT");
@ -232,12 +232,12 @@ public:
std::clog << "empty geom!\n";
return false;
}
if (!geom.is<mapnik::geometry::polygon>())
if (!geom.is<mapnik::geometry::polygon<double>>())
{
std::clog << "not a polygon!\n";
return false;
}
mapnik::geometry::polygon & poly = mapnik::util::get<mapnik::geometry::polygon>(geom);
mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
agg::path_storage ps;
ps.move_to(extent_.minx(), extent_.miny());
ps.line_to(extent_.minx(), extent_.maxy());
@ -253,8 +253,8 @@ public:
unsigned cmd;
double x,y;
clipped.rewind(0);
mapnik::geometry::polygon poly2;
mapnik::geometry::linear_ring ring;
mapnik::geometry::polygon<double> poly2;
mapnik::geometry::linear_ring<double> ring;
// TODO: handle resulting multipolygon
// exterior ring
while (true)
@ -274,7 +274,7 @@ public:
mapnik::geometry::correct(poly2);
std::string expect = expected_+".png";
std::string actual = expected_+"_actual.png";
mapnik::geometry::multi_polygon mp;
mapnik::geometry::multi_polygon<double> mp;
mp.emplace_back(poly2);
auto env = mapnik::geometry::envelope(mp);
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
@ -287,7 +287,7 @@ public:
}
bool operator()() const
{
mapnik::geometry::geometry geom;
mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom))
{
throw std::runtime_error("Failed to parse WKT");
@ -297,12 +297,12 @@ public:
std::clog << "empty geom!\n";
return false;
}
if (!geom.is<mapnik::geometry::polygon>())
if (!geom.is<mapnik::geometry::polygon<double>>())
{
std::clog << "not a polygon!\n";
return false;
}
mapnik::geometry::polygon const& poly = mapnik::util::get<mapnik::geometry::polygon>(geom);
mapnik::geometry::polygon<double> const& poly = mapnik::util::get<mapnik::geometry::polygon<double>>(geom);
agg::path_storage ps;
ps.move_to(extent_.minx(), extent_.miny());
ps.line_to(extent_.minx(), extent_.maxy());
@ -350,7 +350,7 @@ public:
expected_("./benchmark/data/polygon_clipping_boost") {}
bool validate() const
{
mapnik::geometry::geometry geom;
mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom))
{
throw std::runtime_error("Failed to parse WKT");
@ -360,25 +360,25 @@ public:
std::clog << "empty geom!\n";
return false;
}
if (!geom.is<mapnik::geometry::polygon>())
if (!geom.is<mapnik::geometry::polygon<double> >())
{
std::clog << "not a polygon!\n";
return false;
}
mapnik::geometry::polygon & poly = mapnik::util::get<mapnik::geometry::polygon>(geom);
mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geom);
mapnik::geometry::correct(poly);
std::deque<mapnik::geometry::polygon> result;
std::deque<mapnik::geometry::polygon<double> > result;
mapnik::geometry::bounding_box bbox(extent_.minx(),extent_.miny(),extent_.maxx(),extent_.maxy());
boost::geometry::intersection(bbox,poly,result);
std::string expect = expected_+".png";
std::string actual = expected_+"_actual.png";
mapnik::geometry::multi_polygon mp;
mapnik::geometry::multi_polygon<double> mp;
for (auto const& geom: result)
{
//std::clog << boost::geometry::dsv(geom) << "\n";
mp.emplace_back(geom);
}
mapnik::geometry::geometry geom2(mp);
mapnik::geometry::geometry<double> geom2(mp);
auto env = mapnik::geometry::envelope(geom2);
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
{
@ -390,7 +390,7 @@ public:
}
bool operator()() const
{
mapnik::geometry::geometry geom;
mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom))
{
throw std::runtime_error("Failed to parse WKT");
@ -400,18 +400,18 @@ public:
std::clog << "empty geom!\n";
return false;
}
if (!geom.is<mapnik::geometry::polygon>())
if (!geom.is<mapnik::geometry::polygon<double> >())
{
std::clog << "not a polygon!\n";
return false;
}
mapnik::geometry::polygon & poly = mapnik::util::get<mapnik::geometry::polygon>(geom);
mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geom);
mapnik::geometry::correct(poly);
mapnik::geometry::bounding_box bbox(extent_.minx(),extent_.miny(),extent_.maxx(),extent_.maxy());
bool valid = true;
for (unsigned i=0;i<iterations_;++i)
{
std::deque<mapnik::geometry::polygon> result;
std::deque<mapnik::geometry::polygon<double> > result;
boost::geometry::intersection(bbox,poly,result);
unsigned count = 0;
for (auto const& geom : result)
@ -448,7 +448,7 @@ public:
expected_("./benchmark/data/polygon_clipping_clipper") {}
bool validate() const
{
mapnik::geometry::geometry geom;
mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom))
{
throw std::runtime_error("Failed to parse WKT");
@ -458,12 +458,12 @@ public:
std::clog << "empty geom!\n";
return false;
}
if (!geom.is<mapnik::geometry::polygon>())
if (!geom.is<mapnik::geometry::polygon<double> >())
{
std::clog << "not a polygon!\n";
return false;
}
mapnik::geometry::polygon & poly = mapnik::util::get<mapnik::geometry::polygon>(geom);
mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geom);
mapnik::geometry::correct(poly);
ClipperLib::Clipper clipper;
@ -509,7 +509,7 @@ public:
clipper.Execute(ClipperLib::ctIntersection, polygons, ClipperLib::pftNonZero, ClipperLib::pftNonZero);
clipper.Clear();
ClipperLib::PolyNode* polynode = polygons.GetFirst();
mapnik::geometry::multi_polygon mp;
mapnik::geometry::multi_polygon<double> mp;
mp.emplace_back();
bool first = true;
while (polynode)
@ -526,7 +526,7 @@ public:
}
else
{
mapnik::geometry::linear_ring hole;
mapnik::geometry::linear_ring<double> hole;
for (auto const& pt : polynode->Contour)
{
hole.add_coord(pt.X, pt.Y);
@ -538,7 +538,7 @@ public:
}
std::string expect = expected_+".png";
std::string actual = expected_+"_actual.png";
mapnik::geometry::geometry geom2(mp);
mapnik::geometry::geometry<double> geom2(mp);
auto env = mapnik::geometry::envelope(geom2);
if (!mapnik::util::exists(expect) || (std::getenv("UPDATE") != nullptr))
{
@ -550,7 +550,7 @@ public:
}
bool operator()() const
{
mapnik::geometry::geometry geom;
mapnik::geometry::geometry<double> geom;
if (!mapnik::from_wkt(wkt_in_, geom))
{
throw std::runtime_error("Failed to parse WKT");
@ -560,18 +560,18 @@ public:
std::clog << "empty geom!\n";
return false;
}
if (!geom.is<mapnik::geometry::polygon>())
if (!geom.is<mapnik::geometry::polygon<double> >())
{
std::clog << "not a polygon!\n";
return false;
}
mapnik::geometry::polygon & poly = mapnik::util::get<mapnik::geometry::polygon>(geom);
mapnik::geometry::polygon<double> & poly = mapnik::util::get<mapnik::geometry::polygon<double> >(geom);
mapnik::geometry::correct(poly);
mapnik::geometry::bounding_box bbox(extent_.minx(),extent_.miny(),extent_.maxx(),extent_.maxy());
bool valid = true;
for (unsigned i=0;i<iterations_;++i)
{
std::deque<mapnik::geometry::polygon> result;
std::deque<mapnik::geometry::polygon<double> > result;
boost::geometry::intersection(bbox,poly,result);
unsigned count = 0;
for (auto const& geom : result)

View file

@ -62,9 +62,9 @@
namespace {
std::shared_ptr<mapnik::geometry::geometry> from_wkb_impl(std::string const& wkb)
std::shared_ptr<mapnik::geometry::geometry<double> > from_wkb_impl(std::string const& wkb)
{
std::shared_ptr<mapnik::geometry::geometry> geom = std::make_shared<mapnik::geometry::geometry>();
std::shared_ptr<mapnik::geometry::geometry<double> > geom = std::make_shared<mapnik::geometry::geometry<double> >();
try
{
*geom = std::move(mapnik::geometry_utils::from_wkb(wkb.c_str(), wkb.size()));
@ -76,17 +76,17 @@ std::shared_ptr<mapnik::geometry::geometry> from_wkb_impl(std::string const& wkb
return geom;
}
std::shared_ptr<mapnik::geometry::geometry> from_wkt_impl(std::string const& wkt)
std::shared_ptr<mapnik::geometry::geometry<double> > from_wkt_impl(std::string const& wkt)
{
std::shared_ptr<mapnik::geometry::geometry> geom = std::make_shared<mapnik::geometry::geometry>();
std::shared_ptr<mapnik::geometry::geometry<double> > geom = std::make_shared<mapnik::geometry::geometry<double> >();
if (!mapnik::from_wkt(wkt, *geom))
throw std::runtime_error("Failed to parse WKT geometry");
return geom;
}
std::shared_ptr<mapnik::geometry::geometry> from_geojson_impl(std::string const& json)
std::shared_ptr<mapnik::geometry::geometry<double> > from_geojson_impl(std::string const& json)
{
std::shared_ptr<mapnik::geometry::geometry> geom = std::make_shared<mapnik::geometry::geometry>();
std::shared_ptr<mapnik::geometry::geometry<double> > geom = std::make_shared<mapnik::geometry::geometry<double> >();
if (!mapnik::json::from_geojson(json, *geom))
throw std::runtime_error("Failed to parse geojson geometry");
return geom;
@ -101,7 +101,7 @@ inline std::string boost_version()
return s.str();
}
PyObject* to_wkb_impl(mapnik::geometry::geometry const& geom, mapnik::wkbByteOrder byte_order)
PyObject* to_wkb_impl(mapnik::geometry::geometry<double> const& geom, mapnik::wkbByteOrder byte_order)
{
mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(geom,byte_order);
if (wkb)
@ -120,7 +120,7 @@ PyObject* to_wkb_impl(mapnik::geometry::geometry const& geom, mapnik::wkbByteOrd
}
}
std::string to_geojson_impl(mapnik::geometry::geometry const& geom)
std::string to_geojson_impl(mapnik::geometry::geometry<double> const& geom)
{
std::string wkt;
if (!mapnik::util::to_geojson(wkt, geom))
@ -130,7 +130,7 @@ std::string to_geojson_impl(mapnik::geometry::geometry const& geom)
return wkt;
}
std::string to_wkt_impl(mapnik::geometry::geometry const& geom)
std::string to_wkt_impl(mapnik::geometry::geometry<double> const& geom)
{
std::string wkt;
if (!mapnik::util::to_wkt(wkt,geom))
@ -140,49 +140,49 @@ std::string to_wkt_impl(mapnik::geometry::geometry const& geom)
return wkt;
}
mapnik::geometry::geometry_types geometry_type_impl(mapnik::geometry::geometry const& geom)
mapnik::geometry::geometry_types geometry_type_impl(mapnik::geometry::geometry<double> const& geom)
{
return mapnik::geometry::geometry_type(geom);
}
mapnik::box2d<double> geometry_envelope_impl(mapnik::geometry::geometry const& geom)
mapnik::box2d<double> geometry_envelope_impl(mapnik::geometry::geometry<double> const& geom)
{
return mapnik::geometry::envelope(geom);
}
bool geometry_is_valid_impl(mapnik::geometry::geometry const& geom)
bool geometry_is_valid_impl(mapnik::geometry::geometry<double> const& geom)
{
return mapnik::geometry::is_valid(geom);
}
bool geometry_is_simple_impl(mapnik::geometry::geometry const& geom)
bool geometry_is_simple_impl(mapnik::geometry::geometry<double> const& geom)
{
return mapnik::geometry::is_simple(geom);
}
bool geometry_is_empty_impl(mapnik::geometry::geometry const& geom)
bool geometry_is_empty_impl(mapnik::geometry::geometry<double> const& geom)
{
return mapnik::geometry::is_empty(geom);
}
void geometry_correct_impl(mapnik::geometry::geometry & geom)
void geometry_correct_impl(mapnik::geometry::geometry<double> & geom)
{
mapnik::geometry::correct(geom);
}
void polygon_set_exterior_impl(mapnik::geometry::polygon & poly, mapnik::geometry::linear_ring const& ring)
void polygon_set_exterior_impl(mapnik::geometry::polygon<double> & poly, mapnik::geometry::linear_ring<double> const& ring)
{
poly.exterior_ring = ring; // copy
}
void polygon_add_hole_impl(mapnik::geometry::polygon & poly, mapnik::geometry::linear_ring const& ring)
void polygon_add_hole_impl(mapnik::geometry::polygon<double> & poly, mapnik::geometry::linear_ring<double> const& ring)
{
poly.interior_rings.push_back(ring); // copy
}
mapnik::geometry::point geometry_centroid_impl(mapnik::geometry::geometry const& geom)
mapnik::geometry::point<double> geometry_centroid_impl(mapnik::geometry::geometry<double> const& geom)
{
mapnik::geometry::point pt;
mapnik::geometry::point<double> pt;
mapnik::geometry::centroid(geom, pt);
return pt;
}
@ -192,9 +192,9 @@ void export_geometry()
{
using namespace boost::python;
implicitly_convertible<mapnik::geometry::point, mapnik::geometry::geometry>();
implicitly_convertible<mapnik::geometry::line_string, mapnik::geometry::geometry>();
implicitly_convertible<mapnik::geometry::polygon, mapnik::geometry::geometry>();
implicitly_convertible<mapnik::geometry::point<double>, mapnik::geometry::geometry<double> >();
implicitly_convertible<mapnik::geometry::line_string<double>, mapnik::geometry::geometry<double> >();
implicitly_convertible<mapnik::geometry::polygon<double>, mapnik::geometry::geometry<double> >();
enum_<mapnik::geometry::geometry_types>("GeometryType")
.value("Unknown",mapnik::geometry::geometry_types::Unknown)
.value("Point",mapnik::geometry::geometry_types::Point)
@ -217,10 +217,10 @@ void export_geometry()
using mapnik::geometry::linear_ring;
using mapnik::geometry::polygon;
class_<point>("Point", init<double, double>((arg("x"), arg("y")),
class_<point<double> >("Point", init<double, double>((arg("x"), arg("y")),
"Constructs a new Point object\n"))
.add_property("x", &point::x, "X coordinate")
.add_property("y", &point::y, "Y coordinate")
.add_property("x", &point<double>::x, "X coordinate")
.add_property("y", &point<double>::y, "Y coordinate")
.def("is_valid", &geometry_is_valid_impl)
.def("is_simple", &geometry_is_simple_impl)
.def("to_geojson",&to_geojson_impl)
@ -228,9 +228,9 @@ void export_geometry()
.def("to_wkt",&to_wkt_impl)
;
class_<line_string>("LineString", init<>(
class_<line_string<double> >("LineString", init<>(
"Constructs a new LineString object\n"))
.def("add_coord", &line_string::add_coord, "Adds coord")
.def("add_coord", &line_string<double>::add_coord, "Adds coord")
.def("is_valid", &geometry_is_valid_impl)
.def("is_simple", &geometry_is_simple_impl)
.def("to_geojson",&to_geojson_impl)
@ -238,14 +238,14 @@ void export_geometry()
.def("to_wkt",&to_wkt_impl)
;
class_<linear_ring>("LinearRing", init<>(
class_<linear_ring<double> >("LinearRing", init<>(
"Constructs a new LinearRtring object\n"))
.def("add_coord", &linear_ring::add_coord, "Adds coord")
.def("add_coord", &linear_ring<double>::add_coord, "Adds coord")
;
class_<polygon>("Polygon", init<>(
class_<polygon<double> >("Polygon", init<>(
"Constructs a new Polygon object\n"))
.add_property("exterior_ring", &polygon::exterior_ring , "Exterior ring")
.add_property("exterior_ring", &polygon<double>::exterior_ring , "Exterior ring")
.def("add_hole", &polygon_add_hole_impl, "Add interior ring")
.def("num_rings", polygon_set_exterior_impl, "Number of rings (at least 1)")
.def("is_valid", &geometry_is_valid_impl)
@ -255,7 +255,7 @@ void export_geometry()
.def("to_wkt",&to_wkt_impl)
;
class_<geometry, std::shared_ptr<geometry>, boost::noncopyable>("Geometry",no_init)
class_<geometry<double>, std::shared_ptr<geometry<double> >, boost::noncopyable>("Geometry",no_init)
.def("envelope",&geometry_envelope_impl)
.def("from_geojson", from_geojson_impl)
.def("from_wkt", from_wkt_impl)

View file

@ -195,17 +195,17 @@ public:
return ctx_;
}
inline void set_geometry(geometry::geometry && geom)
inline void set_geometry(geometry::geometry<double> && geom)
{
geom_ = std::move(geom);
}
inline void set_geometry_copy(geometry::geometry const& geom)
inline void set_geometry_copy(geometry::geometry<double> const& geom)
{
geom_ = geom;
}
inline geometry::geometry const& get_geometry() const
inline geometry::geometry<double> const& get_geometry() const
{
return geom_;
}
@ -262,7 +262,7 @@ private:
mapnik::value_integer id_;
context_ptr ctx_;
cont_type data_;
geometry::geometry geom_;
geometry::geometry<double> geom_;
raster_ptr raster_;
};

View file

@ -31,11 +31,12 @@
namespace mapnik { namespace geometry {
template <typename T>
struct point
{
using value_type = double;
using value_type = T;
point() {}
point(double x_, double y_)
point(T x_, T y_)
: x(x_), y(y_)
{}
@ -46,41 +47,44 @@ struct point
value_type y;
};
template <typename T>
struct bounding_box
{
bounding_box() {} // no-init
bounding_box(double lox, double loy, double hix, double hiy)
bounding_box(T lox, T loy, T hix, T hiy)
: p0(lox,loy),
p1(hix,hiy) {}
point p0;
point p1;
point<T> p0;
point<T> p1;
};
struct line_string : std::vector<point>
template <typename T>
struct line_string : std::vector<point<T> >
{
line_string() = default;
line_string (line_string && other) = default ;
line_string& operator=(line_string &&) = default;
line_string (line_string const& ) = default;
line_string& operator=(line_string const&) = default;
inline std::size_t num_points() const { return size(); }
inline void add_coord(double x, double y) { emplace_back(x,y);}
inline std::size_t num_points() const { return std::vector<point<T>>::template size(); }
inline void add_coord(T x, T y) { std::vector<point<T>>::template emplace_back(x,y);}
};
template <typename T>
struct linear_ring : line_string<T> {};
struct linear_ring : line_string {};
template <typename T>
struct polygon
{
linear_ring exterior_ring;
std::vector<linear_ring> interior_rings;
linear_ring<T> exterior_ring;
std::vector<linear_ring<T>> interior_rings;
inline void set_exterior_ring(linear_ring && ring)
inline void set_exterior_ring(linear_ring<T> && ring)
{
exterior_ring = std::move(ring);
}
inline void add_hole(linear_ring && ring)
inline void add_hole(linear_ring<T> && ring)
{
interior_rings.emplace_back(std::move(ring));
}
@ -93,21 +97,32 @@ struct polygon
}
};
struct multi_point : line_string {};
struct multi_line_string : std::vector<line_string> {};
struct multi_polygon : std::vector<polygon> {};
struct geometry_collection;
struct geometry_empty {};
using geometry = mapnik::util::variant<geometry_empty,
point,
line_string,
polygon,
multi_point,
multi_line_string,
multi_polygon,
mapnik::util::recursive_wrapper<geometry_collection> >;
template <typename T>
struct multi_point : line_string<T> {};
struct geometry_collection : std::vector<geometry> {};
template <typename T>
struct multi_line_string : std::vector<line_string<T>> {};
template <typename T>
struct multi_polygon : std::vector<polygon<T>> {};
template <typename T>
struct geometry_collection;
struct geometry_empty {};
template <typename T>
using geometry = mapnik::util::variant<geometry_empty,
point<T>,
line_string<T>,
polygon<T>,
multi_point<T>,
multi_line_string<T>,
multi_polygon<T>,
mapnik::util::recursive_wrapper<geometry_collection<T> > >;
template <typename T>
struct geometry_collection : std::vector<geometry<T>> {};
}}

View file

@ -36,155 +36,155 @@
#include <boost/geometry/core/tags.hpp>
// register point
BOOST_GEOMETRY_REGISTER_POINT_2D (mapnik::geometry::point, double, cs::cartesian, x, y)
BOOST_GEOMETRY_REGISTER_POINT_2D (mapnik::geometry::point<double>, double, cs::cartesian, x, y)
// ring
BOOST_GEOMETRY_REGISTER_RING(mapnik::geometry::linear_ring)
BOOST_GEOMETRY_REGISTER_RING(mapnik::geometry::linear_ring<double>)
namespace boost {
template <>
struct range_iterator<mapnik::geometry::line_string>
struct range_iterator<mapnik::geometry::line_string<double> >
{
using type = mapnik::geometry::line_string::iterator;
using type = mapnik::geometry::line_string<double>::iterator;
};
template <>
struct range_const_iterator<mapnik::geometry::line_string>
struct range_const_iterator<mapnik::geometry::line_string<double> >
{
using type = mapnik::geometry::line_string::const_iterator;
using type = mapnik::geometry::line_string<double>::const_iterator;
};
inline mapnik::geometry::line_string::iterator
range_begin(mapnik::geometry::line_string & line) {return line.begin();}
inline mapnik::geometry::line_string<double>::iterator
range_begin(mapnik::geometry::line_string<double> & line) {return line.begin();}
inline mapnik::geometry::line_string::iterator
range_end(mapnik::geometry::line_string & line) {return line.end();}
inline mapnik::geometry::line_string<double>::iterator
range_end(mapnik::geometry::line_string<double> & line) {return line.end();}
inline mapnik::geometry::line_string::const_iterator
range_begin(mapnik::geometry::line_string const& line) {return line.begin();}
inline mapnik::geometry::line_string<double>::const_iterator
range_begin(mapnik::geometry::line_string<double> const& line) {return line.begin();}
inline mapnik::geometry::line_string::const_iterator
range_end(mapnik::geometry::line_string const& line) {return line.end();}
inline mapnik::geometry::line_string<double>::const_iterator
range_end(mapnik::geometry::line_string<double> const& line) {return line.end();}
namespace geometry { namespace traits {
template<> struct tag<mapnik::geometry::bounding_box> { using type = box_tag; };
template<> struct tag<mapnik::geometry::bounding_box<double>> { using type = box_tag; };
template<> struct point_type<mapnik::geometry::bounding_box> { using type = mapnik::geometry::point; };
template<> struct point_type<mapnik::geometry::bounding_box<double>> { using type = mapnik::geometry::point<double>; };
template <>
struct indexed_access<mapnik::geometry::bounding_box, min_corner, 0>
struct indexed_access<mapnik::geometry::bounding_box<double>, min_corner, 0>
{
static inline double get(mapnik::geometry::bounding_box const& b) { return b.p0.x;}
static inline void set(mapnik::geometry::bounding_box& b, double value) { b.p0.x = value; }
static inline double get(mapnik::geometry::bounding_box<double> const& b) { return b.p0.x;}
static inline void set(mapnik::geometry::bounding_box<double> & b, double value) { b.p0.x = value; }
};
template <>
struct indexed_access<mapnik::geometry::bounding_box, min_corner, 1>
struct indexed_access<mapnik::geometry::bounding_box<double>, min_corner, 1>
{
static inline double get(mapnik::geometry::bounding_box const& b) { return b.p0.y;}
static inline void set(mapnik::geometry::bounding_box& b, double value) { b.p0.y = value; }
static inline double get(mapnik::geometry::bounding_box<double> const& b) { return b.p0.y;}
static inline void set(mapnik::geometry::bounding_box<double> & b, double value) { b.p0.y = value; }
};
template <>
struct indexed_access<mapnik::geometry::bounding_box, max_corner, 0>
struct indexed_access<mapnik::geometry::bounding_box<double>, max_corner, 0>
{
static inline double get(mapnik::geometry::bounding_box const& b) { return b.p1.x;}
static inline void set(mapnik::geometry::bounding_box& b, double value) { b.p1.x = value; }
static inline double get(mapnik::geometry::bounding_box<double> const& b) { return b.p1.x;}
static inline void set(mapnik::geometry::bounding_box<double> & b, double value) { b.p1.x = value; }
};
template <>
struct indexed_access<mapnik::geometry::bounding_box, max_corner, 1>
struct indexed_access<mapnik::geometry::bounding_box<double>, max_corner, 1>
{
static inline double get(mapnik::geometry::bounding_box const& b) { return b.p1.y;}
static inline void set(mapnik::geometry::bounding_box& b, double value) { b.p1.y = value; }
static inline double get(mapnik::geometry::bounding_box<double> const& b) { return b.p1.y;}
static inline void set(mapnik::geometry::bounding_box<double> & b, double value) { b.p1.y = value; }
};
template<>
struct tag<mapnik::geometry::line_string>
struct tag<mapnik::geometry::line_string<double> >
{
using type = linestring_tag;
};
// mapnik::geometry::polygon
template<>
struct tag<mapnik::geometry::polygon>
struct tag<mapnik::geometry::polygon<double> >
{
using type = polygon_tag;
};
template <>
struct point_order<mapnik::geometry::linear_ring>
struct point_order<mapnik::geometry::linear_ring<double> >
{
static const order_selector value = counterclockwise;
};
template<>
struct tag<mapnik::geometry::multi_point>
struct tag<mapnik::geometry::multi_point<double> >
{
using type = multi_point_tag;
};
template<>
struct tag<mapnik::geometry::multi_line_string>
struct tag<mapnik::geometry::multi_line_string<double> >
{
using type = multi_linestring_tag;
};
template<> struct tag<mapnik::geometry::multi_polygon>
template<> struct tag<mapnik::geometry::multi_polygon<double> >
{
using type = multi_polygon_tag;
};
// ring
template<> struct ring_const_type<mapnik::geometry::polygon>
template<> struct ring_const_type<mapnik::geometry::polygon<double> >
{
using type = mapnik::geometry::linear_ring const&;
using type = mapnik::geometry::linear_ring<double> const&;
};
template<> struct ring_mutable_type<mapnik::geometry::polygon>
template<> struct ring_mutable_type<mapnik::geometry::polygon<double> >
{
using type = mapnik::geometry::linear_ring&;
using type = mapnik::geometry::linear_ring<double>&;
};
// interior
template<> struct interior_const_type<mapnik::geometry::polygon>
template<> struct interior_const_type<mapnik::geometry::polygon<double> >
{
using type = std::vector<mapnik::geometry::linear_ring> const&;
using type = std::vector<mapnik::geometry::linear_ring<double> > const&;
};
template<> struct interior_mutable_type<mapnik::geometry::polygon>
template<> struct interior_mutable_type<mapnik::geometry::polygon<double> >
{
using type = std::vector<mapnik::geometry::linear_ring>&;
using type = std::vector<mapnik::geometry::linear_ring<double> >&;
};
// exterior
template<>
struct exterior_ring<mapnik::geometry::polygon>
struct exterior_ring<mapnik::geometry::polygon<double> >
{
static mapnik::geometry::linear_ring& get(mapnik::geometry::polygon & p)
static mapnik::geometry::linear_ring<double> & get(mapnik::geometry::polygon<double> & p)
{
return p.exterior_ring;
}
static mapnik::geometry::linear_ring const& get(mapnik::geometry::polygon const& p)
static mapnik::geometry::linear_ring<double> const& get(mapnik::geometry::polygon<double> const& p)
{
return p.exterior_ring;
}
};
template<>
struct interior_rings<mapnik::geometry::polygon>
struct interior_rings<mapnik::geometry::polygon<double> >
{
using holes_type = std::vector<mapnik::geometry::linear_ring>;
static holes_type& get(mapnik::geometry::polygon & p)
using holes_type = std::vector<mapnik::geometry::linear_ring<double> >;
static holes_type& get(mapnik::geometry::polygon<double> & p)
{
return p.interior_rings;
}
static holes_type const& get(mapnik::geometry::polygon const& p)
static holes_type const& get(mapnik::geometry::polygon<double> const& p)
{
return p.interior_rings;
}

View file

@ -31,15 +31,16 @@ namespace mapnik { namespace geometry {
namespace detail {
template <typename T>
struct geometry_centroid
{
using result_type = bool;
geometry_centroid(point & pt)
geometry_centroid(point<T> & pt)
: pt_(pt) {}
template <typename T>
result_type operator() (T const& geom) const
template <typename T1>
result_type operator() (T1 const& geom) const
{
return util::apply_visitor(*this, geom);
}
@ -49,55 +50,55 @@ struct geometry_centroid
return false;
}
result_type operator() (geometry_collection const& collection) const
result_type operator() (geometry_collection<T> const& collection) const
{
return false;
}
result_type operator() (point const& geom) const
result_type operator() (point<T> const& geom) const
{
boost::geometry::centroid(geom, pt_);
return true;
}
result_type operator() (line_string const& geom) const
result_type operator() (line_string<T> const& geom) const
{
boost::geometry::centroid(geom, pt_);
return true;
}
result_type operator() (polygon const& geom) const
result_type operator() (polygon<T> const& geom) const
{
boost::geometry::centroid(geom, pt_);
return true;
}
result_type operator() (multi_point const& geom) const
result_type operator() (multi_point<T> const& geom) const
{
boost::geometry::centroid(geom, pt_);
return true;
}
result_type operator() (multi_line_string const& geom) const
result_type operator() (multi_line_string<T> const& geom) const
{
boost::geometry::centroid(geom, pt_);
return true;
}
result_type operator() (multi_polygon const& geom) const
result_type operator() (multi_polygon<T> const& geom) const
{
boost::geometry::centroid(geom, pt_);
return true;
}
point & pt_;
point<T> & pt_;
};
}
template <typename T>
inline bool centroid(T const& geom, point & pt)
template <typename T1, typename T2>
inline bool centroid(T1 const& geom, point<T2> & pt)
{
return detail::geometry_centroid(pt)(geom);
return detail::geometry_centroid<T2>(pt)(geom);
}
}}

View file

@ -37,12 +37,14 @@ struct geometry_correct
{
using result_type = void;
result_type operator() (geometry & geom) const
template <typename T>
result_type operator() (geometry<T> & geom) const
{
mapnik::util::apply_visitor(*this, geom);
}
result_type operator() (geometry_collection & collection) const
template <typename T>
result_type operator() (geometry_collection<T> & collection) const
{
for (auto & geom : collection)
{
@ -50,12 +52,14 @@ struct geometry_correct
}
}
result_type operator() (polygon & poly) const
template <typename T>
result_type operator() (polygon<T> & poly) const
{
boost::geometry::correct(poly);
}
result_type operator() (multi_polygon & multi_poly) const
template <typename T>
result_type operator() (multi_polygon<T> & multi_poly) const
{
boost::geometry::correct(multi_poly);
}

View file

@ -44,7 +44,7 @@ struct geometry_envelope
void operator() (mapnik::geometry::geometry_empty const&) const {}
void operator() (mapnik::geometry::point const& pt) const
void operator() (mapnik::geometry::point<double> const& pt) const
{
if (!bbox.valid())
{
@ -53,7 +53,7 @@ struct geometry_envelope
bbox.expand_to_include(pt.x, pt.y);
}
void operator() (mapnik::geometry::line_string const& line) const
void operator() (mapnik::geometry::line_string<double> const& line) const
{
bool first = true;
for (auto const& pt : line)
@ -70,7 +70,7 @@ struct geometry_envelope
}
}
void operator() (mapnik::geometry::polygon const& poly) const
void operator() (mapnik::geometry::polygon<double> const& poly) const
{
bool first = true;
for (auto const& pt : poly.exterior_ring)
@ -87,7 +87,7 @@ struct geometry_envelope
}
}
void operator() (mapnik::geometry::multi_point const& multi_point) const
void operator() (mapnik::geometry::multi_point<double> const& multi_point) const
{
bool first = true;
for (auto const& pt : multi_point)
@ -104,7 +104,7 @@ struct geometry_envelope
}
}
void operator() (mapnik::geometry::multi_line_string const& multi_line) const
void operator() (mapnik::geometry::multi_line_string<double> const& multi_line) const
{
for (auto const& line : multi_line)
{
@ -112,7 +112,7 @@ struct geometry_envelope
}
}
void operator() (mapnik::geometry::multi_polygon const& multi_poly) const
void operator() (mapnik::geometry::multi_polygon<double> const& multi_poly) const
{
for (auto const& poly : multi_poly)
{
@ -120,7 +120,7 @@ struct geometry_envelope
}
}
void operator() (mapnik::geometry::geometry_collection const& collection) const
void operator() (mapnik::geometry::geometry_collection<double> const& collection) const
{
for (auto const& geom : collection)
{

View file

@ -29,14 +29,14 @@
#include <vector>
BOOST_FUSION_ADAPT_STRUCT(
mapnik::geometry::point,
mapnik::geometry::point<double>,
(double, x)
(double, y)
)
BOOST_FUSION_ADAPT_STRUCT(
mapnik::geometry::polygon,
(mapnik::geometry::linear_ring const&, exterior_ring)
(std::vector<mapnik::geometry::linear_ring> const& , interior_rings))
mapnik::geometry::polygon<double>,
(mapnik::geometry::linear_ring<double> const&, exterior_ring)
(std::vector<mapnik::geometry::linear_ring<double> > const& , interior_rings))
#endif // MAPNIK_GEOMETRY_FUSION_ADAPTED_HPP

View file

@ -31,42 +31,42 @@ namespace detail {
struct geometry_is_empty
{
bool operator() (mapnik::geometry::geometry const& geom) const
bool operator() (mapnik::geometry::geometry<double> const& geom) const
{
return mapnik::util::apply_visitor(*this, geom);
}
bool operator() (mapnik::geometry::point const&) const
bool operator() (mapnik::geometry::point<double> const&) const
{
return false;
}
bool operator() (mapnik::geometry::line_string const& geom) const
bool operator() (mapnik::geometry::line_string<double> const& geom) const
{
return geom.empty();
}
bool operator() (mapnik::geometry::polygon const& geom) const
bool operator() (mapnik::geometry::polygon<double> const& geom) const
{
return geom.empty();
}
bool operator() (mapnik::geometry::multi_point const& geom) const
bool operator() (mapnik::geometry::multi_point<double> const& geom) const
{
return geom.empty();
}
bool operator() (mapnik::geometry::multi_line_string const& geom) const
bool operator() (mapnik::geometry::multi_line_string<double> const& geom) const
{
return geom.empty();
}
bool operator() (mapnik::geometry::multi_polygon const& geom) const
bool operator() (mapnik::geometry::multi_polygon<double> const& geom) const
{
return geom.empty();
}
bool operator() (mapnik::geometry::geometry_collection const& geom) const
bool operator() (mapnik::geometry::geometry_collection<double> const& geom) const
{
return geom.empty();
}

View file

@ -35,7 +35,8 @@ struct geometry_is_simple
{
using result_type = bool;
result_type operator() (geometry const& geom) const
template <typename T>
result_type operator() (geometry<T> const& geom) const
{
return mapnik::util::apply_visitor(*this, geom);
}
@ -45,7 +46,8 @@ struct geometry_is_simple
return false;
}
result_type operator() (geometry_collection const& collection) const
template <typename T>
result_type operator() (geometry_collection<T> const& collection) const
{
for (auto const& geom : collection)
{
@ -54,27 +56,33 @@ struct geometry_is_simple
return true;
}
result_type operator() (point const& pt) const
template <typename T>
result_type operator() (point<T> const& pt) const
{
return boost::geometry::is_simple(pt);
}
result_type operator() (line_string const& line) const
template <typename T>
result_type operator() (line_string<T> const& line) const
{
return boost::geometry::is_simple(line);
}
result_type operator() (polygon const& poly) const
template <typename T>
result_type operator() (polygon<T> const& poly) const
{
return boost::geometry::is_simple(poly);
}
result_type operator() (multi_point const& multi_pt) const
template <typename T>
result_type operator() (multi_point<T> const& multi_pt) const
{
return boost::geometry::is_simple(multi_pt);
}
result_type operator() (multi_line_string const& multi_line) const
template <typename T>
result_type operator() (multi_line_string<T> const& multi_line) const
{
return boost::geometry::is_simple(multi_line);
}
result_type operator() (multi_polygon const& multi_poly) const
template <typename T>
result_type operator() (multi_polygon<T> const& multi_poly) const
{
return boost::geometry::is_simple(multi_poly);
}

View file

@ -35,7 +35,8 @@ struct geometry_is_valid
{
using result_type = bool;
result_type operator() (geometry const& geom) const
template <typename T>
result_type operator() (geometry<T> const& geom) const
{
return mapnik::util::apply_visitor(*this, geom);
}
@ -45,7 +46,8 @@ struct geometry_is_valid
return false;
}
result_type operator() (geometry_collection const& collection) const
template <typename T>
result_type operator() (geometry_collection<T> const& collection) const
{
for (auto const& geom : collection)
{
@ -54,32 +56,38 @@ struct geometry_is_valid
return true;
}
result_type operator() (point const& pt) const
template <typename T>
result_type operator() (point<T> const& pt) const
{
return boost::geometry::is_valid(pt);
}
result_type operator() (line_string const& line) const
template <typename T>
result_type operator() (line_string<T> const& line) const
{
return boost::geometry::is_valid(line);
}
result_type operator() (polygon const& poly) const
template <typename T>
result_type operator() (polygon<T> const& poly) const
{
return boost::geometry::is_valid(poly);
}
result_type operator() (multi_point const& multi_pt) const
template <typename T>
result_type operator() (multi_point<T> const& multi_pt) const
{
return boost::geometry::is_valid(multi_pt);
}
result_type operator() (multi_line_string const& multi_line) const
template <typename T>
result_type operator() (multi_line_string<T> const& multi_line) const
{
return boost::geometry::is_valid(multi_line);
}
result_type operator() (multi_polygon const& multi_poly) const
template <typename T>
result_type operator() (multi_polygon<T> const& multi_poly) const
{
return boost::geometry::is_valid(multi_poly);
}

View file

@ -37,7 +37,8 @@ namespace geometry {
// This is done this way so that large geometry collections that only have a few failing points or polygon parts could
// still be return with out the few failing projections.
MAPNIK_DECL geometry reproject_copy(geometry const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template <typename T>
MAPNIK_DECL geometry<T> reproject_copy(geometry<T> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template <typename T>
MAPNIK_DECL T reproject_copy(T const& geom, proj_transform const& proj_trans, unsigned int & n_err);

View file

@ -34,13 +34,15 @@ struct geometry_to_path
geometry_to_path(path_type & p)
: p_(p) {}
void operator() (geometry const& geom) const
template <typename T>
void operator() (geometry<T> const& geom) const
{
return mapnik::util::apply_visitor(*this, geom);
}
// point
void operator() (point const& pt) const
template <typename T>
void operator() (point<T> const& pt) const
{
//point pt_new;
//Transformer::apply(pt, pt_new);
@ -48,7 +50,8 @@ struct geometry_to_path
}
// line_string
void operator() (line_string const& line) const
template <typename T>
void operator() (line_string<T> const& line) const
{
bool first = true;
for (auto const& pt : line)
@ -61,7 +64,8 @@ struct geometry_to_path
}
// polygon
void operator() (polygon const& poly) const
template <typename T>
void operator() (polygon<T> const& poly) const
{
// exterior
bool first = true;
@ -87,7 +91,8 @@ struct geometry_to_path
}
// multi point
void operator() (multi_point const& multi_pt) const
template <typename T>
void operator() (multi_point<T> const& multi_pt) const
{
for (auto const& pt : multi_pt)
{
@ -95,7 +100,8 @@ struct geometry_to_path
}
}
// multi_line_string
void operator() (multi_line_string const& multi_line) const
template <typename T>
void operator() (multi_line_string<T> const& multi_line) const
{
for (auto const& line : multi_line)
{
@ -104,7 +110,8 @@ struct geometry_to_path
}
// multi_polygon
void operator() (multi_polygon const& multi_poly) const
template <typename T>
void operator() (multi_polygon<T> const& multi_poly) const
{
for (auto const& poly : multi_poly)
{
@ -112,7 +119,8 @@ struct geometry_to_path
}
}
void operator() (geometry_collection const& collection) const
template <typename T>
void operator() (geometry_collection<T> const& collection) const
{
for (auto const& geom : collection)
{
@ -120,7 +128,6 @@ struct geometry_to_path
}
}
path_type & p_;
};

View file

@ -29,22 +29,22 @@
namespace mapnik { namespace geometry { namespace detail {
template <typename Transformer>
template <typename Transformer, typename V>
struct geometry_transform
{
geometry_transform(Transformer const& transformer)
: transformer_(transformer) {}
using result_type = geometry;
using result_type = geometry<V>;
geometry operator() (geometry_empty const& empty) const
geometry<V> operator() (geometry_empty const& empty) const
{
return empty;
}
geometry operator() (geometry_collection const& collection) const
geometry<V> operator() (geometry_collection<V> const& collection) const
{
geometry_collection collection_out;
geometry_collection<V> collection_out;
for (auto const& geom : collection)
{
collection_out.push_back(std::move((*this)(geom)));
@ -52,13 +52,13 @@ struct geometry_transform
return collection_out;
}
geometry operator() (geometry const& geom) const
geometry<V> operator() (geometry<V> const& geom) const
{
return mapnik::util::apply_visitor(*this, geom);
}
template <typename T>
geometry operator() (T const& geom) const
geometry<V> operator() (T const& geom) const
{
using geometry_type = T;
geometry_type geom_transformed;
@ -72,10 +72,10 @@ struct geometry_transform
};
} // ns detail
template <typename T0, typename T1>
geometry transform(T0 const& geom, T1 const& transformer)
template <typename T0, typename T1, typename T2>
geometry<T0> transform(T1 const& geom, T2 const& transformer)
{
return detail::geometry_transform<T1>(transformer)(geom);
return detail::geometry_transform<T2, T0>(transformer)(geom);
}
}}

View file

@ -42,37 +42,37 @@ struct geometry_type
return mapnik::geometry::geometry_types::Unknown;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::point const&) const
mapnik::geometry::geometry_types operator () (mapnik::geometry::point<double> const&) const
{
return mapnik::geometry::geometry_types::Point;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::line_string const&) const
mapnik::geometry::geometry_types operator () (mapnik::geometry::line_string<double> const&) const
{
return mapnik::geometry::geometry_types::LineString;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::polygon const&) const
mapnik::geometry::geometry_types operator () (mapnik::geometry::polygon<double> const&) const
{
return mapnik::geometry::geometry_types::Polygon;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_point const&) const
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_point<double> const&) const
{
return mapnik::geometry::geometry_types::MultiPoint;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_line_string const&) const
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_line_string<double> const&) const
{
return mapnik::geometry::geometry_types::MultiLineString;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_polygon const&) const
mapnik::geometry::geometry_types operator () (mapnik::geometry::multi_polygon<double> const&) const
{
return mapnik::geometry::geometry_types::MultiPolygon;
}
mapnik::geometry::geometry_types operator () (mapnik::geometry::geometry_collection const&) const
mapnik::geometry::geometry_types operator () (mapnik::geometry::geometry_collection<double> const&) const
{
return mapnik::geometry::geometry_types::GeometryCollection;
}

View file

@ -54,11 +54,11 @@ struct hit_test_visitor
return false;
}
bool operator() (geometry::point const& geom) const
bool operator() (geometry::point<double> const& geom) const
{
return distance(geom.x, geom.y, x_, y_) <= tol_;
}
bool operator() (geometry::multi_point const& geom) const
bool operator() (geometry::multi_point<double> const& geom) const
{
for (auto const& pt : geom)
{
@ -66,7 +66,7 @@ struct hit_test_visitor
}
return false;
}
bool operator() (geometry::line_string const& geom) const
bool operator() (geometry::line_string<double> const& geom) const
{
std::size_t num_points = geom.num_points();
if (num_points > 1)
@ -81,7 +81,7 @@ struct hit_test_visitor
}
return false;
}
bool operator() (geometry::multi_line_string const& geom) const
bool operator() (geometry::multi_line_string<double> const& geom) const
{
for (auto const& line: geom)
{
@ -89,7 +89,7 @@ struct hit_test_visitor
}
return false;
}
bool operator() (geometry::polygon const& geom) const
bool operator() (geometry::polygon<double> const& geom) const
{
auto const& exterior = geom.exterior_ring;
std::size_t num_points = exterior.num_points();
@ -126,7 +126,7 @@ struct hit_test_visitor
}
return inside;
}
bool operator() (geometry::multi_polygon const& geom) const
bool operator() (geometry::multi_polygon<double> const& geom) const
{
for (auto const& poly: geom)
{
@ -134,7 +134,7 @@ struct hit_test_visitor
}
return false;
}
bool operator() (geometry::geometry_collection const& collection) const
bool operator() (geometry::geometry_collection<double> const& collection) const
{
for (auto const& geom: collection)
{
@ -150,7 +150,7 @@ struct hit_test_visitor
}
inline bool hit_test(mapnik::geometry::geometry const& geom, double x, double y, double tol)
inline bool hit_test(mapnik::geometry::geometry<double> const& geom, double x, double y, double tol)
{
return mapnik::util::apply_visitor(detail::hit_test_visitor(x,y,tol), geom);
}

View file

@ -42,7 +42,7 @@
namespace mapnik { namespace json {
using position = mapnik::geometry::point;
using position = mapnik::geometry::point<double>;
using boxes = std::vector<std::pair<box2d<double>, std::pair<std::size_t, std::size_t>>>;
namespace qi = boost::spirit::qi;

View file

@ -65,9 +65,9 @@ struct end_container<mapnik::feature_impl const>
template <>
struct transform_attribute<const boost::fusion::cons<mapnik::feature_impl const&, boost::fusion::nil>,
mapnik::geometry::geometry const& , karma::domain>
mapnik::geometry::geometry<double> const& , karma::domain>
{
using type = mapnik::geometry::geometry const&;
using type = mapnik::geometry::geometry<double> const&;
static type pre(const boost::fusion::cons<mapnik::feature_impl const&, boost::fusion::nil>& f)
{
return boost::fusion::at<mpl::int_<0> >(f).get_geometry();
@ -98,7 +98,7 @@ struct feature_generator_grammar :
{
feature_generator_grammar();
karma::rule<OutputIterator, FeatureType const&()> feature;
geometry_generator_grammar<OutputIterator, mapnik::geometry::geometry> geometry;
geometry_generator_grammar<OutputIterator, mapnik::geometry::geometry<double> > geometry;
properties_generator_grammar<OutputIterator, FeatureType> properties;
boost::phoenix::function<get_id<FeatureType> > id_;
};

View file

@ -94,22 +94,22 @@ struct geometry_generator_grammar :
geometry_generator_grammar();
karma::rule<OutputIterator, Geometry const&()> geometry;
karma::rule<OutputIterator, karma::locals<mapnik::geometry::geometry_types>, Geometry const&() > geometry_dispatch;
karma::rule<OutputIterator, geometry::geometry const&()> point;
karma::rule<OutputIterator, geometry::point const&()> point_coord;
karma::rule<OutputIterator, geometry::geometry const&()> linestring;
karma::rule<OutputIterator, geometry::line_string const&()> linestring_coord;
karma::rule<OutputIterator, geometry::geometry const&()> polygon;
karma::rule<OutputIterator, geometry::polygon const&()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring const&()> exterior_ring_coord;
karma::rule<OutputIterator, std::vector<geometry::linear_ring> const&()> interior_ring_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> multi_point;
karma::rule<OutputIterator, geometry::multi_point const& ()> multi_point_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> multi_linestring;
karma::rule<OutputIterator, geometry::multi_line_string const& ()> multi_linestring_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> multi_polygon;
karma::rule<OutputIterator, geometry::multi_polygon const& ()> multi_polygon_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> geometry_collection;
karma::rule<OutputIterator, geometry::geometry_collection const& ()> geometries;
karma::rule<OutputIterator, geometry::geometry<double> const&()> point;
karma::rule<OutputIterator, geometry::point<double> const&()> point_coord;
karma::rule<OutputIterator, geometry::geometry<double> const&()> linestring;
karma::rule<OutputIterator, geometry::line_string<double> const&()> linestring_coord;
karma::rule<OutputIterator, geometry::geometry<double> const&()> polygon;
karma::rule<OutputIterator, geometry::polygon<double> const&()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring<double> const&()> exterior_ring_coord;
karma::rule<OutputIterator, std::vector<geometry::linear_ring<double> > const&()> interior_ring_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_point;
karma::rule<OutputIterator, geometry::multi_point<double> const& ()> multi_point_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_linestring;
karma::rule<OutputIterator, geometry::multi_line_string<double> const& ()> multi_linestring_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_polygon;
karma::rule<OutputIterator, geometry::multi_polygon<double> const& ()> multi_polygon_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> geometry_collection;
karma::rule<OutputIterator, geometry::geometry_collection<double> const& ()> geometries;
boost::phoenix::function<detail::get_type<Geometry> > geometry_type;
karma::real_generator<double, detail::json_coordinate_policy<double> > coordinate;

View file

@ -40,13 +40,13 @@ namespace qi = boost::spirit::qi;
template <typename Iterator, typename ErrorHandler = error_handler<Iterator> >
struct geometry_grammar :
qi::grammar<Iterator, mapnik::geometry::geometry() ,space_type>
qi::grammar<Iterator, mapnik::geometry::geometry<double>() ,space_type>
{
geometry_grammar();
qi::rule<Iterator, mapnik::geometry::geometry(), space_type> start;
qi::rule<Iterator, qi::locals<int, mapnik::json::coordinates>, mapnik::geometry::geometry(), space_type> geometry;
qi::rule<Iterator, mapnik::geometry::geometry<double>(), space_type> start;
qi::rule<Iterator, qi::locals<int, mapnik::json::coordinates>, mapnik::geometry::geometry<double>(), space_type> geometry;
qi::symbols<char, int> geometry_type_dispatch;
qi::rule<Iterator, mapnik::geometry::geometry_collection(), space_type> geometry_collection;
qi::rule<Iterator, mapnik::geometry::geometry_collection<double>(), space_type> geometry_collection;
positions_grammar<Iterator> coordinates;
boost::phoenix::function<create_geometry_impl> create_geometry;
// error handler

View file

@ -34,7 +34,7 @@
namespace mapnik { namespace json {
inline bool from_geojson(std::string const& json, mapnik::geometry::geometry & geom)
inline bool from_geojson(std::string const& json, mapnik::geometry::geometry<double> & geom)
{
using namespace boost::spirit;
static const geometry_grammar<char const*> g;

View file

@ -39,7 +39,7 @@ struct create_point
void operator() (position const& pos) const
{
mapnik::geometry::point point(pos.x, pos.y);
mapnik::geometry::point<double> point(pos.x, pos.y);
geom_ = std::move(point);
}
@ -59,7 +59,7 @@ struct create_linestring
std::size_t size = ring.size();
if (size > 1)
{
mapnik::geometry::line_string line;
mapnik::geometry::line_string<double> line;
line.reserve(size);
for (auto && pt : ring)
{
@ -83,7 +83,7 @@ struct create_polygon
void operator() (std::vector<positions> const& rings) const
{
mapnik::geometry::polygon poly;
mapnik::geometry::polygon<double> poly;
std::size_t num_rings = rings.size();
if (num_rings > 1)
poly.interior_rings.reserve(num_rings - 1);
@ -91,7 +91,7 @@ struct create_polygon
for ( std::size_t i = 0; i < num_rings; ++i)
{
std::size_t size = rings[i].size();
mapnik::geometry::linear_ring ring;
mapnik::geometry::linear_ring<double> ring;
ring.reserve(size);
for ( auto && pt : rings[i])
{
@ -120,7 +120,7 @@ struct create_multipoint
void operator() (positions const& points) const
{
mapnik::geometry::multi_point multi_point;
mapnik::geometry::multi_point<double> multi_point;
multi_point.reserve(points.size());
for (auto && pos : points)
{
@ -143,12 +143,12 @@ struct create_multilinestring
void operator() (std::vector<positions> const& rings) const
{
mapnik::geometry::multi_line_string multi_line;
mapnik::geometry::multi_line_string<double> multi_line;
multi_line.reserve(rings.size());
for (auto const& ring : rings)
{
mapnik::geometry::line_string line;
mapnik::geometry::line_string<double> line;
line.reserve(ring.size());
for (auto && pt : ring)
{
@ -173,11 +173,11 @@ struct create_multipolygon
void operator()(std::vector<std::vector<positions> > const& rings_array) const
{
mapnik::geometry::multi_polygon multi_poly;
mapnik::geometry::multi_polygon<double> multi_poly;
multi_poly.reserve(rings_array.size());
for (auto const& rings : rings_array)
{
mapnik::geometry::polygon poly;
mapnik::geometry::polygon<double> poly;
std::size_t num_rings = rings.size();
if ( num_rings > 1)
poly.interior_rings.reserve(num_rings - 1);
@ -185,7 +185,7 @@ struct create_multipolygon
for ( std::size_t i = 0; i < num_rings; ++i)
{
std::size_t size = rings[i].size();
mapnik::geometry::linear_ring ring;
mapnik::geometry::linear_ring<double> ring;
ring.reserve(size);
for ( auto && pt : rings[i])
{

View file

@ -45,7 +45,7 @@ namespace mapnik { namespace json {
struct empty {};
using position = mapnik::geometry::point;
using position = mapnik::geometry::point<double>;
using positions = std::vector<position>;
using coordinates = util::variant<empty, position, positions, std::vector<positions>, std::vector<std::vector<positions> > > ;

View file

@ -219,12 +219,12 @@ void apply_markers_multi(feature_impl const& feature, attributes const& vars, Co
if (placement == MARKER_POINT_PLACEMENT &&
multi_policy == MARKER_WHOLE_MULTI)
{
geometry::point pt;
geometry::point<double> pt;
if (geometry::centroid(geom, pt))
{
// unset any clipping since we're now dealing with a point
converter.template unset<clip_poly_tag>();
geometry::point_vertex_adapter va(pt);
geometry::point_vertex_adapter<double> va(pt);
converter.apply(va);
}
}
@ -235,13 +235,13 @@ void apply_markers_multi(feature_impl const& feature, attributes const& vars, Co
// TODO: consider using true area for polygon types
if (type == geometry::geometry_types::MultiPolygon)
{
geometry::multi_polygon const& multi_poly = mapnik::util::get<geometry::multi_polygon>(geom);
geometry::multi_polygon<double> const& multi_poly = mapnik::util::get<geometry::multi_polygon<double> >(geom);
double maxarea = 0;
geometry::polygon const* largest = 0;
for (geometry::polygon const& poly : multi_poly)
geometry::polygon<double> const* largest = 0;
for (geometry::polygon<double> const& poly : multi_poly)
{
box2d<double> bbox = geometry::envelope(poly);
geometry::polygon_vertex_adapter va(poly);
geometry::polygon_vertex_adapter<double> va(poly);
double area = bbox.width() * bbox.height();
if (area > maxarea)
{
@ -251,7 +251,7 @@ void apply_markers_multi(feature_impl const& feature, attributes const& vars, Co
}
if (largest)
{
geometry::polygon_vertex_adapter va(*largest);
geometry::polygon_vertex_adapter<double> va(*largest);
converter.apply(va);
}
}

View file

@ -78,7 +78,7 @@ public:
}
else
{
geometry::geometry const& geom = (*pos_)->get_geometry();
geometry::geometry<double> const& geom = (*pos_)->get_geometry();
if (bbox_.intersects(geometry::envelope(geom)))
{
return *pos_++;

View file

@ -30,8 +30,8 @@
namespace mapnik {
namespace geometry {
struct point;
struct line_string;
template <typename T> struct point;
template <typename T> struct line_string;
}
class projection;
template <typename T> class box2d;
@ -48,10 +48,10 @@ public:
bool backward (double& x, double& y , double& z) const;
bool forward (double *x, double *y , double *z, int point_count) const;
bool backward (double *x, double *y , double *z, int point_count) const;
bool forward (geometry::point & p) const;
bool backward (geometry::point & p) const;
unsigned int forward (geometry::line_string & ls) const;
unsigned int backward (geometry::line_string & ls) const;
bool forward (geometry::point<double> & p) const;
bool backward (geometry::point<double> & p) const;
unsigned int forward (geometry::line_string<double> & ls) const;
unsigned int backward (geometry::line_string<double> & ls) const;
bool forward (box2d<double> & box) const;
bool backward (box2d<double> & box) const;
bool forward (box2d<double> & box, int points) const;

View file

@ -40,9 +40,9 @@ struct apply_local_alignment
x_(x),
y_(y) {}
void operator() (geometry::polygon_vertex_adapter & va)
void operator() (geometry::polygon_vertex_adapter<double> & va)
{
using clipped_geometry_type = agg::conv_clip_polygon<geometry::polygon_vertex_adapter>;
using clipped_geometry_type = agg::conv_clip_polygon<geometry::polygon_vertex_adapter<double> >;
using path_type = transform_path_adapter<view_transform,clipped_geometry_type>;
clipped_geometry_type clipped(va);
clipped.clip_box(clip_box_.minx(),clip_box_.miny(),clip_box_.maxx(),clip_box_.maxy());

View file

@ -36,7 +36,7 @@ namespace mapnik {
namespace detail {
template <typename F1, typename F2, typename F3>
void make_building(geometry::polygon const& poly, double height, F1 const& face_func, F2 const& frame_func, F3 const& roof_func)
void make_building(geometry::polygon<double> const& poly, double height, F1 const& face_func, F2 const& frame_func, F3 const& roof_func)
{
const std::unique_ptr<path_type> frame(new path_type(path_type::types::LineString));
const std::unique_ptr<path_type> roof(new path_type(path_type::types::Polygon));
@ -44,7 +44,7 @@ void make_building(geometry::polygon const& poly, double height, F1 const& face_
double x0 = 0;
double y0 = 0;
double x,y;
geometry::polygon_vertex_adapter va(poly);
geometry::polygon_vertex_adapter<double> va(poly);
va.rewind(0);
for (unsigned cm = va.vertex(&x, &y); cm != SEG_END;
cm = va.vertex(&x, &y))
@ -115,14 +115,14 @@ void render_building_symbolizer(mapnik::feature_impl const& feature,
{
auto const& geom = feature.get_geometry();
if (geom.is<geometry::polygon>())
if (geom.is<geometry::polygon<double> >())
{
auto const& poly = geom.get<geometry::polygon>();
auto const& poly = geom.get<geometry::polygon<double> >();
detail::make_building(poly, height, face_func, frame_func, roof_func);
}
else if (geom.is<geometry::multi_polygon>())
else if (geom.is<geometry::multi_polygon<double> >())
{
auto const& multi_poly = geom.get<geometry::multi_polygon>();
auto const& multi_poly = geom.get<geometry::multi_polygon<double> >();
for (auto const& poly : multi_poly)
{
detail::make_building(poly, height, face_func, frame_func, roof_func);

View file

@ -343,7 +343,7 @@ void render_group_symbolizer(group_symbolizer const& sym,
// try to ensure that we don't get edge artefacts due to any
// symbolizers with avoid-edges set: only the avoid-edges of
// the group symbolizer itself should matter.
geometry::point origin_pt(x,y);
geometry::point<double> origin_pt(x,y);
sub_feature->set_geometry(origin_pt);
// get the layout for this set of properties
for (auto const& rule : props->get_rules())

View file

@ -63,8 +63,8 @@ void render_point_symbolizer(point_symbolizer const &sym,
agg::trans_affine recenter_tr = recenter * tr;
box2d<double> label_ext = bbox * recenter_tr * agg::trans_affine_scaling(common.scale_factor_);
mapnik::geometry::geometry const& geometry = feature.get_geometry();
mapnik::geometry::point pt;
mapnik::geometry::geometry<double> const& geometry = feature.get_geometry();
mapnik::geometry::point<double> pt;
if (placement == CENTROID_POINT_PLACEMENT)
{
if (!geometry::centroid(geometry, pt)) return;

View file

@ -62,9 +62,9 @@ class base_symbolizer_helper
{
public:
using point_cref = std::reference_wrapper<geometry::point const>;
using line_string_cref = std::reference_wrapper<geometry::line_string const>;
using polygon_cref = std::reference_wrapper<geometry::polygon const>;
using point_cref = std::reference_wrapper<geometry::point<double> const>;
using line_string_cref = std::reference_wrapper<geometry::line_string<double> const>;
using polygon_cref = std::reference_wrapper<geometry::polygon<double> const>;
using geometry_cref = util::variant<point_cref, line_string_cref, polygon_cref>;
// Using list instead of vector, because we delete random elements and need iterators to stay valid.
using geometry_container_type = std::list<geometry_cref>;

View file

@ -42,44 +42,44 @@ struct datasource_geometry_type
return mapnik::datasource_geometry_t::Unknown;
}
mapnik::datasource_geometry_t operator () (mapnik::geometry::point const&) const
mapnik::datasource_geometry_t operator () (mapnik::geometry::point<double> const&) const
{
return mapnik::datasource_geometry_t::Point;
}
mapnik::datasource_geometry_t operator () (mapnik::geometry::line_string const&) const
mapnik::datasource_geometry_t operator () (mapnik::geometry::line_string<double> const&) const
{
return mapnik::datasource_geometry_t::LineString;
}
mapnik::datasource_geometry_t operator () (mapnik::geometry::polygon const&) const
mapnik::datasource_geometry_t operator () (mapnik::geometry::polygon<double> const&) const
{
return mapnik::datasource_geometry_t::Polygon;
}
mapnik::datasource_geometry_t operator () (mapnik::geometry::multi_point const&) const
mapnik::datasource_geometry_t operator () (mapnik::geometry::multi_point<double> const&) const
{
return mapnik::datasource_geometry_t::Point;
}
mapnik::datasource_geometry_t operator () (mapnik::geometry::multi_line_string const&) const
mapnik::datasource_geometry_t operator () (mapnik::geometry::multi_line_string<double> const&) const
{
return mapnik::datasource_geometry_t::LineString;
}
mapnik::datasource_geometry_t operator () (mapnik::geometry::multi_polygon const&) const
mapnik::datasource_geometry_t operator () (mapnik::geometry::multi_polygon<double> const&) const
{
return mapnik::datasource_geometry_t::Polygon;
}
mapnik::datasource_geometry_t operator () (mapnik::geometry::geometry_collection const&) const
mapnik::datasource_geometry_t operator () (mapnik::geometry::geometry_collection<double> const&) const
{
return mapnik::datasource_geometry_t::Collection;
}
};
} // detail
static inline mapnik::datasource_geometry_t to_ds_type(mapnik::geometry::geometry const& geom)
static inline mapnik::datasource_geometry_t to_ds_type(mapnik::geometry::geometry<double> const& geom)
{
return util::apply_visitor(detail::datasource_geometry_type(), geom);
}

View file

@ -29,10 +29,10 @@
namespace mapnik { namespace util {
inline bool to_geojson(std::string & json, mapnik::geometry::geometry const& geom)
inline bool to_geojson(std::string & json, mapnik::geometry::geometry<double> const& geom)
{
using sink_type = std::back_insert_iterator<std::string>;
static const mapnik::json::geometry_generator_grammar<sink_type, mapnik::geometry::geometry> grammar;
static const mapnik::json::geometry_generator_grammar<sink_type, mapnik::geometry::geometry<double> > grammar;
sink_type sink(json);
return boost::spirit::karma::generate(sink, grammar, geom);
}

View file

@ -131,7 +131,7 @@ struct wkb_buffer
using wkb_buffer_ptr = std::unique_ptr<wkb_buffer>;
wkb_buffer_ptr point_wkb( geometry::point const& pt, wkbByteOrder byte_order)
wkb_buffer_ptr point_wkb( geometry::point<double> const& pt, wkbByteOrder byte_order)
{
std::size_t size = 1 + 4 + 8 * 2 ; // byteOrder + wkbType + Point
wkb_buffer_ptr wkb = std::make_unique<wkb_buffer>(size);
@ -144,7 +144,7 @@ wkb_buffer_ptr point_wkb( geometry::point const& pt, wkbByteOrder byte_order)
return std::move(wkb);
}
wkb_buffer_ptr line_string_wkb(geometry::line_string const& line, wkbByteOrder byte_order)
wkb_buffer_ptr line_string_wkb(geometry::line_string<double> const& line, wkbByteOrder byte_order)
{
unsigned num_points = line.size();
assert(num_points > 1);
@ -156,7 +156,7 @@ wkb_buffer_ptr line_string_wkb(geometry::line_string const& line, wkbByteOrder b
write(ss, num_points, 4, byte_order);
for (unsigned i=0; i< num_points; ++i)
{
geometry::point const& pt = line[i];
geometry::point<double> const& pt = line[i];
write(ss, pt.x, 8, byte_order);
write(ss, pt.y, 8, byte_order);
}
@ -164,7 +164,7 @@ wkb_buffer_ptr line_string_wkb(geometry::line_string const& line, wkbByteOrder b
return std::move(wkb);
}
wkb_buffer_ptr polygon_wkb( geometry::polygon const& poly, wkbByteOrder byte_order)
wkb_buffer_ptr polygon_wkb( geometry::polygon<double> const& poly, wkbByteOrder byte_order)
{
std::size_t size = 1 + 4 + 4 ; // byteOrder + wkbType + numRings
size += 4 + 2 * 8 * poly.exterior_ring.size();
@ -202,7 +202,7 @@ wkb_buffer_ptr polygon_wkb( geometry::polygon const& poly, wkbByteOrder byte_ord
return std::move(wkb);
}
wkb_buffer_ptr multi_point_wkb( geometry::multi_point const& multi_pt, wkbByteOrder byte_order)
wkb_buffer_ptr multi_point_wkb( geometry::multi_point<double> const& multi_pt, wkbByteOrder byte_order)
{
std::size_t size = 1 + 4 + 4 + (1 + 4 + 8 * 2) * multi_pt.size() ; // byteOrder + wkbType + num_point + Point.size * num_points
wkb_buffer_ptr wkb = std::make_unique<wkb_buffer>(size);
@ -233,7 +233,7 @@ struct geometry_to_wkb
geometry_to_wkb(wkbByteOrder byte_order)
: byte_order_(byte_order) {}
result_type operator() (geometry::geometry const& geom) const
result_type operator() (geometry::geometry<double> const& geom) const
{
return util::apply_visitor(*this, geom);
}
@ -243,24 +243,24 @@ struct geometry_to_wkb
return result_type();
}
result_type operator() (geometry::point const& pt) const
result_type operator() (geometry::point<double> const& pt) const
{
return point_wkb(pt, byte_order_);
}
result_type operator() (geometry::line_string const& line) const
result_type operator() (geometry::line_string<double> const& line) const
{
return line_string_wkb(line, byte_order_);
}
result_type operator() (geometry::polygon const& poly) const
result_type operator() (geometry::polygon<double> const& poly) const
{
return polygon_wkb(poly, byte_order_);
}
// multi/collection
result_type operator() (geometry::multi_point const& multi_pt) const
result_type operator() (geometry::multi_point<double> const& multi_pt) const
{
return multi_point_wkb(multi_pt, byte_order_);
}

View file

@ -32,10 +32,10 @@
namespace mapnik { namespace util {
inline bool to_wkt(std::string & wkt, mapnik::geometry::geometry const& geom)
inline bool to_wkt(std::string & wkt, mapnik::geometry::geometry<double> const& geom)
{
using sink_type = std::back_insert_iterator<std::string>;
static const mapnik::wkt::wkt_generator_grammar<sink_type, mapnik::geometry::geometry> generator;
static const mapnik::wkt::wkt_generator_grammar<sink_type, mapnik::geometry::geometry<double> > generator;
sink_type sink(wkt);
return boost::spirit::karma::generate(sink, generator, geom);
}

View file

@ -28,90 +28,90 @@
namespace boost { namespace spirit { namespace traits {
template <>
struct transform_attribute<mapnik::geometry::geometry const,
mapnik::geometry::point const&, karma::domain>
struct transform_attribute<mapnik::geometry::geometry<double> const,
mapnik::geometry::point<double> const&, karma::domain>
{
using type = mapnik::geometry::point const&;
static type pre(mapnik::geometry::geometry const& geom)
using type = mapnik::geometry::point<double> const&;
static type pre(mapnik::geometry::geometry<double> const& geom)
{
return mapnik::util::get<mapnik::geometry::point>(geom);
return mapnik::util::get<mapnik::geometry::point<double> >(geom);
}
};
template <>
struct transform_attribute<mapnik::geometry::geometry const,
mapnik::geometry::line_string const&, karma::domain>
struct transform_attribute<mapnik::geometry::geometry<double> const,
mapnik::geometry::line_string<double> const&, karma::domain>
{
using type = mapnik::geometry::line_string const&;
static type pre(mapnik::geometry::geometry const& geom)
using type = mapnik::geometry::line_string<double> const&;
static type pre(mapnik::geometry::geometry<double> const& geom)
{
return mapnik::util::get<mapnik::geometry::line_string>(geom);
return mapnik::util::get<mapnik::geometry::line_string<double> >(geom);
}
};
template <>
struct transform_attribute<mapnik::geometry::geometry const,
mapnik::geometry::polygon const&, karma::domain>
struct transform_attribute<mapnik::geometry::geometry<double> const,
mapnik::geometry::polygon<double> const&, karma::domain>
{
using type = mapnik::geometry::polygon const&;
static type pre(mapnik::geometry::geometry const& geom)
using type = mapnik::geometry::polygon<double> const&;
static type pre(mapnik::geometry::geometry<double> const& geom)
{
return mapnik::util::get<mapnik::geometry::polygon>(geom);
return mapnik::util::get<mapnik::geometry::polygon<double> >(geom);
}
};
template <>
struct transform_attribute<mapnik::geometry::polygon const,
std::vector<mapnik::geometry::linear_ring> const&, karma::domain>
struct transform_attribute<mapnik::geometry::polygon<double> const,
std::vector<mapnik::geometry::linear_ring<double> > const&, karma::domain>
{
using type = std::vector<mapnik::geometry::linear_ring> const&;
static type pre(mapnik::geometry::polygon const& poly)
using type = std::vector<mapnik::geometry::linear_ring<double> > const&;
static type pre(mapnik::geometry::polygon<double> const& poly)
{
return poly.interior_rings;
}
};
template <>
struct transform_attribute<mapnik::geometry::geometry const,
mapnik::geometry::multi_point const&, karma::domain>
struct transform_attribute<mapnik::geometry::geometry<double> const,
mapnik::geometry::multi_point<double> const&, karma::domain>
{
using type = mapnik::geometry::multi_point const&;
static type pre(mapnik::geometry::geometry const& geom)
using type = mapnik::geometry::multi_point<double> const&;
static type pre(mapnik::geometry::geometry<double> const& geom)
{
return mapnik::util::get<mapnik::geometry::multi_point>(geom);
return mapnik::util::get<mapnik::geometry::multi_point<double> >(geom);
}
};
template <>
struct transform_attribute<mapnik::geometry::geometry const,
mapnik::geometry::multi_line_string const&, karma::domain>
struct transform_attribute<mapnik::geometry::geometry<double> const,
mapnik::geometry::multi_line_string<double> const&, karma::domain>
{
using type = mapnik::geometry::multi_line_string const&;
static type pre(mapnik::geometry::geometry const& geom)
using type = mapnik::geometry::multi_line_string<double> const&;
static type pre(mapnik::geometry::geometry<double> const& geom)
{
return mapnik::util::get<mapnik::geometry::multi_line_string>(geom);
return mapnik::util::get<mapnik::geometry::multi_line_string<double> >(geom);
}
};
template <>
struct transform_attribute<mapnik::geometry::geometry const,
mapnik::geometry::multi_polygon const&, karma::domain>
struct transform_attribute<mapnik::geometry::geometry<double> const,
mapnik::geometry::multi_polygon<double> const&, karma::domain>
{
using type = mapnik::geometry::multi_polygon const&;
static type pre(mapnik::geometry::geometry const& geom)
using type = mapnik::geometry::multi_polygon<double> const&;
static type pre(mapnik::geometry::geometry<double> const& geom)
{
return mapnik::util::get<mapnik::geometry::multi_polygon>(geom);
return mapnik::util::get<mapnik::geometry::multi_polygon<double> >(geom);
}
};
template <>
struct transform_attribute<mapnik::geometry::geometry const,
mapnik::geometry::geometry_collection const&, karma::domain>
struct transform_attribute<mapnik::geometry::geometry<double> const,
mapnik::geometry::geometry_collection<double> const&, karma::domain>
{
using type = mapnik::geometry::geometry_collection const&;
static type pre(mapnik::geometry::geometry const& geom)
using type = mapnik::geometry::geometry_collection<double> const&;
static type pre(mapnik::geometry::geometry<double> const& geom)
{
return mapnik::util::get<mapnik::geometry::geometry_collection>(geom);
return mapnik::util::get<mapnik::geometry::geometry_collection<double> >(geom);
}
};

View file

@ -29,11 +29,12 @@
namespace mapnik { namespace geometry {
template <typename T>
struct point_vertex_adapter
{
using value_type = typename point::value_type;
using value_type = typename point<T>::value_type;
point_vertex_adapter(point const& pt)
point_vertex_adapter(point<T> const& pt)
: pt_(pt),
first_(true) {}
@ -59,14 +60,15 @@ struct point_vertex_adapter
return geometry_types::Point;
}
point const& pt_;
point<T> const& pt_;
mutable bool first_;
};
template <typename T>
struct line_string_vertex_adapter
{
using value_type = typename point::value_type;
line_string_vertex_adapter(line_string const& line)
using value_type = typename point<T>::value_type;
line_string_vertex_adapter(line_string<T> const& line)
: line_(line),
current_index_(0),
end_index_(line.size())
@ -76,7 +78,7 @@ struct line_string_vertex_adapter
{
if (current_index_ != end_index_)
{
point const& coord = line_[current_index_++];
point<T> const& coord = line_[current_index_++];
*x = coord.x;
*y = coord.y;
if (current_index_ == 1)
@ -101,16 +103,17 @@ struct line_string_vertex_adapter
return geometry_types::LineString;
}
line_string const& line_;
line_string<T> const& line_;
mutable std::size_t current_index_;
const std::size_t end_index_;
};
template <typename T>
struct polygon_vertex_adapter
{
using value_type = typename point::value_type;
polygon_vertex_adapter(polygon const& poly)
using value_type = typename point<T>::value_type;
polygon_vertex_adapter(polygon<T> const& poly)
: poly_(poly),
rings_itr_(0),
rings_end_(poly_.interior_rings.size() + 1),
@ -135,7 +138,7 @@ struct polygon_vertex_adapter
}
if (current_index_ < end_index_)
{
point const& coord = (rings_itr_ == 0) ?
point<T> const& coord = (rings_itr_ == 0) ?
poly_.exterior_ring[current_index_++] : poly_.interior_rings[rings_itr_- 1][current_index_++];
*x = coord.x;
*y = coord.y;
@ -156,7 +159,7 @@ struct polygon_vertex_adapter
{
current_index_ = 0;
end_index_ = poly_.interior_rings[rings_itr_ - 1].size();
point const& coord = poly_.interior_rings[rings_itr_ - 1][current_index_++];
point<T> const& coord = poly_.interior_rings[rings_itr_ - 1][current_index_++];
*x = coord.x;
*y = coord.y;
return mapnik::SEG_MOVETO;
@ -170,7 +173,7 @@ struct polygon_vertex_adapter
}
private:
polygon const& poly_;
polygon<T> const& poly_;
mutable std::size_t rings_itr_;
mutable std::size_t rings_end_;
mutable std::size_t current_index_;
@ -179,42 +182,42 @@ private:
};
template <typename T>
struct vertex_adapter_traits{};
struct vertex_adapter_traits {};
template <>
struct vertex_adapter_traits<point>
struct vertex_adapter_traits<point<double> >
{
using type = point_vertex_adapter;
using type = point_vertex_adapter<double>;
};
template <>
struct vertex_adapter_traits<line_string>
struct vertex_adapter_traits<line_string<double> >
{
using type = line_string_vertex_adapter;
using type = line_string_vertex_adapter<double>;
};
template <>
struct vertex_adapter_traits<polygon>
struct vertex_adapter_traits<polygon<double> >
{
using type = polygon_vertex_adapter;
using type = polygon_vertex_adapter<double>;
};
template <>
struct vertex_adapter_traits<multi_point>
struct vertex_adapter_traits<multi_point<double> >
{
using type = point_vertex_adapter;
using type = point_vertex_adapter<double>;
};
template <>
struct vertex_adapter_traits<multi_line_string>
struct vertex_adapter_traits<multi_line_string<double> >
{
using type = line_string_vertex_adapter;
using type = line_string_vertex_adapter<double>;
};
template <>
struct vertex_adapter_traits<multi_polygon>
struct vertex_adapter_traits<multi_polygon<double> >
{
using type = polygon_vertex_adapter;
using type = polygon_vertex_adapter<double>;
};
}}

View file

@ -43,52 +43,60 @@ struct vertex_processor
{
// no-op
}
void operator() (point const& pt)
template <typename T1>
void operator() (point<T1> const& pt)
{
point_vertex_adapter va(pt);
point_vertex_adapter<T1> va(pt);
proc_(va);
}
void operator() (line_string const& line)
template <typename T1>
void operator() (line_string<T1> const& line)
{
line_string_vertex_adapter va(line);
line_string_vertex_adapter<T1> va(line);
proc_(va);
}
void operator() (polygon const& poly)
template <typename T1>
void operator() (polygon<T1> const& poly)
{
polygon_vertex_adapter va(poly);
polygon_vertex_adapter<T1> va(poly);
proc_(va);
}
void operator() (multi_point const& multi_pt)
template <typename T1>
void operator() (multi_point<T1> const& multi_pt)
{
for (auto const& pt : multi_pt)
{
point_vertex_adapter va(pt);
point_vertex_adapter<T1> va(pt);
proc_(va);
}
}
void operator() (multi_line_string const& multi_line)
template <typename T1>
void operator() (multi_line_string<T1> const& multi_line)
{
for (auto const& line : multi_line)
{
line_string_vertex_adapter va(line);
line_string_vertex_adapter<T1> va(line);
proc_(va);
}
}
void operator() (multi_polygon const& multi_poly)
template <typename T1>
void operator() (multi_polygon<T1> const& multi_poly)
{
for ( auto const& poly : multi_poly)
{
polygon_vertex_adapter va(poly);
polygon_vertex_adapter<T1> va(poly);
proc_(va);
}
}
void operator() (geometry_collection const& collection)
template <typename T1>
void operator() (geometry_collection<T1> const& collection)
{
for (auto const& geom : collection)
{

View file

@ -90,7 +90,7 @@ static inline bool merc2lonlat(double * x, double * y , int point_count)
return true;
}
static inline bool lonlat2merc(geometry::line_string & ls)
static inline bool lonlat2merc(geometry::line_string<double> & ls)
{
for(auto & p : ls)
{
@ -105,7 +105,7 @@ static inline bool lonlat2merc(geometry::line_string & ls)
return true;
}
static inline bool merc2lonlat(geometry::line_string & ls)
static inline bool merc2lonlat(geometry::line_string<double> & ls)
{
for (auto & p : ls)
{

View file

@ -59,7 +59,7 @@ class MAPNIK_DECL geometry_utils : private util::noncopyable
{
public:
static mapnik::geometry::geometry from_wkb(const char* wkb,
static mapnik::geometry::geometry<double> from_wkb(const char* wkb,
unsigned size,
wkbFormat format = wkbGeneric);
};

View file

@ -34,7 +34,7 @@
namespace mapnik {
inline bool from_wkt(std::string const& wkt, mapnik::geometry::geometry & geom)
inline bool from_wkt(std::string const& wkt, mapnik::geometry::geometry<double> & geom)
{
using namespace boost::spirit;
static const mapnik::wkt::wkt_grammar<std::string::const_iterator> g;

View file

@ -95,22 +95,22 @@ struct wkt_generator_grammar :
// rules
karma::rule<OutputIterator, Geometry const&()> geometry;
karma::rule<OutputIterator, karma::locals<mapnik::geometry::geometry_types>, Geometry const&() > geometry_dispatch;
karma::rule<OutputIterator, geometry::geometry const&()> point;
karma::rule<OutputIterator, geometry::point const&()> point_coord;
karma::rule<OutputIterator, geometry::geometry const&()> linestring;
karma::rule<OutputIterator, geometry::line_string const&()> linestring_coord;
karma::rule<OutputIterator, geometry::geometry const&()> polygon;
karma::rule<OutputIterator, geometry::polygon const&()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring const&()> exterior_ring_coord;
karma::rule<OutputIterator, std::vector<geometry::linear_ring> const&()> interior_ring_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> multi_point;
karma::rule<OutputIterator, geometry::multi_point const& ()> multi_point_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> multi_linestring;
karma::rule<OutputIterator, geometry::multi_line_string const& ()> multi_linestring_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> multi_polygon;
karma::rule<OutputIterator, geometry::multi_polygon const& ()> multi_polygon_coord;
karma::rule<OutputIterator, geometry::geometry const& ()> geometry_collection;
karma::rule<OutputIterator, geometry::geometry_collection const& ()> geometries;
karma::rule<OutputIterator, geometry::geometry<double> const&()> point;
karma::rule<OutputIterator, geometry::point<double> const&()> point_coord;
karma::rule<OutputIterator, geometry::geometry<double> const&()> linestring;
karma::rule<OutputIterator, geometry::line_string<double> const&()> linestring_coord;
karma::rule<OutputIterator, geometry::geometry<double> const&()> polygon;
karma::rule<OutputIterator, geometry::polygon<double> const&()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring<double> const&()> exterior_ring_coord;
karma::rule<OutputIterator, std::vector<geometry::linear_ring<double> > const&()> interior_ring_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_point;
karma::rule<OutputIterator, geometry::multi_point<double> const& ()> multi_point_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_linestring;
karma::rule<OutputIterator, geometry::multi_line_string<double> const& ()> multi_linestring_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> multi_polygon;
karma::rule<OutputIterator, geometry::multi_polygon<double> const& ()> multi_polygon_coord;
karma::rule<OutputIterator, geometry::geometry<double> const& ()> geometry_collection;
karma::rule<OutputIterator, geometry::geometry_collection<double> const& ()> geometries;
boost::phoenix::function<detail::get_type<Geometry> > geometry_type;
karma::symbols<mapnik::geometry::geometry_types, char const*> empty;
//

View file

@ -75,7 +75,7 @@ wkt_generator_grammar<OutputIterator, Geometry>::wkt_generator_grammar()
<< (geometry_collection | empty[_1 = _a]))
|
(&uint_(geometry::geometry_types::Unknown)[_1 = _a]
<< lit("POINT EMPTY")) // special case for geometry_empty as mapnik::geometry::point can't be empty
<< lit("POINT EMPTY")) // special case for geometry_empty as mapnik::geometry::point<double> can't be empty
;
point = lit("POINT(") << point_coord << lit(")")

View file

@ -85,29 +85,29 @@ struct add_hole
}
template <typename Iterator>
struct wkt_grammar : qi::grammar<Iterator, void(mapnik::geometry::geometry&) , ascii::space_type>
struct wkt_grammar : qi::grammar<Iterator, void(mapnik::geometry::geometry<double> &) , ascii::space_type>
{
wkt_grammar();
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> geometry_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> point_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> linestring_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> polygon_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> multipoint_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> multilinestring_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> multipolygon_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry&), ascii::space_type> geometrycollection_tagged_text;
qi::rule<Iterator, mapnik::geometry::point(), ascii::space_type> point_text;
qi::rule<Iterator, mapnik::geometry::line_string(), ascii::space_type> linestring_text;
qi::rule<Iterator, mapnik::geometry::linear_ring(), ascii::space_type> linearring_text;
qi::rule<Iterator, mapnik::geometry::polygon(), ascii::space_type> polygon_text;
qi::rule<Iterator, mapnik::geometry::multi_point(), ascii::space_type> multipoint_text;
qi::rule<Iterator, mapnik::geometry::multi_line_string(), ascii::space_type> multilinestring_text;
qi::rule<Iterator, mapnik::geometry::multi_polygon(), ascii::space_type> multipolygon_text;
qi::rule<Iterator, qi::locals<mapnik::geometry::geometry>,
mapnik::geometry::geometry_collection(), ascii::space_type> geometrycollection_text;
qi::rule<Iterator, mapnik::geometry::point(), ascii::space_type> point;
qi::rule<Iterator, mapnik::geometry::line_string(), ascii::space_type> points;
qi::rule<Iterator, mapnik::geometry::linear_ring(), ascii::space_type> ring_points;
qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> geometry_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> point_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> linestring_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> polygon_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> multipoint_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> multilinestring_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> multipolygon_tagged_text;
qi::rule<Iterator, void(mapnik::geometry::geometry<double> &), ascii::space_type> geometrycollection_tagged_text;
qi::rule<Iterator, mapnik::geometry::point<double>(), ascii::space_type> point_text;
qi::rule<Iterator, mapnik::geometry::line_string<double>(), ascii::space_type> linestring_text;
qi::rule<Iterator, mapnik::geometry::linear_ring<double>(), ascii::space_type> linearring_text;
qi::rule<Iterator, mapnik::geometry::polygon<double>(), ascii::space_type> polygon_text;
qi::rule<Iterator, mapnik::geometry::multi_point<double>(), ascii::space_type> multipoint_text;
qi::rule<Iterator, mapnik::geometry::multi_line_string<double>(), ascii::space_type> multilinestring_text;
qi::rule<Iterator, mapnik::geometry::multi_polygon<double>(), ascii::space_type> multipolygon_text;
qi::rule<Iterator, qi::locals<mapnik::geometry::geometry<double> >,
mapnik::geometry::geometry_collection<double>(), ascii::space_type> geometrycollection_text;
qi::rule<Iterator, mapnik::geometry::point<double>(), ascii::space_type> point;
qi::rule<Iterator, mapnik::geometry::line_string<double>(), ascii::space_type> points;
qi::rule<Iterator, mapnik::geometry::linear_ring<double>(), ascii::space_type> ring_points;
qi::rule<Iterator,ascii::space_type> empty_set;
boost::phoenix::function<detail::assign> assign;
boost::phoenix::function<detail::move_part> move_part;

View file

@ -63,7 +63,7 @@ wkt_grammar<Iterator>::wkt_grammar()
// <point text> ::= <empty set> | <left paren> <point> <right paren>
point_text = (lit("(") >> point >> lit(')'))
//| empty_set - we're catching 'POINT EMPTY' case in point_tagged_text rule ^^ by creating geometry_empty
// because our geometry::point can't be empty
// because our geometry::point<double> can't be empty
;
//<linestring tagged text> ::= linestring <linestring text>
@ -133,7 +133,7 @@ wkt_grammar<Iterator>::wkt_grammar()
// geometry collection text
geometrycollection_text = (lit('(')
>> ( eps[_a = construct<geometry::geometry>()]
>> ( eps[_a = construct<geometry::geometry<double> >()]
>> geometry_tagged_text(_a)[move_part(_val,_a)] % lit(','))
>> lit(')'))
|

View file

@ -541,7 +541,7 @@ void csv_datasource::parse_csv(T & stream,
{
break;
}
mapnik::geometry::geometry geom;
mapnik::geometry::geometry<double> geom;
if (mapnik::from_wkt(value, geom))
{
// correct orientations etc
@ -581,7 +581,7 @@ void csv_datasource::parse_csv(T & stream,
{
break;
}
mapnik::geometry::geometry geom;
mapnik::geometry::geometry<double> geom;
if (mapnik::json::from_geojson(value, geom))
{
feature->set_geometry(std::move(geom));
@ -816,7 +816,7 @@ void csv_datasource::parse_csv(T & stream,
{
if (parsed_x && parsed_y)
{
mapnik::geometry::point pt(x,y);
mapnik::geometry::point<double> pt(x,y);
feature->set_geometry(std::move(pt));
features_.push_back(feature);
null_geom = false;

View file

@ -613,7 +613,7 @@ feature_ptr gdal_featureset::get_feature_at_point(mapnik::coord2d const& pt)
{
// construct feature
feature_ptr feature = feature_factory::create(ctx_,1);
feature->set_geometry(mapnik::geometry::point(pt.x,pt.y));
feature->set_geometry(mapnik::geometry::point<double>(pt.x,pt.y));
feature->put_new("value",value);
if (raster_has_nodata)
{

View file

@ -29,7 +29,7 @@
#include <ogr_core.h>
#include <ogr_geometry.h>
mapnik::geometry::geometry ogr_converter::convert_geometry(OGRGeometry* ogr_geom)
mapnik::geometry::geometry<double> ogr_converter::convert_geometry(OGRGeometry* ogr_geom)
{
// NOTE: wkbFlatten macro in ogr flattens 2.5d types into base 2d type
switch (wkbFlatten(ogr_geom->getGeometryType()))
@ -65,19 +65,19 @@ mapnik::geometry::geometry ogr_converter::convert_geometry(OGRGeometry* ogr_geom
MAPNIK_LOG_WARN(ogr) << "ogr_converter: unknown <ogr> geometry_type="
<< wkbFlatten(ogr_geom->getGeometryType());
}
return mapnik::geometry::geometry();
return mapnik::geometry::geometry<double>();
break;
}
}
mapnik::geometry::point ogr_converter::convert_point(OGRPoint* ogr_geom)
mapnik::geometry::point<double> ogr_converter::convert_point(OGRPoint* ogr_geom)
{
return mapnik::geometry::point(ogr_geom->getX(), ogr_geom->getY());
return mapnik::geometry::point<double>(ogr_geom->getX(), ogr_geom->getY());
}
mapnik::geometry::multi_point ogr_converter::convert_multipoint(OGRMultiPoint* ogr_geom)
mapnik::geometry::multi_point<double> ogr_converter::convert_multipoint(OGRMultiPoint* ogr_geom)
{
mapnik::geometry::multi_point geom;
mapnik::geometry::multi_point<double> geom;
int num_geometries = ogr_geom->getNumGeometries();
geom.reserve(num_geometries);
for (int i = 0; i < num_geometries; ++i)
@ -88,9 +88,9 @@ mapnik::geometry::multi_point ogr_converter::convert_multipoint(OGRMultiPoint* o
return geom;
}
mapnik::geometry::line_string ogr_converter::convert_linestring(OGRLineString* ogr_geom)
mapnik::geometry::line_string<double> ogr_converter::convert_linestring(OGRLineString* ogr_geom)
{
mapnik::geometry::line_string geom;
mapnik::geometry::line_string<double> geom;
int num_points = ogr_geom->getNumPoints();
geom.reserve(num_points);
for (int i = 0; i < num_points; ++i)
@ -100,9 +100,9 @@ mapnik::geometry::line_string ogr_converter::convert_linestring(OGRLineString* o
return geom;
}
mapnik::geometry::multi_line_string ogr_converter::convert_multilinestring(OGRMultiLineString* ogr_geom)
mapnik::geometry::multi_line_string<double> ogr_converter::convert_multilinestring(OGRMultiLineString* ogr_geom)
{
mapnik::geometry::multi_line_string geom;
mapnik::geometry::multi_line_string<double> geom;
int num_geometries = ogr_geom->getNumGeometries();
geom.reserve(num_geometries);
for (int i = 0; i < num_geometries; ++i)
@ -114,10 +114,10 @@ mapnik::geometry::multi_line_string ogr_converter::convert_multilinestring(OGRMu
}
mapnik::geometry::polygon ogr_converter::convert_polygon(OGRPolygon* ogr_geom)
mapnik::geometry::polygon<double> ogr_converter::convert_polygon(OGRPolygon* ogr_geom)
{
mapnik::geometry::polygon geom;
mapnik::geometry::linear_ring exterior;
mapnik::geometry::polygon<double> geom;
mapnik::geometry::linear_ring<double> exterior;
OGRLinearRing* ogr_exterior = ogr_geom->getExteriorRing();
int num_points = ogr_exterior->getNumPoints();
exterior.reserve(num_points);
@ -131,7 +131,7 @@ mapnik::geometry::polygon ogr_converter::convert_polygon(OGRPolygon* ogr_geom)
for (int r = 0; r < num_interior; ++r)
{
OGRLinearRing* ogr_interior = ogr_geom->getInteriorRing(r);
mapnik::geometry::linear_ring interior;
mapnik::geometry::linear_ring<double> interior;
int num_interior_points = ogr_interior->getNumPoints();
interior.reserve(num_interior_points);
for (int i = 0; i < num_interior_points; ++i)
@ -143,9 +143,9 @@ mapnik::geometry::polygon ogr_converter::convert_polygon(OGRPolygon* ogr_geom)
return geom;
}
mapnik::geometry::multi_polygon ogr_converter::convert_multipolygon(OGRMultiPolygon* ogr_geom)
mapnik::geometry::multi_polygon<double> ogr_converter::convert_multipolygon(OGRMultiPolygon* ogr_geom)
{
mapnik::geometry::multi_polygon geom;
mapnik::geometry::multi_polygon<double> geom;
int num_geometries = ogr_geom->getNumGeometries();
geom.reserve(num_geometries);
for (int i = 0; i < num_geometries; ++i)
@ -156,9 +156,9 @@ mapnik::geometry::multi_polygon ogr_converter::convert_multipolygon(OGRMultiPoly
return geom;
}
mapnik::geometry::geometry_collection ogr_converter::convert_collection(OGRGeometryCollection* ogr_geom)
mapnik::geometry::geometry_collection<double> ogr_converter::convert_collection(OGRGeometryCollection* ogr_geom)
{
mapnik::geometry::geometry_collection geom;
mapnik::geometry::geometry_collection<double> geom;
int num_geometries = ogr_geom->getNumGeometries();
geom.reserve(num_geometries);
for (int i = 0; i < num_geometries; ++i)

View file

@ -39,14 +39,14 @@ class ogr_converter
{
public:
static mapnik::geometry::geometry convert_geometry (OGRGeometry* ogr_geom);
static mapnik::geometry::point convert_point (OGRPoint* ogr_geom);
static mapnik::geometry::multi_point convert_multipoint (OGRMultiPoint* ogr_geom);
static mapnik::geometry::line_string convert_linestring (OGRLineString* ogr_geom);
static mapnik::geometry::multi_line_string convert_multilinestring (OGRMultiLineString* ogr_geom);
static mapnik::geometry::polygon convert_polygon (OGRPolygon* ogr_geom);
static mapnik::geometry::multi_polygon convert_multipolygon (OGRMultiPolygon* ogr_geom);
static mapnik::geometry::geometry_collection convert_collection (OGRGeometryCollection* ogr_geom);
static mapnik::geometry::geometry<double> convert_geometry (OGRGeometry* ogr_geom);
static mapnik::geometry::point<double> convert_point (OGRPoint* ogr_geom);
static mapnik::geometry::multi_point<double> convert_multipoint (OGRMultiPoint* ogr_geom);
static mapnik::geometry::line_string<double> convert_linestring (OGRLineString* ogr_geom);
static mapnik::geometry::multi_line_string<double> convert_multilinestring (OGRMultiLineString* ogr_geom);
static mapnik::geometry::polygon<double> convert_polygon (OGRPolygon* ogr_geom);
static mapnik::geometry::multi_polygon<double> convert_multipolygon (OGRMultiPolygon* ogr_geom);
static mapnik::geometry::geometry_collection<double> convert_collection (OGRGeometryCollection* ogr_geom);
};
#endif // OGR_CONVERTER_HPP

View file

@ -81,7 +81,7 @@ feature_ptr osm_featureset<filterT>::next()
feature = feature_factory::create(ctx_, cur_item->id);
if (static_cast<osm_way*>(cur_item)->is_polygon())
{
mapnik::geometry::linear_ring ring;
mapnik::geometry::linear_ring<double> ring;
for (unsigned int count = 0;
count < static_cast<osm_way*>(cur_item)->nodes.size();
count++)
@ -89,13 +89,13 @@ feature_ptr osm_featureset<filterT>::next()
ring.add_coord(static_cast<osm_way*>(cur_item)->nodes[count]->lon,
static_cast<osm_way*>(cur_item)->nodes[count]->lat);
}
mapnik::geometry::polygon geom;
mapnik::geometry::polygon<double> geom;
geom.set_exterior_ring(std::move(ring));
feature->set_geometry(std::move(geom));
}
else
{
mapnik::geometry::line_string geom;
mapnik::geometry::line_string<double> geom;
for (unsigned int count = 0;
count < static_cast<osm_way*>(cur_item)->nodes.size();
count++)

View file

@ -122,7 +122,7 @@ feature_ptr postgis_featureset::next()
int size = rs_->getFieldLength(0);
const char *data = rs_->getValue(0);
mapnik::geometry::geometry geometry = geometry_utils::from_wkb(data, size);
mapnik::geometry::geometry<double> geometry = geometry_utils::from_wkb(data, size);
feature->set_geometry(std::move(geometry));
totalGeomSize_ += size;

View file

@ -87,7 +87,7 @@ feature_ptr shape_featureset<filterT>::next()
double y = record.read_double();
if (!filter_.pass(mapnik::box2d<double>(x,y,x,y)))
continue;
feature->set_geometry(mapnik::geometry::point(x,y));
feature->set_geometry(mapnik::geometry::point<double>(x,y));
break;
}
case shape_io::shape_multipoint:
@ -97,12 +97,12 @@ feature_ptr shape_featureset<filterT>::next()
shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue;
int num_points = record.read_ndr_integer();
mapnik::geometry::multi_point multi_point;
mapnik::geometry::multi_point<double> multi_point;
for (int i = 0; i < num_points; ++i)
{
double x = record.read_double();
double y = record.read_double();
multi_point.emplace_back(mapnik::geometry::point(x, y));
multi_point.emplace_back(mapnik::geometry::point<double>(x, y));
}
feature->set_geometry(std::move(multi_point));
break;

View file

@ -103,7 +103,7 @@ feature_ptr shape_index_featureset<filterT>::next()
{
double x = record.read_double();
double y = record.read_double();
feature->set_geometry(mapnik::geometry::point(x,y));
feature->set_geometry(mapnik::geometry::point<double>(x,y));
break;
}
case shape_io::shape_multipoint:
@ -113,12 +113,12 @@ feature_ptr shape_index_featureset<filterT>::next()
shape_io::read_bbox(record, feature_bbox_);
if (!filter_.pass(feature_bbox_)) continue;
int num_points = record.read_ndr_integer();
mapnik::geometry::multi_point multi_point;
mapnik::geometry::multi_point<double> multi_point;
for (int i = 0; i < num_points; ++i)
{
double x = record.read_double();
double y = record.read_double();
multi_point.emplace_back(mapnik::geometry::point(x, y));
multi_point.emplace_back(mapnik::geometry::point<double>(x, y));
}
feature->set_geometry(std::move(multi_point));
break;

View file

@ -88,15 +88,15 @@ void shape_io::read_bbox(shape_file::record_type & record, mapnik::box2d<double>
bbox.init(lox, loy, hix, hiy);
}
mapnik::geometry::geometry shape_io::read_polyline(shape_file::record_type & record)
mapnik::geometry::geometry<double> shape_io::read_polyline(shape_file::record_type & record)
{
mapnik::geometry::geometry geom; // default empty
mapnik::geometry::geometry<double> geom; // default empty
int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer();
if (num_parts == 1)
{
mapnik::geometry::line_string line;
mapnik::geometry::line_string<double> line;
line.reserve(num_points);
record.skip(4);
for (int i = 0; i < num_points; ++i)
@ -116,7 +116,7 @@ mapnik::geometry::geometry shape_io::read_polyline(shape_file::record_type & rec
}
int start, end;
mapnik::geometry::multi_line_string multi_line;
mapnik::geometry::multi_line_string<double> multi_line;
for (int k = 0; k < num_parts; ++k)
{
start = parts[k];
@ -129,7 +129,7 @@ mapnik::geometry::geometry shape_io::read_polyline(shape_file::record_type & rec
end = parts[k + 1];
}
mapnik::geometry::line_string line;
mapnik::geometry::line_string<double> line;
line.reserve(end - start);
for (int j = start; j < end; ++j)
{
@ -145,9 +145,9 @@ mapnik::geometry::geometry shape_io::read_polyline(shape_file::record_type & rec
}
mapnik::geometry::geometry shape_io::read_polygon(shape_file::record_type & record)
mapnik::geometry::geometry<double> shape_io::read_polygon(shape_file::record_type & record)
{
mapnik::geometry::geometry geom; // default empty
mapnik::geometry::geometry<double> geom; // default empty
int num_parts = record.read_ndr_integer();
int num_points = record.read_ndr_integer();
@ -158,15 +158,15 @@ mapnik::geometry::geometry shape_io::read_polygon(shape_file::record_type & reco
parts[i] = record.read_ndr_integer();
}
mapnik::geometry::multi_polygon multi_poly;
mapnik::geometry::polygon poly;
mapnik::geometry::multi_polygon<double> multi_poly;
mapnik::geometry::polygon<double> poly;
for (int k = 0; k < num_parts; ++k)
{
int start = parts[k];
int end;
if (k == num_parts - 1) end = num_points;
else end = parts[k + 1];
mapnik::geometry::linear_ring ring;
mapnik::geometry::linear_ring<double> ring;
ring.reserve(end - start);
for (int j = start; j < end; ++j)
{

View file

@ -76,8 +76,8 @@ public:
void move_to(std::streampos pos);
static void read_bbox(shape_file::record_type & record, mapnik::box2d<double> & bbox);
static mapnik::geometry::geometry read_polyline(shape_file::record_type & record);
static mapnik::geometry::geometry read_polygon(shape_file::record_type & record);
static mapnik::geometry::geometry<double> read_polyline(shape_file::record_type & record);
static mapnik::geometry::geometry<double> read_polygon(shape_file::record_type & record);
shapeType type_;
shape_file shp_;

View file

@ -448,7 +448,7 @@ boost::optional<mapnik::datasource_geometry_t> sqlite_datasource::get_geometry_t
if (data)
{
mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb(data, size, format_);
mapnik::geometry::geometry<double> geom = mapnik::geometry_utils::from_wkb(data, size, format_);
if (mapnik::geometry::is_empty(geom))
{
continue;

View file

@ -81,7 +81,7 @@ feature_ptr sqlite_featureset::next()
}
feature_ptr feature = feature_factory::create(ctx_,rs_->column_integer64(1));
mapnik::geometry::geometry geom = geometry_utils::from_wkb(data, size, format_);
mapnik::geometry::geometry<double> geom = geometry_utils::from_wkb(data, size, format_);
if (mapnik::geometry::is_empty(geom))
{
continue;

View file

@ -196,7 +196,7 @@ public:
const char* data = static_cast<const char*>(rs->column_blob(0, size));
if (data)
{
mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto);
mapnik::geometry::geometry<double> geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto);
if (!mapnik::geometry::is_empty(geom))
{
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
@ -280,7 +280,7 @@ public:
const char* data = (const char*) rs->column_blob(0, size);
if (data)
{
mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto);
mapnik::geometry::geometry<double> geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto);
if (!mapnik::geometry::is_empty(geom))
{
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
@ -356,7 +356,7 @@ public:
const char* data = static_cast<const char*>(rs->column_blob(0, size));
if (data)
{
mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto);
mapnik::geometry::geometry<double> geom = mapnik::geometry_utils::from_wkb(data, size, mapnik::wkbAuto);
if (!mapnik::geometry::is_empty(geom))
{
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);

View file

@ -53,7 +53,7 @@ mapnik::feature_ptr hello_featureset::next()
// take the outer ring of the bbox that was used to query
// to dynamically generate a fake line
mapnik::geometry::line_string line;
mapnik::geometry::line_string<double> line;
line.reserve(4);
line.add_coord(box_.minx(),box_.maxy());
line.add_coord(box_.maxx(),box_.maxy());

View file

@ -96,7 +96,7 @@ struct feature_generator
x = x * (*topo_.tr).scale_x + (*topo_.tr).translate_x;
y = y * (*topo_.tr).scale_y + (*topo_.tr).translate_y;
}
mapnik::geometry::point point(x, y);
mapnik::geometry::point<double> point(x, y);
feature->set_geometry(std::move(point));
assign_properties(*feature, pt, tr_);
return feature;
@ -105,7 +105,7 @@ struct feature_generator
feature_ptr operator() (multi_point const& multi_pt) const
{
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_));
mapnik::geometry::multi_point multi_point;
mapnik::geometry::multi_point<double> multi_point;
multi_point.reserve(multi_pt.points.size());
for (auto const& pt : multi_pt.points)
{
@ -129,7 +129,7 @@ struct feature_generator
double px = 0, py = 0;
index_type arc_index = line.ring;
mapnik::geometry::line_string line_string;
mapnik::geometry::line_string<double> line_string;
line_string.reserve( topo_.arcs[arc_index].coordinates.size());
for (auto pt : topo_.arcs[arc_index].coordinates)
@ -152,14 +152,14 @@ struct feature_generator
{
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_));
mapnik::geometry::multi_line_string multi_line_string;
mapnik::geometry::multi_line_string<double> multi_line_string;
multi_line_string.reserve(multi_line.rings.size());
for (auto const& index : multi_line.rings)
{
double px = 0, py = 0;
bool reverse = index < 0;
index_type arc_index = reverse ? std::abs(index) - 1 : index;
mapnik::geometry::line_string line_string;
mapnik::geometry::line_string<double> line_string;
line_string.reserve(topo_.arcs[arc_index].coordinates.size());
for (auto pt : topo_.arcs[arc_index].coordinates)
{
@ -183,12 +183,12 @@ struct feature_generator
{
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_));
std::vector<mapnik::topojson::coordinate> processed_coords;
mapnik::geometry::polygon polygon;
mapnik::geometry::polygon<double> polygon;
if (poly.rings.size() > 1) polygon.interior_rings.reserve(poly.rings.size() - 1);
bool first = true;
for (auto const& ring : poly.rings)
{
mapnik::geometry::linear_ring linear_ring;
mapnik::geometry::linear_ring<double> linear_ring;
for (auto const& index : ring)
{
double px = 0, py = 0;
@ -248,18 +248,18 @@ struct feature_generator
{
mapnik::feature_ptr feature(mapnik::feature_factory::create(ctx_,feature_id_));
std::vector<mapnik::topojson::coordinate> processed_coords;
mapnik::geometry::multi_polygon multi_polygon;
mapnik::geometry::multi_polygon<double> multi_polygon;
multi_polygon.reserve(multi_poly.polygons.size());
for (auto const& poly : multi_poly.polygons)
{
bool first = true;
mapnik::geometry::polygon polygon;
mapnik::geometry::polygon<double> polygon;
if (poly.size() > 1) polygon.interior_rings.reserve(poly.size() - 1);
for (auto const& ring : poly)
{
mapnik::geometry::linear_ring linear_ring;
mapnik::geometry::linear_ring<double> linear_ring;
for (auto const& index : ring)
{
double px = 0, py = 0;

View file

@ -26,16 +26,16 @@
namespace mapnik {
namespace geometry {
template MAPNIK_DECL mapnik::box2d<double> envelope(geometry const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(geometry<double> 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);
template MAPNIK_DECL mapnik::box2d<double> envelope(point<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(line_string<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(polygon<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(multi_point<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(multi_line_string<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(multi_polygon<double> const& geom);
template MAPNIK_DECL mapnik::box2d<double> envelope(geometry_collection<double> const& geom);
} // end ns geometry
} // end ns mapnik

View file

@ -35,9 +35,10 @@ geometry_empty reproject_internal(geometry_empty const&, proj_transform const&,
return geometry_empty();
}
point reproject_internal(point const & p, proj_transform const& proj_trans, unsigned int & n_err)
template <typename T>
point<T> reproject_internal(point<T> const & p, proj_transform const& proj_trans, unsigned int & n_err)
{
point new_p(p);
point<T> new_p(p);
if (!proj_trans.forward(new_p))
{
++n_err;
@ -45,9 +46,10 @@ point reproject_internal(point const & p, proj_transform const& proj_trans, unsi
return new_p;
}
line_string reproject_internal(line_string const & ls, proj_transform const& proj_trans, unsigned int & n_err)
template <typename T>
line_string<T> reproject_internal(line_string<T> const & ls, proj_transform const& proj_trans, unsigned int & n_err)
{
line_string new_ls(ls);
line_string<T> new_ls(ls);
unsigned int err = proj_trans.forward(new_ls);
if (err > 0)
{
@ -56,10 +58,11 @@ line_string reproject_internal(line_string const & ls, proj_transform const& pro
return new_ls;
}
polygon reproject_internal(polygon const & poly, proj_transform const& proj_trans, unsigned int & n_err)
template <typename T>
polygon<T> reproject_internal(polygon<T> const & poly, proj_transform const& proj_trans, unsigned int & n_err)
{
polygon new_poly;
linear_ring new_ext(poly.exterior_ring);
polygon<T> new_poly;
linear_ring<T> new_ext(poly.exterior_ring);
unsigned int err = proj_trans.forward(new_ext);
// If the exterior ring doesn't transform don't bother with the holes.
if (err > 0 || new_ext.empty())
@ -73,7 +76,7 @@ polygon reproject_internal(polygon const & poly, proj_transform const& proj_tran
for (auto const& lr : poly.interior_rings)
{
linear_ring new_lr(lr);
linear_ring<T> new_lr(lr);
err = proj_trans.forward(new_lr);
if (err > 0 || new_lr.empty())
{
@ -88,9 +91,10 @@ polygon reproject_internal(polygon const & poly, proj_transform const& proj_tran
return new_poly;
}
multi_point reproject_internal(multi_point const & mp, proj_transform const& proj_trans, unsigned int & n_err)
template <typename T>
multi_point<T> reproject_internal(multi_point<T> const & mp, proj_transform const& proj_trans, unsigned int & n_err)
{
multi_point new_mp;
multi_point<T> new_mp;
if (proj_trans.is_known())
{
// If the projection is known we do them all at once because it is faster
@ -103,7 +107,7 @@ multi_point reproject_internal(multi_point const & mp, proj_transform const& pro
new_mp.reserve(mp.size());
for (auto const& p : mp)
{
point new_p(p);
point<T> new_p(p);
if (!proj_trans.forward(new_p))
{
++n_err;
@ -117,13 +121,14 @@ multi_point reproject_internal(multi_point const & mp, proj_transform const& pro
return new_mp;
}
multi_line_string reproject_internal(multi_line_string const & mls, proj_transform const& proj_trans, unsigned int & n_err)
template <typename T>
multi_line_string<T> reproject_internal(multi_line_string<T> const & mls, proj_transform const& proj_trans, unsigned int & n_err)
{
multi_line_string new_mls;
multi_line_string<T> new_mls;
new_mls.reserve(mls.size());
for (auto const& ls : mls)
{
line_string new_ls = reproject_internal(ls, proj_trans, n_err);
line_string<T> new_ls = reproject_internal(ls, proj_trans, n_err);
if (!new_ls.empty())
{
new_mls.emplace_back(std::move(new_ls));
@ -132,13 +137,14 @@ multi_line_string reproject_internal(multi_line_string const & mls, proj_transfo
return new_mls;
}
multi_polygon reproject_internal(multi_polygon const & mpoly, proj_transform const& proj_trans, unsigned int & n_err)
template <typename T>
multi_polygon<T> reproject_internal(multi_polygon<T> const & mpoly, proj_transform const& proj_trans, unsigned int & n_err)
{
multi_polygon new_mpoly;
multi_polygon<T> new_mpoly;
new_mpoly.reserve(mpoly.size());
for (auto const& poly : mpoly)
{
polygon new_poly = reproject_internal(poly, proj_trans, n_err);
polygon<T> new_poly = reproject_internal(poly, proj_trans, n_err);
if (!new_poly.exterior_ring.empty())
{
new_mpoly.emplace_back(std::move(new_poly));
@ -147,14 +153,16 @@ multi_polygon reproject_internal(multi_polygon const & mpoly, proj_transform con
return new_mpoly;
}
geometry_collection reproject_internal(geometry_collection const & c, proj_transform const& proj_trans, unsigned int & n_err)
template <typename T>
geometry_collection<T> reproject_internal(geometry_collection<T> const & c, proj_transform const& proj_trans, unsigned int & n_err)
{
geometry_collection new_c;
geometry_collection<T> new_c;
new_c.reserve(c.size());
for (auto const& g : c)
{
geometry new_g(std::move(reproject_copy(g, proj_trans, n_err)));
if (!new_g.is<geometry_empty>())
geometry<T> new_g(std::move(reproject_copy(g, proj_trans, n_err)));
if (!new_g.template is<geometry_empty>())
{
new_c.emplace_back(std::move(new_g));
}
@ -162,77 +170,78 @@ geometry_collection reproject_internal(geometry_collection const & c, proj_trans
return new_c;
}
template <typename T>
struct geom_reproj_copy_visitor {
geom_reproj_copy_visitor(proj_transform const & proj_trans, unsigned int & n_err)
: proj_trans_(proj_trans),
n_err_(n_err) {}
geometry operator() (geometry_empty const&)
geometry<T> operator() (geometry_empty const&)
{
return geometry_empty();
}
geometry operator() (point const& p)
geometry<T> operator() (point<T> const& p)
{
geometry geom; // default empty
geometry<T> geom; // default empty
unsigned int intial_err = n_err_;
point new_p = reproject_internal(p, proj_trans_, n_err_);
point<T> new_p = reproject_internal(p, proj_trans_, n_err_);
if (n_err_ > intial_err) return geom;
geom = std::move(new_p);
return geom;
}
geometry operator() (line_string const& ls)
geometry<T> operator() (line_string<T> const& ls)
{
geometry geom; // default empty
geometry<T> geom; // default empty
int intial_err = n_err_;
line_string new_ls = reproject_internal(ls, proj_trans_, n_err_);
line_string<T> new_ls = reproject_internal(ls, proj_trans_, n_err_);
if (n_err_ > intial_err || new_ls.empty()) return geom;
geom = std::move(new_ls);
return geom;
}
geometry operator() (polygon const& poly)
geometry<T> operator() (polygon<T> const& poly)
{
geometry geom; // default empty
polygon new_poly = reproject_internal(poly, proj_trans_, n_err_);
geometry<T> geom; // default empty
polygon<T> new_poly = reproject_internal(poly, proj_trans_, n_err_);
if (new_poly.exterior_ring.empty()) return geom;
geom = std::move(new_poly);
return geom;
}
geometry operator() (multi_point const& mp)
geometry<T> operator() (multi_point<T> const& mp)
{
geometry geom; // default empty
multi_point new_mp = reproject_internal(mp, proj_trans_, n_err_);
geometry<T> geom; // default empty
multi_point<T> new_mp = reproject_internal(mp, proj_trans_, n_err_);
if (new_mp.empty()) return geom;
geom = std::move(new_mp);
return geom;
}
geometry operator() (multi_line_string const& mls)
geometry<T> operator() (multi_line_string<T> const& mls)
{
geometry geom; // default empty
multi_line_string new_mls = reproject_internal(mls, proj_trans_, n_err_);
geometry<T> geom; // default empty
multi_line_string<T> new_mls = reproject_internal(mls, proj_trans_, n_err_);
if (new_mls.empty()) return geom;
geom = std::move(new_mls);
return geom;
}
geometry operator() (multi_polygon const& mpoly)
geometry<T> operator() (multi_polygon<T> const& mpoly)
{
geometry geom; // default empty
multi_polygon new_mpoly = reproject_internal(mpoly, proj_trans_, n_err_);
geometry<T> geom; // default empty
multi_polygon<T> new_mpoly = reproject_internal(mpoly, proj_trans_, n_err_);
if (new_mpoly.empty()) return geom;
geom = std::move(new_mpoly);
return geom;
}
geometry operator() (geometry_collection const& c)
geometry<T> operator() (geometry_collection<T> const& c)
{
geometry geom; // default empty
geometry_collection new_c = reproject_internal(c, proj_trans_, n_err_);
geometry<T> geom; // default empty
geometry_collection<T> new_c = reproject_internal(c, proj_trans_, n_err_);
if (new_c.empty()) return geom;
geom = std::move(new_c);
return geom;
@ -246,9 +255,10 @@ private:
} // end detail ns
geometry reproject_copy(geometry const& geom, proj_transform const& proj_trans, unsigned int & n_err)
template <typename T>
geometry<T> reproject_copy(geometry<T> const& geom, proj_transform const& proj_trans, unsigned int & n_err)
{
detail::geom_reproj_copy_visitor visit(proj_trans, n_err);
detail::geom_reproj_copy_visitor<T> visit(proj_trans, n_err);
return mapnik::util::apply_visitor(visit, geom);
}
@ -259,13 +269,13 @@ T reproject_copy(T const& geom, proj_transform const& proj_trans, unsigned int &
}
template MAPNIK_DECL geometry_empty reproject_copy(geometry_empty const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL point reproject_copy(point const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL line_string reproject_copy(line_string const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL polygon reproject_copy(polygon const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL multi_point reproject_copy(multi_point const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL multi_line_string reproject_copy(multi_line_string const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL multi_polygon reproject_copy(multi_polygon const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL geometry_collection reproject_copy(geometry_collection const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL point<double> reproject_copy(point<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL line_string<double> reproject_copy(line_string<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL polygon<double> reproject_copy(polygon<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL multi_point<double> reproject_copy(multi_point<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL multi_line_string<double> reproject_copy(multi_line_string<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL multi_polygon<double> reproject_copy(multi_polygon<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template MAPNIK_DECL geometry_collection<double> reproject_copy(geometry_collection<double> const& geom, proj_transform const& proj_trans, unsigned int & n_err);
template <typename T>
T reproject_copy(T const& geom, projection const& source, projection const& dest, unsigned int & n_err)
@ -274,15 +284,15 @@ T reproject_copy(T const& geom, projection const& source, projection const& dest
return reproject_copy(geom, proj_trans, n_err);
}
template MAPNIK_DECL geometry reproject_copy(geometry const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL geometry<double> reproject_copy(geometry<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL geometry_empty reproject_copy(geometry_empty const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL point reproject_copy(point const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL line_string reproject_copy(line_string const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL polygon reproject_copy(polygon const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL multi_point reproject_copy(multi_point const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL multi_line_string reproject_copy(multi_line_string const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL multi_polygon reproject_copy(multi_polygon const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL geometry_collection reproject_copy(geometry_collection const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL point<double> reproject_copy(point<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL line_string<double> reproject_copy(line_string<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL polygon<double> reproject_copy(polygon<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL multi_point<double> reproject_copy(multi_point<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL multi_line_string<double> reproject_copy(multi_line_string<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL multi_polygon<double> reproject_copy(multi_polygon<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
template MAPNIK_DECL geometry_collection<double> reproject_copy(geometry_collection<double> const& geom, projection const& source, projection const& dest, unsigned int & n_err);
namespace detail {
@ -291,14 +301,16 @@ struct geom_reproj_visitor {
geom_reproj_visitor(proj_transform const & proj_trans)
: proj_trans_(proj_trans) {}
bool operator() (geometry & geom)
template <typename T>
bool operator() (geometry<T> & geom)
{
return mapnik::util::apply_visitor((*this), geom);
}
bool operator() (geometry_empty &) { return true; }
bool operator() (point & p)
template <typename T>
bool operator() (point<T> & p)
{
if (!proj_trans_.forward(p))
{
@ -307,7 +319,8 @@ struct geom_reproj_visitor {
return true;
}
bool operator() (line_string & ls)
template <typename T>
bool operator() (line_string<T> & ls)
{
if (proj_trans_.forward(ls) > 0)
{
@ -316,7 +329,8 @@ struct geom_reproj_visitor {
return true;
}
bool operator() (polygon & poly)
template <typename T>
bool operator() (polygon<T> & poly)
{
if (proj_trans_.forward(poly.exterior_ring) > 0)
{
@ -333,12 +347,14 @@ struct geom_reproj_visitor {
return true;
}
bool operator() (multi_point & mp)
template <typename T>
bool operator() (multi_point<T> & mp)
{
return (*this) (static_cast<line_string &>(mp));
return (*this) (static_cast<line_string<T> &>(mp));
}
bool operator() (multi_line_string & mls)
template <typename T>
bool operator() (multi_line_string<T> & mls)
{
for (auto & ls : mls)
{
@ -350,7 +366,8 @@ struct geom_reproj_visitor {
return true;
}
bool operator() (multi_polygon & mpoly)
template <typename T>
bool operator() (multi_polygon<T> & mpoly)
{
for (auto & poly : mpoly)
{
@ -362,7 +379,8 @@ struct geom_reproj_visitor {
return true;
}
bool operator() (geometry_collection & c)
template <typename T>
bool operator() (geometry_collection<T> & c)
{
for (auto & g : c)
{
@ -388,15 +406,15 @@ bool reproject(T & geom, proj_transform const& proj_trans)
return visit(geom);
}
template MAPNIK_DECL bool reproject(geometry & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(geometry<double> & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(geometry_empty & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(point & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(line_string & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(polygon & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(multi_point & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(multi_line_string & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(multi_polygon & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(geometry_collection & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(point<double> & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(line_string<double> & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(polygon<double> & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(multi_point<double> & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(multi_line_string<double> & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(multi_polygon<double> & geom, proj_transform const& proj_trans);
template MAPNIK_DECL bool reproject(geometry_collection<double> & geom, proj_transform const& proj_trans);
template <typename T>
bool reproject(T & geom, projection const& source, projection const& dest)
@ -406,15 +424,15 @@ bool reproject(T & geom, projection const& source, projection const& dest)
return visit(geom);
}
template MAPNIK_DECL bool reproject(geometry & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(geometry<double> & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(geometry_empty & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(point & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(line_string & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(polygon & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(multi_point & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(multi_line_string & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(multi_polygon & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(geometry_collection & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(point<double> & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(line_string<double> & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(polygon<double> & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(multi_point<double> & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(multi_line_string<double> & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(multi_polygon<double> & geom, projection const& source, projection const& dest);
template MAPNIK_DECL bool reproject(geometry_collection<double> & geom, projection const& source, projection const& dest);
} // end geometry ns

View file

@ -32,4 +32,4 @@ using sink_type = std::back_insert_iterator<std::string>;
template struct mapnik::json::properties_generator_grammar<sink_type, mapnik::feature_impl>;
template struct mapnik::json::feature_generator_grammar<sink_type, mapnik::feature_impl>;
template struct mapnik::json::geometry_generator_grammar<sink_type, mapnik::geometry::geometry>;
template struct mapnik::json::geometry_generator_grammar<sink_type, mapnik::geometry::geometry<double> >;

View file

@ -97,13 +97,13 @@ bool proj_transform::forward (double & x, double & y , double & z) const
return forward(&x, &y, &z, 1);
}
bool proj_transform::forward (geometry::point & p) const
bool proj_transform::forward (geometry::point<double> & p) const
{
double z = 0;
return forward(&(p.x), &(p.y), &z, 1);
}
unsigned int proj_transform::forward (geometry::line_string & ls) const
unsigned int proj_transform::forward (geometry::line_string<double> & ls) const
{
if (is_source_equal_dest_)
return 0;
@ -220,13 +220,13 @@ bool proj_transform::backward (double & x, double & y , double & z) const
return backward(&x, &y, &z, 1);
}
bool proj_transform::backward (geometry::point & p) const
bool proj_transform::backward (geometry::point<double> & p) const
{
double z = 0;
return backward(&(p.x), &(p.y), &z, 1);
}
unsigned int proj_transform::backward (geometry::line_string & ls) const
unsigned int proj_transform::backward (geometry::line_string<double> & ls) const
{
if (is_source_equal_dest_)
return 0;

View file

@ -86,14 +86,14 @@ struct split_multi_geometries
minimum_path_length_(minimum_path_length) {}
void operator() (geometry::geometry_empty const&) const {}
void operator() (geometry::multi_point const& multi_pt) const
void operator() (geometry::multi_point<double> const& multi_pt) const
{
for ( auto const& pt : multi_pt )
{
cont_.push_back(std::move(base_symbolizer_helper::geometry_cref(std::cref(pt))));
}
}
void operator() (geometry::multi_line_string const& multi_line) const
void operator() (geometry::multi_line_string<double> const& multi_line) const
{
for ( auto const& line : multi_line )
{
@ -101,7 +101,7 @@ struct split_multi_geometries
}
}
void operator() (geometry::polygon const& poly) const
void operator() (geometry::polygon<double> const& poly) const
{
if (minimum_path_length_ > 0)
{
@ -117,7 +117,7 @@ struct split_multi_geometries
}
}
void operator() (geometry::multi_polygon const& multi_poly) const
void operator() (geometry::multi_polygon<double> const& multi_poly) const
{
for ( auto const& poly : multi_poly )
{
@ -125,7 +125,7 @@ struct split_multi_geometries
}
}
void operator() (geometry::geometry_collection const& collection) const
void operator() (geometry::geometry_collection<double> const& collection) const
{
for ( auto const& geom : collection)
{
@ -173,7 +173,7 @@ base_symbolizer_helper::base_symbolizer_helper(
struct largest_bbox_first
{
bool operator() (geometry::geometry const* g0, geometry::geometry const* g1) const
bool operator() (geometry::geometry<double> const* g0, geometry::geometry<double> const* g1) const
{
box2d<double> b0 = geometry::envelope(*g0);
box2d<double> b1 = geometry::envelope(*g1);
@ -239,13 +239,13 @@ void base_symbolizer_helper::initialize_points() const
// FIXME: how to handle MultiLineString?
if (type == geometry::geometry_types::LineString)
{
auto const& line = mapnik::util::get<geometry::line_string>(geom);
geometry::line_string_vertex_adapter va(line);
auto const& line = mapnik::util::get<geometry::line_string<double> >(geom);
geometry::line_string_vertex_adapter<double> va(line);
success = label::middle_point(va, label_x,label_y);
}
else if (how_placed == POINT_PLACEMENT)
{
geometry::point pt;
geometry::point<double> pt;
geometry::centroid(geom, pt);
label_x = pt.x;
label_y = pt.y;
@ -255,8 +255,8 @@ void base_symbolizer_helper::initialize_points() const
{
if (type == geometry::geometry_types::Polygon)
{
auto const& poly = mapnik::util::get<geometry::polygon>(geom);
geometry::polygon_vertex_adapter va(poly);
auto const& poly = mapnik::util::get<geometry::polygon<double> >(geom);
geometry::polygon_vertex_adapter<double> va(poly);
success = label::interior_position(va, label_x, label_y);
}
}
@ -333,8 +333,8 @@ bool text_symbolizer_helper::next_line_placement() const
if (geo_itr_->is<base_symbolizer_helper::line_string_cref>()) // line_string
{
auto const& line = util::get<geometry::line_string const>(*geo_itr_);
geometry::line_string_vertex_adapter va(line);
auto const& line = util::get<geometry::line_string<double> const>(*geo_itr_);
geometry::line_string_vertex_adapter<double> va(line);
converter_.apply(va);
if (adapter_.status())
{

View file

@ -118,9 +118,9 @@ public:
needSwap_ = byteOrder_ ? wkbXDR : wkbNDR;
}
mapnik::geometry::geometry read()
mapnik::geometry::geometry<double> read()
{
mapnik::geometry::geometry geom = mapnik::geometry::geometry_empty();
mapnik::geometry::geometry<double> geom = mapnik::geometry::geometry_empty();
int type = read_integer();
switch (type)
{
@ -263,19 +263,19 @@ private:
}
template <bool Z = false, bool M = false>
mapnik::geometry::point read_point()
mapnik::geometry::point<double> read_point()
{
double x = read_double();
double y = read_double();
if (Z) pos_ += 8;
if (M) pos_ += 8;
return mapnik::geometry::point(x, y);
return mapnik::geometry::point<double>(x, y);
}
template <bool Z = false, bool M = false>
mapnik::geometry::multi_point read_multipoint()
mapnik::geometry::multi_point<double> read_multipoint()
{
mapnik::geometry::multi_point multi_point;
mapnik::geometry::multi_point<double> multi_point;
int num_points = read_integer();
multi_point.reserve(num_points);
for (int i = 0; i < num_points; ++i)
@ -287,23 +287,23 @@ private:
}
template <bool M = false, bool Z = false>
mapnik::geometry::line_string read_linestring()
mapnik::geometry::line_string<double> read_linestring()
{
mapnik::geometry::line_string line;
mapnik::geometry::line_string<double> line;
int num_points = read_integer();
if (num_points > 0)
{
line.reserve(num_points);
read_coords<mapnik::geometry::line_string, M, Z>(line, num_points);
read_coords<mapnik::geometry::line_string<double>, M, Z>(line, num_points);
}
return line;
}
template <bool M = false, bool Z = false>
mapnik::geometry::multi_line_string read_multilinestring()
mapnik::geometry::multi_line_string<double> read_multilinestring()
{
int num_lines = read_integer();
mapnik::geometry::multi_line_string multi_line;
mapnik::geometry::multi_line_string<double> multi_line;
multi_line.reserve(num_lines);
for (int i = 0; i < num_lines; ++i)
{
@ -314,10 +314,10 @@ private:
}
template <bool M = false, bool Z = false>
mapnik::geometry::polygon read_polygon()
mapnik::geometry::polygon<double> read_polygon()
{
int num_rings = read_integer();
mapnik::geometry::polygon poly;
mapnik::geometry::polygon<double> poly;
if (num_rings > 1)
{
poly.interior_rings.reserve(num_rings - 1);
@ -325,12 +325,12 @@ private:
for (int i = 0; i < num_rings; ++i)
{
mapnik::geometry::linear_ring ring;
mapnik::geometry::linear_ring<double> ring;
int num_points = read_integer();
if (num_points > 0)
{
ring.reserve(num_points);
read_coords<mapnik::geometry::linear_ring, M, Z>(ring, num_points);
read_coords<mapnik::geometry::linear_ring<double>, M, Z>(ring, num_points);
}
if ( i == 0) poly.set_exterior_ring(std::move(ring));
else poly.add_hole(std::move(ring));
@ -339,10 +339,10 @@ private:
}
template <bool M = false, bool Z = false>
mapnik::geometry::multi_polygon read_multipolygon()
mapnik::geometry::multi_polygon<double> read_multipolygon()
{
int num_polys = read_integer();
mapnik::geometry::multi_polygon multi_poly;
mapnik::geometry::multi_polygon<double> multi_poly;
for (int i = 0; i < num_polys; ++i)
{
pos_ += 5;
@ -351,10 +351,10 @@ private:
return multi_poly;
}
mapnik::geometry::geometry_collection read_collection()
mapnik::geometry::geometry_collection<double> read_collection()
{
int num_geometries = read_integer();
mapnik::geometry::geometry_collection collection;
mapnik::geometry::geometry_collection<double> collection;
for (int i = 0; i < num_geometries; ++i)
{
pos_ += 1; // skip byte order
@ -405,12 +405,12 @@ private:
};
mapnik::geometry::geometry geometry_utils::from_wkb(const char* wkb,
mapnik::geometry::geometry<double> geometry_utils::from_wkb(const char* wkb,
unsigned size,
wkbFormat format)
{
wkb_reader reader(wkb, size, format);
mapnik::geometry::geometry geom(reader.read());
mapnik::geometry::geometry<double> geom(reader.read());
mapnik::geometry::correct(geom);
return geom;
}

View file

@ -27,6 +27,6 @@
namespace mapnik { namespace wkt {
using sink_type = std::back_insert_iterator<std::string>;
template struct wkt_generator_grammar<sink_type, mapnik::geometry::geometry>;
template struct wkt_generator_grammar<sink_type, mapnik::geometry::geometry<double> >;
}}

View file

@ -50,7 +50,7 @@ int main(int argc, char** argv)
feature->put("name",ustr);
//auto pt = std::make_unique<mapnik::geometry_type>(mapnik::geometry::geometry_types::Point);
//pt->move_to(128,128);
mapnik::geometry::point pt(128,128);
mapnik::geometry::point<double> pt(128,128);
feature->set_geometry(std::move(pt));
mapnik::parameters params;

View file

@ -18,10 +18,10 @@ int main(int argc, char** argv)
try
{
// reused these for simplicity
mapnik::geometry::point centroid;
mapnik::geometry::point<double> centroid;
{
// single point
mapnik::geometry::point pt(10,10);
mapnik::geometry::point<double> pt(10,10);
BOOST_TEST( mapnik::geometry::centroid(pt, centroid));
BOOST_TEST( pt.x == centroid.x);
BOOST_TEST( pt.y == centroid.y);
@ -29,7 +29,7 @@ int main(int argc, char** argv)
// linestring with three consecutive verticies
{
mapnik::geometry::line_string line;
mapnik::geometry::line_string<double> line;
line.add_coord(0, 0);
line.add_coord(25, 25);
line.add_coord(50, 50);

View file

@ -68,7 +68,7 @@ int main(int argc, char** argv)
try {
// spatialite blob
mapnik::geometry::geometry geom = mapnik::geometry_utils::from_wkb((const char*)sp_valid_blob,
mapnik::geometry::geometry<double> geom = mapnik::geometry_utils::from_wkb((const char*)sp_valid_blob,
sizeof(sp_valid_blob) / sizeof(sp_valid_blob[0]),
mapnik::wkbSpatiaLite);
BOOST_TEST(mapnik::geometry::is_valid(geom) && mapnik::geometry::is_simple(geom));

View file

@ -29,13 +29,13 @@ SECTION("hello world") {
REQUIRE( feat1->id() == static_cast<mapnik::value_integer>(1) );
REQUIRE( feat2->id() == static_cast<mapnik::value_integer>(2) );
auto const& geom1 = feat1->get_geometry();
REQUIRE( geom1.is<mapnik::geometry::point>() );
auto const& point = mapnik::util::get<mapnik::geometry::point>(geom1);
REQUIRE( geom1.is<mapnik::geometry::point<double> >() );
auto const& point = mapnik::util::get<mapnik::geometry::point<double> >(geom1);
REQUIRE( point.x == bbox.center().x );
REQUIRE( point.y == bbox.center().y );
auto const& geom2 = feat2->get_geometry();
REQUIRE( geom2.is<mapnik::geometry::line_string>() );
auto const& line = mapnik::util::get<mapnik::geometry::line_string>(geom2);
REQUIRE( geom2.is<mapnik::geometry::line_string<double> >() );
auto const& line = mapnik::util::get<mapnik::geometry::line_string<double> >(geom2);
REQUIRE( line.size() == 4 );
REQUIRE( line[0].x == bbox.minx() );
REQUIRE( line[0].y == bbox.maxy() );

View file

@ -11,11 +11,11 @@ TEST_CASE("geometry") {
SECTION("json point") {
mapnik::util::file input("./tests/data/json/fixtures/point1.json");
auto json = input.data();
mapnik::geometry::geometry geom;
mapnik::geometry::geometry<double> geom;
std::string json_string(json.get());
REQUIRE( mapnik::json::from_geojson(json_string, geom) );
REQUIRE( geom.is<mapnik::geometry::point>() );
auto const& point = mapnik::util::get<mapnik::geometry::point>(geom);
REQUIRE( geom.is<mapnik::geometry::point<double> >() );
auto const& point = mapnik::util::get<mapnik::geometry::point<double> >(geom);
REQUIRE( point.x == 30 );
REQUIRE( point.y == 10 );
std::string new_json;
@ -25,11 +25,11 @@ SECTION("json point") {
SECTION("json point reversed") {
mapnik::util::file input("./tests/data/json/fixtures/point2.json");
auto json = input.data();
mapnik::geometry::geometry geom;
mapnik::geometry::geometry<double> geom;
std::string json_string(json.get());
REQUIRE( mapnik::json::from_geojson(json_string,geom) );
REQUIRE( geom.is<mapnik::geometry::point>() );
auto const& point = mapnik::util::get<mapnik::geometry::point>(geom);
REQUIRE( geom.is<mapnik::geometry::point<double> >() );
auto const& point = mapnik::util::get<mapnik::geometry::point<double> >(geom);
REQUIRE( point.x == 30 );
REQUIRE( point.y == 10 );
}

View file

@ -6,10 +6,10 @@
TEST_CASE("geometry ops - envelope") {
SECTION("envelope_test") {
SECTION("envelope_test - double") {
using namespace mapnik::geometry;
{
geometry geom(point(1,2));
geometry<double> geom(point<double>(1,2));
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
REQUIRE( bbox.minx() == 1 );
REQUIRE( bbox.miny() == 2 );
@ -18,16 +18,16 @@ SECTION("envelope_test") {
}
{
// Test empty geom
geometry geom(std::move(mapnik::geometry::geometry_empty()));
geometry<double> geom(std::move(mapnik::geometry::geometry_empty()));
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
REQUIRE_FALSE( bbox.valid() );
}
{
line_string line;
line_string<double> line;
line.add_coord(0,0);
line.add_coord(1,1);
line.add_coord(2,2);
geometry geom(line);
geometry<double> geom(line);
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
REQUIRE( bbox.minx() == 0 );
REQUIRE( bbox.miny() == 0 );
@ -35,18 +35,18 @@ SECTION("envelope_test") {
REQUIRE( bbox.maxy() == 2 );
}
{
line_string line;
line_string<double> line;
line.add_coord(0,0);
line.add_coord(1,1);
line.add_coord(2,2);
line_string line2;
line_string<double> line2;
line2.add_coord(0,0);
line2.add_coord(-1,-1);
line2.add_coord(-2,-2);
multi_line_string multi_line;
multi_line_string<double> multi_line;
multi_line.emplace_back(std::move(line));
multi_line.emplace_back(std::move(line2));
geometry geom(multi_line);
geometry<double> geom(multi_line);
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
REQUIRE( bbox.minx() == -2 );
REQUIRE( bbox.miny() == -2 );
@ -54,24 +54,24 @@ SECTION("envelope_test") {
REQUIRE( bbox.maxy() == 2 );
}
{
polygon poly;
linear_ring ring;
polygon<double> poly;
linear_ring<double> ring;
ring.add_coord(0,0);
ring.add_coord(-10,0);
ring.add_coord(-10,10);
ring.add_coord(0,10);
ring.add_coord(0,0);
poly.set_exterior_ring(std::move(ring));
geometry geom(poly);
geometry<double> geom(poly);
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
REQUIRE( bbox.minx() == -10 );
REQUIRE( bbox.miny() == 0 );
REQUIRE( bbox.maxx() == 0 );
REQUIRE( bbox.maxy() == 10 );
multi_polygon mp;
multi_polygon<double> mp;
mp.push_back(poly);
geometry geom_mp(mp);
geometry<double> geom_mp(mp);
bbox = mapnik::geometry::envelope(geom_mp);
REQUIRE( bbox.minx() == -10 );
REQUIRE( bbox.miny() == 0 );
@ -91,7 +91,7 @@ SECTION("envelope_test") {
REQUIRE( bbox.maxx() == 0 );
REQUIRE( bbox.maxy() == 10 );
geometry_collection gc;
geometry_collection<double> gc;
bbox = mapnik::geometry::envelope(gc);
REQUIRE_FALSE( bbox.valid() );
gc.push_back(geom_mp);
@ -100,7 +100,7 @@ SECTION("envelope_test") {
REQUIRE( bbox.miny() == 0 );
REQUIRE( bbox.maxx() == 0 );
REQUIRE( bbox.maxy() == 10 );
gc.emplace_back(point(-50,-50));
gc.emplace_back(point<double>(-50,-50));
bbox = mapnik::geometry::envelope(gc);
REQUIRE( bbox.minx() == -50 );
REQUIRE( bbox.miny() == -50 );
@ -110,22 +110,22 @@ SECTION("envelope_test") {
{
// polygon with hole
polygon poly;
linear_ring ring;
polygon<double> poly;
linear_ring<double> ring;
ring.add_coord(0,0);
ring.add_coord(-10,0);
ring.add_coord(-10,10);
ring.add_coord(0,10);
ring.add_coord(0,0);
poly.set_exterior_ring(std::move(ring));
linear_ring hole;
linear_ring<double> hole;
hole.add_coord(-7,7);
hole.add_coord(-7,3);
hole.add_coord(-3,3);
hole.add_coord(-3,7);
hole.add_coord(-7,7);
poly.add_hole(std::move(hole));
geometry geom(poly);
geometry<double> geom(poly);
mapnik::box2d<double> bbox = mapnik::geometry::envelope(poly);
REQUIRE( bbox.minx() == -10 );
REQUIRE( bbox.miny() == 0 );
@ -133,7 +133,7 @@ SECTION("envelope_test") {
REQUIRE( bbox.maxy() == 10 );
// add another hole inside the first hole
// which should be considered a hit
linear_ring fill;
linear_ring<double> fill;
fill.add_coord(-6,4);
fill.add_coord(-6,6);
fill.add_coord(-4,6);

View file

@ -79,7 +79,8 @@ auto zip_crange(Conts&... conts)
using namespace mapnik::geometry;
void assert_g_equal(geometry const& g1, geometry const& g2);
template <typename T>
void assert_g_equal(geometry<T> const& g1, geometry<T> const& g2);
struct geometry_equal_visitor
{
@ -95,13 +96,15 @@ struct geometry_equal_visitor
REQUIRE(true);
}
void operator() (point const& p1, point const& p2)
template <typename T>
void operator() (point<T> const& p1, point<T> const& p2)
{
REQUIRE(p1.x == Approx(p2.x));
REQUIRE(p1.y == Approx(p2.y));
}
void operator() (line_string const& ls1, line_string const& ls2)
template <typename T>
void operator() (line_string<T> const& ls1, line_string<T> const& ls2)
{
if (ls1.size() != ls2.size())
{
@ -115,9 +118,10 @@ struct geometry_equal_visitor
}
}
void operator() (polygon const& p1, polygon const& p2)
template <typename T>
void operator() (polygon<T> const& p1, polygon<T> const& p2)
{
(*this)(static_cast<line_string const&>(p1.exterior_ring), static_cast<line_string const&>(p2.exterior_ring));
(*this)(static_cast<line_string<T> const&>(p1.exterior_ring), static_cast<line_string<T> const&>(p2.exterior_ring));
if (p1.interior_rings.size() != p2.interior_rings.size())
{
@ -126,16 +130,18 @@ struct geometry_equal_visitor
for (auto const& p : zip_crange(p1.interior_rings, p2.interior_rings))
{
(*this)(static_cast<line_string const&>(p.get<0>()),static_cast<line_string const&>(p.get<1>()));
(*this)(static_cast<line_string<T> const&>(p.get<0>()),static_cast<line_string<T> const&>(p.get<1>()));
}
}
void operator() (multi_point const& mp1, multi_point const& mp2)
template <typename T>
void operator() (multi_point<T> const& mp1, multi_point<T> const& mp2)
{
(*this)(static_cast<line_string const&>(mp1), static_cast<line_string const&>(mp2));
(*this)(static_cast<line_string<T> const&>(mp1), static_cast<line_string<T> const&>(mp2));
}
void operator() (multi_line_string const& mls1, multi_line_string const& mls2)
template <typename T>
void operator() (multi_line_string<T> const& mls1, multi_line_string<T> const& mls2)
{
if (mls1.size() != mls2.size())
{
@ -148,7 +154,8 @@ struct geometry_equal_visitor
}
}
void operator() (multi_polygon const& mpoly1, multi_polygon const& mpoly2)
template <typename T>
void operator() (multi_polygon<T> const& mpoly1, multi_polygon<T> const& mpoly2)
{
if (mpoly1.size() != mpoly2.size())
{
@ -161,10 +168,11 @@ struct geometry_equal_visitor
}
}
void operator() (mapnik::util::recursive_wrapper<geometry_collection> const& c1_, mapnik::util::recursive_wrapper<geometry_collection> const& c2_)
template <typename T>
void operator() (mapnik::util::recursive_wrapper<geometry_collection<T> > const& c1_, mapnik::util::recursive_wrapper<geometry_collection<T> > const& c2_)
{
geometry_collection const& c1 = static_cast<geometry_collection const&>(c1_);
geometry_collection const& c2 = static_cast<geometry_collection const&>(c2_);
geometry_collection<T> const& c1 = static_cast<geometry_collection<T> const&>(c1_);
geometry_collection<T> const& c2 = static_cast<geometry_collection<T> const&>(c2_);
if (c1.size() != c2.size())
{
REQUIRE(false);
@ -176,7 +184,8 @@ struct geometry_equal_visitor
}
}
void operator() (geometry_collection const& c1, geometry_collection const& c2)
template <typename T>
void operator() (geometry_collection<T> const& c1, geometry_collection<T> const& c2)
{
if (c1.size() != c2.size())
{
@ -190,7 +199,8 @@ struct geometry_equal_visitor
}
};
void assert_g_equal(geometry const& g1, geometry const& g2)
template <typename T>
void assert_g_equal(geometry<T> const& g1, geometry<T> const& g2)
{
return mapnik::util::apply_visitor(geometry_equal_visitor(), g1, g2);
}

View file

@ -6,57 +6,57 @@
TEST_CASE("geometry ops") {
SECTION("hit_test_filter") {
SECTION("hit_test_filter - double") {
using namespace mapnik::geometry;
{
geometry geom(point(0,0));
geometry<double> geom(point<double>(0,0));
REQUIRE( mapnik::hit_test(geom,0,0,0) );
}
{
geometry geom(point(0,0));
geometry<double> geom(point<double>(0,0));
REQUIRE( mapnik::hit_test(geom,1,0,1) );
}
{
geometry geom(point(0,0));
geometry<double> geom(point<double>(0,0));
REQUIRE( mapnik::hit_test(geom,0,1,1) );
}
{
geometry geom(point(0,0));
geometry<double> geom(point<double>(0,0));
REQUIRE( mapnik::hit_test(geom,1,1,1.5) );
}
{
line_string line;
line_string<double> line;
line.add_coord(0,0);
line.add_coord(1,1);
line.add_coord(2,2);
geometry geom(line);
geometry<double> geom(line);
REQUIRE( mapnik::hit_test(geom,0,0,1.5) );
}
{
line_string line;
line_string<double> line;
line.add_coord(0,0);
line.add_coord(1,1);
line.add_coord(2,2);
multi_line_string multi_line;
multi_line_string<double> multi_line;
multi_line.emplace_back(std::move(line));
geometry geom(multi_line);
geometry<double> geom(multi_line);
REQUIRE( mapnik::hit_test(geom,0,0,1.5) );
}
{
polygon poly;
linear_ring ring;
polygon<double> poly;
linear_ring<double> ring;
ring.add_coord(0,0);
ring.add_coord(-10,0);
ring.add_coord(-10,10);
ring.add_coord(0,10);
ring.add_coord(0,0);
poly.set_exterior_ring(std::move(ring));
geometry geom(poly);
geometry<double> geom(poly);
REQUIRE( mapnik::hit_test(geom,-5,5,0) );
multi_polygon mp;
multi_polygon<double> mp;
mp.push_back(poly);
geometry geom_mp(mp);
geometry<double> geom_mp(mp);
REQUIRE( mapnik::hit_test(geom_mp,-5,5,0) );
correct(geom);
@ -64,44 +64,44 @@ SECTION("hit_test_filter") {
correct(geom_mp);
REQUIRE( mapnik::hit_test(geom_mp,-5,5,0) );
geometry_collection gc;
REQUIRE( !mapnik::hit_test(geometry(gc),-5,5,0) );
geometry_collection<double> gc;
REQUIRE( !mapnik::hit_test(geometry<double>(gc),-5,5,0) );
gc.push_back(geom_mp);
REQUIRE( mapnik::hit_test(geometry(gc),-5,5,0) );
REQUIRE( !mapnik::hit_test(geometry(gc),-50,-50,0) );
gc.emplace_back(point(-50,-50));
REQUIRE( mapnik::hit_test(geometry(gc),-50,-50,0) );
REQUIRE( mapnik::hit_test(geometry<double>(gc),-5,5,0) );
REQUIRE( !mapnik::hit_test(geometry<double>(gc),-50,-50,0) );
gc.emplace_back(point<double>(-50,-50));
REQUIRE( mapnik::hit_test(geometry<double>(gc),-50,-50,0) );
}
{
// polygon with hole
polygon poly;
linear_ring ring;
polygon<double> poly;
linear_ring<double> ring;
ring.add_coord(0,0);
ring.add_coord(-10,0);
ring.add_coord(-10,10);
ring.add_coord(0,10);
ring.add_coord(0,0);
poly.set_exterior_ring(std::move(ring));
linear_ring hole;
linear_ring<double> hole;
hole.add_coord(-7,7);
hole.add_coord(-7,3);
hole.add_coord(-3,3);
hole.add_coord(-3,7);
hole.add_coord(-7,7);
poly.add_hole(std::move(hole));
geometry geom(poly);
geometry<double> geom(poly);
REQUIRE( !mapnik::hit_test(geom,-5,5,0) );
// add another hole inside the first hole
// which should be considered a hit
linear_ring fill;
linear_ring<double> fill;
fill.add_coord(-6,4);
fill.add_coord(-6,6);
fill.add_coord(-4,6);
fill.add_coord(-4,4);
fill.add_coord(-6,4);
poly.add_hole(std::move(fill));
REQUIRE( mapnik::hit_test(geometry(poly),-5,5,0) );
REQUIRE( mapnik::hit_test(geometry<double>(poly),-5,5,0) );
}
}

File diff suppressed because it is too large Load diff

View file

@ -6,13 +6,13 @@
TEST_CASE("vertex_adapters") {
SECTION("polygon") {
mapnik::geometry::polygon g;
mapnik::geometry::polygon<double> g;
g.exterior_ring.add_coord(1,1);
g.exterior_ring.add_coord(2,2);
g.exterior_ring.add_coord(100,100);
g.exterior_ring.add_coord(1,1);
mapnik::geometry::polygon_vertex_adapter va(g);
mapnik::geometry::polygon_vertex_adapter<double> va(g);
double x,y;
unsigned cmd;
@ -45,14 +45,14 @@ SECTION("polygon") {
}
SECTION("polygon with hole") {
mapnik::geometry::polygon g;
mapnik::geometry::polygon<double> g;
g.exterior_ring.add_coord(0,0);
g.exterior_ring.add_coord(-10,0);
g.exterior_ring.add_coord(-10,10);
g.exterior_ring.add_coord(0,10);
g.exterior_ring.add_coord(0,0);
std::vector<mapnik::geometry::linear_ring> interior_rings;
mapnik::geometry::linear_ring hole;
std::vector<mapnik::geometry::linear_ring<double> > interior_rings;
mapnik::geometry::linear_ring<double> hole;
hole.add_coord(-7,7);
hole.add_coord(-7,3);
hole.add_coord(-3,3);
@ -60,7 +60,7 @@ SECTION("polygon with hole") {
hole.add_coord(-7,7);
g.add_hole(std::move(hole));
mapnik::geometry::linear_ring hole_in_hole;
mapnik::geometry::linear_ring<double> hole_in_hole;
hole_in_hole.add_coord(-6,4);
hole_in_hole.add_coord(-6,6);
hole_in_hole.add_coord(-4,6);
@ -68,7 +68,7 @@ SECTION("polygon with hole") {
hole_in_hole.add_coord(-6,4);
g.add_hole(std::move(hole_in_hole));
mapnik::geometry::polygon_vertex_adapter va(g);
mapnik::geometry::polygon_vertex_adapter<double> va(g);
double x,y;
unsigned cmd;

View file

@ -81,7 +81,7 @@ int main (int argc, char ** argv )
while(f)
{
std::cerr << *f << std::endl;
mapnik::geometry::geometry const& geom = f->get_geometry();
mapnik::geometry::geometry<double> const& geom = f->get_geometry();
// NDR
{
mapnik::util::wkb_buffer_ptr wkb = mapnik::util::to_wkb(geom,mapnik::wkbNDR);

View file

@ -389,7 +389,7 @@ void pgsql2sqlite(Connection conn,
if (oid == geometry_oid)
{
mapnik::Feature feat(ctx,pkid);
mapnik::geometry::geometry geom = geometry_utils::from_wkb(buf, size, wkbGeneric);
mapnik::geometry::geometry<double> geom = geometry_utils::from_wkb(buf, size, wkbGeneric);
if (!mapnik::geometry::is_empty(geom))
{
box2d<double> bbox = mapnik::geometry::envelope(geom);