diff --git a/include/geometry.hpp b/include/geometry.hpp index cd9ec71d2..fdaea9d96 100644 --- a/include/geometry.hpp +++ b/include/geometry.hpp @@ -27,6 +27,7 @@ #include "geom_util.hpp" #include +#include namespace mapnik { @@ -36,136 +37,133 @@ namespace mapnik Polygon = 3, }; - template class Container=vertex_vector> - class geometry + template + class geometry : private boost::noncopyable { public: typedef T vertex_type; typedef typename vertex_type::type value_type; - typedef Container container_type; private: int srid_; - mutable unsigned itr_; - protected: - container_type cont_; public: geometry (int srid=-1) - : srid_(srid), - itr_(0), - cont_() {} - - virtual int type() const=0; - - virtual bool hit_test(value_type x,value_type y) const=0; - + : srid_(srid) {} + int srid() const { return srid_; } + virtual int type() const=0; + virtual bool hit_test(value_type x,value_type y) const=0; + virtual void move_to(value_type x,value_type y)=0; + + virtual void line_to(value_type x,value_type y)=0; + virtual void transform(const mapnik::CoordTransform& t)=0; + virtual unsigned num_points() const = 0; + virtual unsigned vertex(double* x, double* y)=0; + virtual void rewind(unsigned )=0; + virtual ~geometry() {} + }; + + template + class point : public geometry + { + typedef geometry geometry_base; + typedef typename geometry::vertex_type vertex_type; + typedef typename geometry::value_type value_type; + private: + vertex_type pt_; + public: + point(int srid) + : geometry(srid) + {} + + int type() const + { + return Point; + } + void move_to(value_type x,value_type y) { - cont_.push_back(x,y,SEG_MOVETO); + pt_.x = x; + pt_.y = y; } + + void line_to(value_type ,value_type ) {} + + void transform(const mapnik::CoordTransform& t) + { + t.forward_x(&pt_.x); + t.forward_y(&pt_.y); + } + + unsigned num_points() const + { + return 1; + } + + unsigned vertex(double* x, double* y) + { + *x = pt_.x; + *y = pt_.y; + return SEG_LINETO; + } + + void rewind(unsigned ) {} + + bool hit_test(value_type x,value_type y) const + { + return false; + } + virtual ~point() {} + }; + template class Container=vertex_vector> + class polygon : public geometry + { + typedef geometry geometry_base; + typedef typename geometry::vertex_type vertex_type; + typedef typename geometry_base::value_type value_type; + typedef Container container_type; + private: + container_type cont_; + mutable unsigned itr_; + public: + polygon(int srid) + : geometry_base(srid), + itr_(0) + {} + + int type() const + { + return Polygon; + } + void line_to(value_type x,value_type y) { cont_.push_back(x,y,SEG_LINETO); } - - template - class path_iterator + + void move_to(value_type x,value_type y) { - typedef vertex vertex_type; - const container_type* cont_; - unsigned pos_; - unsigned cmd_; - vertex_type vertex_; - - private: - - void advance () - { - if (pos_ < cont_->size()) - { - value_type x,y; - vertex_.cmd=cont_->get_vertex(pos_,&x,&y); - vertex_.x=Transform::apply(x); - vertex_.y=Transform::apply(y); - } - else - { - vertex_.cmd=SEG_END; - vertex_.x=0; - vertex_.y=0; - } - ++pos_; - } - - public: - - path_iterator() - : cont_(0), - pos_(0), - cmd_(SEG_END), - vertex_(0,0,cmd_) {} - - explicit path_iterator(const container_type& cont) - : cont_(&cont), - pos_(0), - cmd_(SEG_MOVETO), - vertex_(0,0,cmd_) - { - advance(); - } - - path_iterator& operator++() - { - advance(); - return *this; - } - - const vertex_type& operator*() const - { - return vertex_; - } - - const vertex_type* operator->() const - { - return &vertex_; - } - - bool operator !=(const path_iterator& itr) - { - return vertex_.cmd !=itr.vertex_.cmd; - } - }; - - template - path_iterator begin() const - { - return path_iterator(cont_); + cont_.push_back(x,y,SEG_MOVETO); } - template - path_iterator end() const + void transform(mapnik::CoordTransform const& t) { - return path_iterator(); - } - - void transform(const mapnik::CoordTransform& t) - { - for (unsigned pos=0;pos class Container=vertex_vector> - class point : public geometry - { - typedef geometry geometry_base; - typedef typename geometry::value_type value_type; - using geometry::cont_; - public: - point(int srid) - : geometry(srid) - {} - - int type() const - { - return Point; - } - bool hit_test(value_type x,value_type y) const - { - typedef typename geometry_base::template path_iterator path_iterator; - path_iterator start = geometry_base::template begin(); - path_iterator end = geometry_base::template end(); - return point_on_points(x,y,start,end); - } - }; - - template class Container=vertex_vector> - class polygon : public geometry - { - typedef geometry geometry_base; - typedef typename geometry_base::value_type value_type; - - public: - polygon(int srid) - : geometry_base(srid) - {} - - int type() const - { - return Polygon; - } - bool hit_test(value_type x,value_type y) const { - typedef typename geometry_base::template path_iterator path_iterator; - path_iterator start = geometry_base::template begin(); - path_iterator end = geometry_base::template end(); - return point_inside_path(x,y, start,end); + return false; } + virtual ~polygon() {} }; template class Container=vertex_vector> - class line_string : public geometry + class line_string : public geometry { - typedef geometry geometry_base; - typedef typename geometry::value_type value_type; + typedef geometry geometry_base; + typedef typename geometry_base::value_type value_type; + typedef typename geometry::vertex_type vertex_type; + typedef Container container_type; + private: + container_type cont_; + mutable unsigned itr_; public: line_string(int srid) - : geometry(srid) + : geometry_base(srid), + itr_(0) {} - + int type() const { return LineString; } - bool hit_test(value_type x,value_type y) const + void line_to(value_type x,value_type y) { - typedef typename geometry_base::template path_iterator path_iterator; - path_iterator start = geometry_base::template begin(); - path_iterator end = geometry_base::template end(); - return point_on_path(x,y,start,end); + cont_.push_back(x,y,SEG_LINETO); } + + void move_to(value_type x,value_type y) + { + cont_.push_back(x,y,SEG_MOVETO); + } + + void transform(mapnik::CoordTransform const& t) + { + unsigned size = cont_.size(); + for (unsigned pos=0; pos < size; ++pos) + { + cont_.transform_at(pos,t); + } + } + + unsigned num_points() const + { + return cont_.size(); + } + + unsigned vertex(double* x, double* y) + { + return cont_.get_vertex(itr_++,x,y); + } + + void rewind(unsigned ) + { + itr_=0; + } + + bool hit_test(value_type x,value_type y) const + { + return false; + } + virtual ~line_string() {} }; typedef point point_impl;