make mapnik::geometry::point<T> an alias to mapbox::geometry::point

This commit is contained in:
artemp 2016-06-27 09:45:37 +01:00
parent d169fb473e
commit 19d376b7e6
23 changed files with 99 additions and 120 deletions

View file

@ -46,7 +46,7 @@ struct geometry_collection;
template <typename T>
struct geometry_empty
{
using coord_type = T;
using coordinate_type = T;
};
template <typename T>
@ -61,7 +61,7 @@ using geometry_base = mapnik::util::variant<geometry_empty<T>,
template <typename T>
struct geometry : geometry_base<T>
{
using coord_type = T;
using coordinate_type = T;
geometry()
: geometry_base<T>() {} // empty
@ -76,7 +76,7 @@ struct geometry : geometry_base<T>
template <typename T, template <typename...> class Cont>
struct geometry_collection : Cont<geometry<T>>
{
using coord_type = T;
using coordinate_type = T;
};
}}

View file

@ -33,14 +33,14 @@ namespace mapnik { namespace geometry {
template <typename T, template <typename...> class Cont = std::vector>
struct line_string : Cont<point<T> >
{
using coord_type = T;
using point_type = point<coord_type>;
using coordinate_type = T;
using point_type = point<coordinate_type>;
using container_type = Cont<point_type>;
line_string() = default;
explicit line_string(std::size_t size)
: container_type(size) {}
inline std::size_t num_points() const { return container_type::size(); }
inline void add_coord(coord_type x, coord_type y) { container_type::template emplace_back(x,y);}
inline void add_coord(coordinate_type x, coordinate_type y) { container_type::template emplace_back(x,y);}
};
}}

View file

@ -33,7 +33,7 @@ namespace mapnik { namespace geometry {
template <typename T, template <typename...> class Cont = std::vector>
struct multi_line_string : Cont<line_string<T>>
{
using coord_type = T;
using coordinate_type = T;
};
}}

View file

