+ use path-like geometries

This commit is contained in:
Artem Pavlenko 2010-05-27 10:20:41 +00:00
parent 48d145d98c
commit e6e165f1e0
2 changed files with 64 additions and 44 deletions

View file

@ -20,7 +20,6 @@
* *
*****************************************************************************/ *****************************************************************************/
//$Id: geometry.hpp 39 2005-04-10 20:39:53Z pavlenko $ //$Id: geometry.hpp 39 2005-04-10 20:39:53Z pavlenko $
#ifndef GEOMETRY_HPP #ifndef GEOMETRY_HPP
@ -137,18 +136,18 @@ namespace mapnik {
}; };
template <typename T, template <typename> class Container=vertex_vector2> template <typename T, template <typename> class Container=vertex_vector2>
class polygon : public geometry<T> class polygon //: public geometry<T>
{ {
typedef geometry<T> geometry_base; typedef T vertex_type;
typedef typename geometry<T>::vertex_type vertex_type; typedef typename vertex_type::type value_type;
typedef typename geometry_base::value_type value_type;
typedef Container<vertex_type> container_type; typedef Container<vertex_type> container_type;
private: private:
container_type cont_; container_type cont_;
mutable unsigned itr_; mutable unsigned itr_;
public: public:
polygon() polygon()
: geometry_base(), : //geometry_base(),
itr_(0) itr_(0)
{} {}
@ -157,6 +156,25 @@ namespace mapnik {
return Polygon; return Polygon;
} }
box2d<double> envelope() const
{
box2d<double> result;
double x,y;
rewind(0);
for (unsigned i=0;i<num_points();++i)
{
vertex(&x,&y);
if (i==0)
{
result.init(x,y,x,y);
}
else
{
result.expand_to_include(x,y);
}
}
return result;
}
void label_position(double *x, double *y) const void label_position(double *x, double *y) const
{ {
unsigned size = cont_.size(); unsigned size = cont_.size();
@ -239,7 +257,7 @@ namespace mapnik {
{ {
cont_.set_capacity(size); cont_.set_capacity(size);
} }
virtual ~polygon() {} //virtual ~polygon() {}
}; };
template <typename T, template <typename> class Container=vertex_vector2> template <typename T, template <typename> class Container=vertex_vector2>
@ -350,11 +368,13 @@ namespace mapnik {
virtual ~line_string() {} virtual ~line_string() {}
}; };
typedef point<vertex2d> point_impl; //typedef point<vertex2d> point_impl;
typedef line_string<vertex2d,vertex_vector2> line_string_impl; //typedef line_string<vertex2d,vertex_vector2> line_string_impl;
typedef polygon<vertex2d,vertex_vector2> point_impl;
typedef polygon<vertex2d,vertex_vector2> line_string_impl;
typedef polygon<vertex2d,vertex_vector2> polygon_impl; typedef polygon<vertex2d,vertex_vector2> polygon_impl;
typedef geometry<vertex2d> geometry2d; typedef polygon_impl geometry2d;
typedef boost::shared_ptr<geometry2d> geometry_ptr; typedef boost::shared_ptr<geometry2d> geometry_ptr;
typedef boost::ptr_vector<geometry2d> geometry_containter; typedef boost::ptr_vector<geometry2d> geometry_containter;
} }

View file

@ -203,7 +203,7 @@ namespace mapnik
void read_point(Feature & feature) void read_point(Feature & feature)
{ {
geometry2d * pt = new point<vertex2d>; geometry2d * pt = new geometry2d;//new point<vertex2d>;
double x = read_double(); double x = read_double();
double y = read_double(); double y = read_double();
pt->move_to(x,y); pt->move_to(x,y);
@ -222,7 +222,7 @@ namespace mapnik
void read_multipoint_2(Feature & feature) void read_multipoint_2(Feature & feature)
{ {
geometry2d * pt = new point<vertex2d>; geometry2d * pt = new geometry2d;//point<vertex2d>;
int num_points = read_integer(); int num_points = read_integer();
for (int i=0;i<num_points;++i) for (int i=0;i<num_points;++i)
{ {
@ -236,7 +236,7 @@ namespace mapnik
void read_linestring(Feature & feature) void read_linestring(Feature & feature)
{ {
geometry2d * line = new line_string<vertex2d>; geometry2d * line = new geometry2d;//line_string<vertex2d>;
int num_points=read_integer(); int num_points=read_integer();
CoordinateArray ar(num_points); CoordinateArray ar(num_points);
read_coords(ar); read_coords(ar);
@ -261,7 +261,7 @@ namespace mapnik
void read_multilinestring_2(Feature & feature) void read_multilinestring_2(Feature & feature)
{ {
geometry2d * line = new line_string<vertex2d>; geometry2d * line = new geometry2d;//line_string<vertex2d>;
int num_lines=read_integer(); int num_lines=read_integer();
unsigned capacity = 0; unsigned capacity = 0;
for (int i=0;i<num_lines;++i) for (int i=0;i<num_lines;++i)