+ 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 $
#ifndef GEOMETRY_HPP
@ -81,7 +80,7 @@ namespace mapnik {
virtual void rewind(unsigned) const=0;
virtual void set_capacity(size_t size)=0;
virtual ~geometry() {}
};
};
template <typename T>
class point : public geometry<T>
@ -137,19 +136,19 @@ namespace mapnik {
};
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 typename geometry<T>::vertex_type vertex_type;
typedef typename geometry_base::value_type value_type;
typedef Container<vertex_type> container_type;
typedef T vertex_type;
typedef typename vertex_type::type value_type;
typedef Container<vertex_type> container_type;
private:
container_type cont_;
mutable unsigned itr_;
public:
polygon()
: geometry_base(),
itr_(0)
: //geometry_base(),
itr_(0)
{}
int type() const
@ -157,33 +156,52 @@ namespace mapnik {
return Polygon;
}
void label_position(double *x, double *y) const
{
unsigned size = cont_.size();
if (size < 3)
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
{
unsigned size = cont_.size();
if (size < 3)
{
cont_.get_vertex(0,x,y);
return;
}
}
double ai;
double atmp = 0;
double xtmp = 0;
double ytmp = 0;
double x0 =0;
double y0 =0;
double x1 =0;
double y1 =0;
double ox =0;
double oy =0;
double ai;
double atmp = 0;
double xtmp = 0;
double ytmp = 0;
double x0 =0;
double y0 =0;
double x1 =0;
double y1 =0;
double ox =0;
double oy =0;
unsigned i;
unsigned i;
// Use first point as origin to improve numerical accuracy
cont_.get_vertex(0,&ox,&oy);
cont_.get_vertex(0,&ox,&oy);
for (i = 0; i < size-1; i++)
{
for (i = 0; i < size-1; i++)
{
cont_.get_vertex(i,&x0,&y0);
cont_.get_vertex(i+1,&x1,&y1);
@ -239,7 +257,7 @@ namespace mapnik {
{
cont_.set_capacity(size);
}
virtual ~polygon() {}
//virtual ~polygon() {}
};
template <typename T, template <typename> class Container=vertex_vector2>
@ -350,13 +368,15 @@ namespace mapnik {
virtual ~line_string() {}
};
typedef point<vertex2d> point_impl;
typedef line_string<vertex2d,vertex_vector2> line_string_impl;
typedef polygon<vertex2d,vertex_vector2> polygon_impl;
//typedef point<vertex2d> point_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 geometry<vertex2d> geometry2d;
typedef boost::shared_ptr<geometry2d> geometry_ptr;
typedef boost::ptr_vector<geometry2d> geometry_containter;
typedef polygon_impl geometry2d;
typedef boost::shared_ptr<geometry2d> geometry_ptr;
typedef boost::ptr_vector<geometry2d> geometry_containter;
}
#endif //GEOMETRY_HPP

View file

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