@ -33,8 +33,8 @@ namespace mapnik { namespace geometry {
template <typename T, template <typename...> class Cont = std::vector>
struct multi_point : Cont<point<T>>
{
using coord_type = T;
using point_type = point<coord_type>;
using coordinate_type = T;
using point_type = point<coordinate_type>;
using container_type = Cont<point_type>;
multi_point() = default;
explicit multi_point(std::size_t size)

View file

@ -33,7 +33,7 @@ namespace mapnik { namespace geometry {
template <typename T, template <typename...> class Cont = std::vector>
struct multi_polygon : Cont<polygon<T>>
{
using coord_type = T;
using coordinate_type = T;
};
}}

View file

@ -23,31 +23,12 @@
#ifndef MAPNIK_GEOMETRY_POINT_HPP
#define MAPNIK_GEOMETRY_POINT_HPP
#include <mapbox/geometry/point.hpp>
namespace mapnik { namespace geometry {
template <typename T>
struct point
{
using coord_type = T;
point() {}
point(T x_, T y_)
: x(x_), y(y_)
{}
coord_type x;
coord_type y;
};
template <typename T>
bool operator==(point<T> const& lhs, point<T> const& rhs)
{
return lhs.x == rhs.x && lhs.y == rhs.y;
}
template <typename T>
bool operator!=(point<T> const& lhs, point<T> const& rhs)
{
return lhs.x != rhs.x || lhs.y != rhs.y;
}
using point = mapbox::geometry::point<T>;
}}

View file

@ -34,7 +34,7 @@ namespace mapnik { namespace geometry {
template <typename T>
struct linear_ring : line_string<T>
{
using coord_type = T;
using coordinate_type = T;
linear_ring() = default;
explicit linear_ring(std::size_t size)
: line_string<T>(size) {}
@ -50,8 +50,8 @@ using rings_container = std::vector<linear_ring<T>>;
template <typename T, template <typename> class InteriorRings = rings_container>
struct polygon
{
using coord_type = T;
using rings_container = InteriorRings<coord_type>;
using coordinate_type = T;
using rings_container = InteriorRings<coordinate_type>;
linear_ring<T> exterior_ring;
rings_container interior_rings;

View file

@ -30,7 +30,7 @@ namespace mapnik {
namespace geometry {
template <typename T>
MAPNIK_DECL auto envelope(T const& geom) -> box2d<typename T::coord_type>;
MAPNIK_DECL auto envelope(T const& geom) -> box2d<typename T::coordinate_type>;
} // end ns geometry
} // end ns mapnik

View file

@ -31,8 +31,8 @@ namespace detail {
template <typename T>
struct geometry_envelope
{
using coord_type = T;
using bbox_type = box2d<coord_type>;
using coordinate_type = T;
using bbox_type = box2d<coordinate_type>;
bbox_type & bbox;
explicit geometry_envelope(bbox_type & bbox_)
@ -139,11 +139,11 @@ struct geometry_envelope
} // end ns detail
template <typename T>
auto envelope(T const& geom) -> box2d<typename T::coord_type>
auto envelope(T const& geom) -> box2d<typename T::coordinate_type>
{
using coord_type = typename T::coord_type;
box2d<coord_type> bbox;
detail::geometry_envelope<coord_type> op(bbox);
using coordinate_type = typename T::coordinate_type;
box2d<coordinate_type> bbox;
detail::geometry_envelope<coordinate_type> op(bbox);
op(geom);
return bbox;
}

View file

@ -161,15 +161,15 @@ private:
template <typename G>
inline bool is_empty(G const& geom)
{
using coord_type = typename G::coord_type;
return detail::geometry_is_empty<coord_type>()(geom);
using coordinate_type = typename G::coordinate_type;
return detail::geometry_is_empty<coordinate_type>()(geom);
}
template <typename G>
inline bool has_empty(G const& geom)
{
using coord_type = typename G::coord_type;
return detail::geometry_has_empty<coord_type>()(geom);
using coordinate_type = typename G::coordinate_type;
return detail::geometry_has_empty<coordinate_type>()(geom);
}
}}

View file

@ -132,8 +132,8 @@ struct geometry_is_simple
template <typename T>
inline bool is_simple(T const& geom)
{
using coord_type = typename T::coord_type;
return detail::geometry_is_simple<coord_type>() (geom);
using coordinate_type = typename T::coordinate_type;
return detail::geometry_is_simple<coordinate_type>() (geom);
}
template <typename T>

View file

@ -219,8 +219,8 @@ struct geometry_is_valid_string
template <typename T>
inline bool is_valid(T const& geom)
{
using coord_type = typename T::coord_type;
return detail::geometry_is_valid<coord_type>() (geom);
using coordinate_type = typename T::coordinate_type;
return detail::geometry_is_valid<coordinate_type>() (geom);
}
template <typename T>
@ -232,8 +232,8 @@ inline bool is_valid(mapnik::geometry::geometry<T> const& geom)
template <typename T>
inline bool is_valid(T const& geom, boost::geometry::validity_failure_type & failure)
{
using coord_type = typename T::coord_type;
return detail::geometry_is_valid_reason<coord_type>(failure) (geom);
using coordinate_type = typename T::coordinate_type;
return detail::geometry_is_valid_reason<coordinate_type>(failure) (geom);
}
template <typename T>
@ -246,8 +246,8 @@ inline bool is_valid(mapnik::geometry::geometry<T> const& geom,
template <typename T>
inline bool is_valid(T const& geom, std::string & message)
{
using coord_type = typename T::coord_type;
return detail::geometry_is_valid_string<coord_type>(message) (geom);
using coordinate_type = typename T::coordinate_type;
return detail::geometry_is_valid_string<coordinate_type>(message) (geom);
}
template <typename T>

View file

@ -149,8 +149,8 @@ struct geometry_to_path
template <typename T>
void to_path(T const& geom, path_type & p)
{
using coord_type = typename T::coord_type;
detail::geometry_to_path<coord_type> func(p);
using coordinate_type = typename T::coordinate_type;
detail::geometry_to_path<coordinate_type> func(p);
func(geom);
}

View file

@ -82,8 +82,8 @@ struct geometry_type
template <typename T>
static inline mapnik::geometry::geometry_types geometry_type(T const& geom)
{
using coord_type = typename T::coord_type;
return detail::geometry_type<coord_type>()(geom);
using coordinate_type = typename T::coordinate_type;
return detail::geometry_type<coordinate_type>()(geom);
}
}}

View file

@ -44,8 +44,8 @@ public:
PolygonExterior = Polygon,
PolygonInterior = Polygon | ( 1 << geometry_bits)
};
using coord_type = T;
using container_type = Container<coord_type>;
using coordinate_type = T;
using container_type = Container<coordinate_type>;
using value_type = typename container_type::value_type;
using size_type = typename container_type::size_type;
container_type cont_;
@ -84,17 +84,17 @@ public:
{
return cont_.size();
}
void push_vertex(coord_type x, coord_type y, CommandType c)
void push_vertex(coordinate_type x, coordinate_type y, CommandType c)
{
cont_.push_back(x,y,c);
}
void line_to(coord_type x,coord_type y)
void line_to(coordinate_type x,coordinate_type y)
{
push_vertex(x,y,SEG_LINETO);
}
void move_to(coord_type x,coord_type y)
void move_to(coordinate_type x,coordinate_type y)
{
push_vertex(x,y,SEG_MOVETO);
}

View file

@ -26,14 +26,12 @@
// mapnik
#include <mapnik/config.hpp>
#include <mapnik/util/noncopyable.hpp>
#include <mapnik/geometry/point.hpp>
// stl
#include <vector>
namespace mapnik {
namespace geometry {
template <typename T> struct point;
}
class projection;
template <typename T> class box2d;

View file

@ -145,7 +145,7 @@ struct svg_path_generator :
{
using path_type = Path;
using coord_type = typename boost::remove_pointer<typename path_type::value_type>::type;
using coordinate_type = typename boost::remove_pointer<typename path_type::value_type>::type;
svg_path_generator();
// rules
@ -153,7 +153,7 @@ struct svg_path_generator :
karma::rule<OutputIterator, path_type const& ()> point;
karma::rule<OutputIterator, path_type const& ()> linestring;
karma::rule<OutputIterator, path_type const& ()> polygon;
karma::rule<OutputIterator, coord_type ()> svg_point;
karma::rule<OutputIterator, coordinate_type ()> svg_point;
karma::rule<OutputIterator, path_type const& ()> svg_path;
// phoenix functions

View file

@ -117,8 +117,8 @@ private:
void increment()
{
// variables used to extract vertex components.
geometry_type::coord_type x;
geometry_type::coord_type y;
geometry_type::coordinate_type x;
geometry_type::coordinate_type y;
// extract next vertex components.
unsigned cmd = path_.vertex(&x, &y);
@ -170,7 +170,7 @@ private:
// Specialization of geometry_iterator, as needed by mapnik::svg::svg_path_data_grammar.
// The Value type is a std::tuple that holds 5 elements, the command and the x and y coordinate.
// Each coordinate is stored twice to match the needs of the grammar.
//using path_iterator_type = path_iterator<std::tuple<unsigned, geometry_type::coord_type, geometry_type::value_type>,
//using path_iterator_type = path_iterator<std::tuple<unsigned, geometry_type::coordinate_type, geometry_type::value_type>,
// transform_path_adapter<view_transform, geometry_type> >;
}}

View file

@ -39,7 +39,7 @@ enum CommandType : std::uint8_t {
template <typename T,int dim>
struct vertex {
using coord_type = T;
using coordinate_type = T;
};
template <typename T>
@ -47,9 +47,9 @@ struct vertex<T,2>
{
enum no_init_t : std::uint8_t { no_init };
using coord_type = T;
coord_type x;
coord_type y;
using coordinate_type = T;
coordinate_type x;
coordinate_type y;
unsigned cmd;
vertex()
@ -58,13 +58,13 @@ struct vertex<T,2>
explicit vertex(no_init_t)
{}
vertex(coord_type x_,coord_type y_,unsigned cmd_)
vertex(coordinate_type x_,coordinate_type y_,unsigned cmd_)
: x(x_),y(y_),cmd(cmd_) {}
template <typename T2>
vertex(vertex<T2,2> const& rhs)
: x(coord_type(rhs.x)),
y(coord_type(rhs.y)),
: x(coordinate_type(rhs.x)),
y(coordinate_type(rhs.y)),
cmd(rhs.cmd) {}
template <typename T2>

View file

@ -32,9 +32,9 @@ namespace mapnik { namespace geometry {
template <typename T>
struct point_vertex_adapter
{
using coord_type = T;
using coordinate_type = T;
point_vertex_adapter(point<T> const& pt);
unsigned vertex(coord_type * x, coord_type * y) const;
unsigned vertex(coordinate_type * x, coordinate_type * y) const;
void rewind(unsigned) const;
geometry_types type () const;
point<T> const& pt_;
@ -44,9 +44,9 @@ struct point_vertex_adapter
template <typename T>
struct line_string_vertex_adapter
{
using coord_type = T;
using coordinate_type = T;
line_string_vertex_adapter(line_string<T> const& line);
unsigned vertex(coord_type * x, coord_type * y) const;
unsigned vertex(coordinate_type * x, coordinate_type * y) const;
void rewind(unsigned) const;
geometry_types type () const;
line_string<T> const& line_;
@ -57,10 +57,10 @@ struct line_string_vertex_adapter
template <typename T>
struct polygon_vertex_adapter
{
using coord_type = T;
using coordinate_type = T;
polygon_vertex_adapter(polygon<T> const& poly);
void rewind(unsigned) const;
unsigned vertex(coord_type * x, coord_type * y) const;
unsigned vertex(coordinate_type * x, coordinate_type * y) const;
geometry_types type () const;
private:
polygon<T> const& poly_;
@ -74,10 +74,10 @@ private:
template <typename T>
struct ring_vertex_adapter
{
using coord_type = T;
using coordinate_type = T;
ring_vertex_adapter(linear_ring<T> const& ring);
void rewind(unsigned) const;
unsigned vertex(coord_type * x, coord_type * y) const;
unsigned vertex(coordinate_type * x, coordinate_type * y) const;
geometry_types type () const;
private:
linear_ring<T> const& ring_;

View file

@ -42,7 +42,7 @@ namespace mapnik
template <typename T>
class vertex_vector : private util::noncopyable
{
using coord_type = T;
using coordinate_type = T;
enum block_e {
block_shift = 8,
block_size = 1<<block_shift,
@ -51,13 +51,13 @@ class vertex_vector : private util::noncopyable
};
public:
// required for iterators support
using value_type = std::tuple<unsigned,coord_type,coord_type>;
using value_type = std::tuple<unsigned,coordinate_type,coordinate_type>;
using size_type = std::size_t;
using command_size = std::uint8_t;
private:
unsigned num_blocks_;
unsigned max_blocks_;
coord_type** vertices_;
coordinate_type** vertices_;
command_size** commands_;
size_type pos_;
@ -74,7 +74,7 @@ public:
{
if ( num_blocks_ )
{
coord_type** vertices=vertices_ + num_blocks_ - 1;
coordinate_type** vertices=vertices_ + num_blocks_ - 1;
while ( num_blocks_-- )
{
::operator delete(*vertices);
@ -88,14 +88,14 @@ public:
return pos_;
}
void push_back (coord_type x,coord_type y,command_size command)
void push_back (coordinate_type x,coordinate_type y,command_size command)
{
size_type block = pos_ >> block_shift;
if (block >= num_blocks_)
{
allocate_block(block);
}
coord_type* vertex = vertices_[block] + ((pos_ & block_mask) << 1);
coordinate_type* vertex = vertices_[block] + ((pos_ & block_mask) << 1);
command_size* cmd= commands_[block] + (pos_ & block_mask);
*cmd = static_cast<command_size>(command);
@ -103,11 +103,11 @@ public:
*vertex = y;
++pos_;
}
unsigned get_vertex(unsigned pos,coord_type* x,coord_type* y) const
unsigned get_vertex(unsigned pos,coordinate_type* x,coordinate_type* y) const
{
if (pos >= pos_) return SEG_END;
size_type block = pos >> block_shift;
const coord_type* vertex = vertices_[block] + (( pos & block_mask) << 1);
const coordinate_type* vertex = vertices_[block] + (( pos & block_mask) << 1);
*x = (*vertex++);
*y = (*vertex);
return commands_[block] [pos & block_mask];
@ -126,8 +126,8 @@ private:
{
if (block >= max_blocks_)
{
coord_type** new_vertices =
static_cast<coord_type**>(::operator new (sizeof(coord_type*)*((max_blocks_ + grow_by) * 2)));
coordinate_type** new_vertices =
static_cast<coordinate_type**>(::operator new (sizeof(coordinate_type*)*((max_blocks_ + grow_by) * 2)));
command_size** new_commands = (command_size**)(new_vertices + max_blocks_ + grow_by);
if (vertices_)
{
@ -139,8 +139,8 @@ private:
commands_ = new_commands;
max_blocks_ += grow_by;
}
vertices_[block] = static_cast<coord_type*>
(::operator new(sizeof(coord_type)*(block_size * 2 + block_size / (sizeof(coord_type)))));
vertices_[block] = static_cast<coordinate_type*>
(::operator new(sizeof(coordinate_type)*(block_size * 2 + block_size / (sizeof(coordinate_type)))));
commands_[block] = (command_size*)(vertices_[block] + block_size*2);
++num_blocks_;

View file

@ -104,31 +104,31 @@ template <typename OutputIterator, typename Geometry>
struct wkt_generator_grammar :
karma::grammar<OutputIterator, Geometry const& ()>
{
using coord_type = typename Geometry::coord_type;
using coordinate_type = typename Geometry::coordinate_type;
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<coord_type> const&()> point;
karma::rule<OutputIterator, geometry::point<coord_type> const&()> point_coord;
karma::rule<OutputIterator, geometry::geometry<coord_type> const&()> linestring;
karma::rule<OutputIterator, geometry::line_string<coord_type> const&()> linestring_coord;
karma::rule<OutputIterator, geometry::geometry<coord_type> const&()> polygon;
karma::rule<OutputIterator, geometry::polygon<coord_type> const&()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring<coord_type> const&()> exterior_ring_coord;
karma::rule<OutputIterator, std::vector<geometry::linear_ring<coord_type> > const&()> interior_ring_coord;
karma::rule<OutputIterator, geometry::geometry<coord_type> const& ()> multi_point;
karma::rule<OutputIterator, geometry::multi_point<coord_type> const& ()> multi_point_coord;
karma::rule<OutputIterator, geometry::geometry<coord_type> const& ()> multi_linestring;
karma::rule<OutputIterator, geometry::multi_line_string<coord_type> const& ()> multi_linestring_coord;
karma::rule<OutputIterator, geometry::geometry<coord_type> const& ()> multi_polygon;
karma::rule<OutputIterator, geometry::multi_polygon<coord_type> const& ()> multi_polygon_coord;
karma::rule<OutputIterator, geometry::geometry<coord_type> const& ()> geometry_collection;
karma::rule<OutputIterator, geometry::geometry_collection<coord_type> const& ()> geometries;
karma::rule<OutputIterator, geometry::geometry<coordinate_type> const&()> point;
karma::rule<OutputIterator, geometry::point<coordinate_type> const&()> point_coord;
karma::rule<OutputIterator, geometry::geometry<coordinate_type> const&()> linestring;
karma::rule<OutputIterator, geometry::line_string<coordinate_type> const&()> linestring_coord;
karma::rule<OutputIterator, geometry::geometry<coordinate_type> const&()> polygon;
karma::rule<OutputIterator, geometry::polygon<coordinate_type> const&()> polygon_coord;
karma::rule<OutputIterator, geometry::linear_ring<coordinate_type> const&()> exterior_ring_coord;
karma::rule<OutputIterator, std::vector<geometry::linear_ring<coordinate_type> > const&()> interior_ring_coord;
karma::rule<OutputIterator, geometry::geometry<coordinate_type> const& ()> multi_point;
karma::rule<OutputIterator, geometry::multi_point<coordinate_type> const& ()> multi_point_coord;
karma::rule<OutputIterator, geometry::geometry<coordinate_type> const& ()> multi_linestring;
karma::rule<OutputIterator, geometry::multi_line_string<coordinate_type> const& ()> multi_linestring_coord;
karma::rule<OutputIterator, geometry::geometry<coordinate_type> const& ()> multi_polygon;
karma::rule<OutputIterator, geometry::multi_polygon<coordinate_type> const& ()> multi_polygon_coord;
karma::rule<OutputIterator, geometry::geometry<coordinate_type> const& ()> geometry_collection;
karma::rule<OutputIterator, geometry::geometry_collection<coordinate_type> const& ()> geometries;
boost::phoenix::function<detail::get_type<Geometry> > geometry_type;
karma::symbols<mapnik::geometry::geometry_types, char const*> empty;
//
typename detail::coordinate_generator<coord_type>::generator coordinate;
typename detail::coordinate_generator<coordinate_type>::generator coordinate;
};
}}

View file

@ -34,7 +34,7 @@ point_vertex_adapter<T>::point_vertex_adapter(point<T> const& pt)
first_(true) {}
template <typename T>
unsigned point_vertex_adapter<T>::vertex(coord_type * x, coord_type * y) const
unsigned point_vertex_adapter<T>::vertex(coordinate_type * x, coordinate_type * y) const
{
if (first_)
{
@ -67,7 +67,7 @@ line_string_vertex_adapter<T>::line_string_vertex_adapter(line_string<T> const&
{}
template <typename T>
unsigned line_string_vertex_adapter<T>::vertex(coord_type * x, coord_type * y) const
unsigned line_string_vertex_adapter<T>::vertex(coordinate_type * x, coordinate_type * y) const
{
if (current_index_ != end_index_)
{
@ -117,7 +117,7 @@ void polygon_vertex_adapter<T>::rewind(unsigned) const
start_loop_ = true;
}
template <typename T>
unsigned polygon_vertex_adapter<T>::vertex(coord_type * x, coord_type * y) const
unsigned polygon_vertex_adapter<T>::vertex(coordinate_type * x, coordinate_type * y) const
{
if (rings_itr_ == rings_end_)
{
@ -177,7 +177,7 @@ void ring_vertex_adapter<T>::rewind(unsigned) const
}
template <typename T>
unsigned ring_vertex_adapter<T>::vertex(coord_type * x, coord_type * y) const
unsigned ring_vertex_adapter<T>::vertex(coordinate_type * x, coordinate_type * y) const
{
if (current_index_ < end_index_)
{