added set_capacity method to geometry classes.
(now we can use std::vector<boost::tuple<value_type,value_type,char> > as an alternative vertex storage).
This commit is contained in:
parent
2a858bcd19
commit
2d4ea20560
3 changed files with 34 additions and 17 deletions
|
@ -62,6 +62,7 @@ namespace mapnik
|
|||
virtual unsigned num_points() const = 0;
|
||||
virtual unsigned vertex(double* x, double* y)=0;
|
||||
virtual void rewind(unsigned )=0;
|
||||
virtual void set_capacity(size_t size)=0;
|
||||
virtual ~geometry() {}
|
||||
};
|
||||
|
||||
|
@ -120,6 +121,7 @@ namespace mapnik
|
|||
{
|
||||
return false;
|
||||
}
|
||||
void set_capacity(size_t) {}
|
||||
virtual ~point() {}
|
||||
};
|
||||
|
||||
|
@ -216,6 +218,10 @@ namespace mapnik
|
|||
{
|
||||
return false;
|
||||
}
|
||||
void set_capacity(size_t size)
|
||||
{
|
||||
cont_.set_capacity(size);
|
||||
}
|
||||
virtual ~polygon() {}
|
||||
};
|
||||
|
||||
|
@ -332,12 +338,17 @@ namespace mapnik
|
|||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
void set_capacity(size_t size)
|
||||
{
|
||||
cont_.set_capacity(size);
|
||||
}
|
||||
virtual ~line_string() {}
|
||||
};
|
||||
|
||||
typedef point<vertex2d> point_impl;
|
||||
typedef line_string<vertex2d,vertex_vector> line_string_impl;
|
||||
typedef polygon<vertex2d,vertex_vector> polygon_impl;
|
||||
typedef line_string<vertex2d,vertex_vector2> line_string_impl;
|
||||
typedef polygon<vertex2d,vertex_vector2> polygon_impl;
|
||||
|
||||
typedef geometry<vertex2d> geometry_type;
|
||||
typedef boost::shared_ptr<geometry_type> geometry_ptr;
|
||||
|
|
|
@ -115,7 +115,10 @@ namespace mapnik
|
|||
++vertex;
|
||||
t.forward_y(vertex);
|
||||
}
|
||||
|
||||
void set_capacity(size_t)
|
||||
{
|
||||
//do nothing
|
||||
}
|
||||
private:
|
||||
void allocate_block(unsigned block)
|
||||
{
|
||||
|
@ -143,9 +146,8 @@ namespace mapnik
|
|||
struct vertex_vector2 : boost::noncopyable
|
||||
{
|
||||
typedef typename T::type value_type;
|
||||
typedef boost::tuple<value_type,value_type,char> coord;
|
||||
typedef boost::tuple<value_type,value_type,char> vertex_type;
|
||||
vertex_vector2() {}
|
||||
|
||||
unsigned size() const
|
||||
{
|
||||
return cont_.size();
|
||||
|
@ -153,27 +155,30 @@ namespace mapnik
|
|||
|
||||
void push_back (value_type x,value_type y,unsigned command)
|
||||
{
|
||||
cont_.push_back(coord(x,y,command));
|
||||
cont_.push_back(vertex_type(x,y,command));
|
||||
}
|
||||
unsigned get_vertex(unsigned pos,value_type* x,value_type* y) const
|
||||
{
|
||||
if (pos >= cont_.size()) return SEG_END;
|
||||
coord const& c = cont_[pos];
|
||||
vertex_type const& c = cont_[pos];
|
||||
*x = boost::get<0>(c);
|
||||
*y = boost::get<1>(c);
|
||||
return boost::get<2>(c);
|
||||
}
|
||||
|
||||
|
||||
void transform_at(unsigned pos,const CoordTransform& t)
|
||||
{
|
||||
if (pos >= cont_.size()) return;
|
||||
coord & c = cont_[pos];
|
||||
vertex_type & c = cont_[pos];
|
||||
t.forward_x(&boost::get<0>(c));
|
||||
t.forward_y(&boost::get<1>(c));
|
||||
}
|
||||
|
||||
void set_capacity(size_t size)
|
||||
{
|
||||
cont_.reserve(size);
|
||||
}
|
||||
private:
|
||||
std::vector<coord> cont_;
|
||||
std::vector<vertex_type> cont_;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -92,9 +92,10 @@ geometry_ptr shape_io::read_polyline()
|
|||
int num_parts=record.read_ndr_integer();
|
||||
int num_points=record.read_ndr_integer();
|
||||
geometry_ptr line(new line_string_impl(-1));
|
||||
|
||||
line->set_capacity(num_points + num_parts);
|
||||
if (num_parts == 1)
|
||||
{
|
||||
line->set_capacity(num_points + 1);
|
||||
record.skip(4);
|
||||
double x=record.read_double();
|
||||
double y=record.read_double();
|
||||
|
@ -145,7 +146,7 @@ geometry_ptr shape_io::read_polylinem()
|
|||
int num_parts=record.read_ndr_integer();
|
||||
int num_points=record.read_ndr_integer();
|
||||
geometry_ptr line(new line_string_impl(-1));
|
||||
|
||||
line->set_capacity(num_points + num_parts);
|
||||
if (num_parts == 1)
|
||||
{
|
||||
record.skip(4);
|
||||
|
@ -207,7 +208,7 @@ geometry_ptr shape_io::read_polylinez()
|
|||
int num_parts=record.read_ndr_integer();
|
||||
int num_points=record.read_ndr_integer();
|
||||
geometry_ptr line(new line_string_impl(-1));
|
||||
|
||||
line->set_capacity(num_points + num_parts);
|
||||
if (num_parts == 1)
|
||||
{
|
||||
record.skip(4);
|
||||
|
@ -277,7 +278,7 @@ geometry_ptr shape_io::read_polygon()
|
|||
int num_points=record.read_ndr_integer();
|
||||
std::vector<int> parts(num_parts);
|
||||
geometry_ptr poly(new polygon_impl(-1));
|
||||
|
||||
poly->set_capacity(num_points + num_parts);
|
||||
for (int i=0;i<num_parts;++i)
|
||||
{
|
||||
parts[i]=record.read_ndr_integer();
|
||||
|
@ -317,7 +318,7 @@ geometry_ptr shape_io::read_polygonm()
|
|||
int num_points=record.read_ndr_integer();
|
||||
std::vector<int> parts(num_parts);
|
||||
geometry_ptr poly(new polygon_impl(-1));
|
||||
|
||||
poly->set_capacity(num_points + num_parts);
|
||||
for (int i=0;i<num_parts;++i)
|
||||
{
|
||||
parts[i]=record.read_ndr_integer();
|
||||
|
@ -365,7 +366,7 @@ geometry_ptr shape_io::read_polygonz()
|
|||
int num_points=record.read_ndr_integer();
|
||||
std::vector<int> parts(num_parts);
|
||||
geometry_ptr poly(new polygon_impl(-1));
|
||||
|
||||
poly->set_capacity(num_points + num_parts);
|
||||
for (int i=0;i<num_parts;++i)
|
||||
{
|
||||
parts[i]=record.read_ndr_integer();
|
||||
|
|
Loading…
Reference in a new issue