/***************************************************************************** * * This file is part of Mapnik (c++ mapping toolkit) * * Copyright (C) 2016 Artem Pavlenko * * This library is free software; you can redistribute it and/or * modify it under the terms of the GNU Lesser General Public * License as published by the Free Software Foundation; either * version 2.1 of the License, or (at your option) any later version. * * This library is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU * Lesser General Public License for more details. * * You should have received a copy of the GNU Lesser General Public * License along with this library; if not, write to the Free Software * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA * *****************************************************************************/ #include #include #include #include namespace mapnik { namespace geometry { // point adapter template point_vertex_adapter::point_vertex_adapter(point const& pt) : pt_(pt), first_(true) {} template unsigned point_vertex_adapter::vertex(coordinate_type * x, coordinate_type * y) const { if (first_) { *x = pt_.x; *y = pt_.y; first_ = false; return mapnik::SEG_MOVETO; } return mapnik::SEG_END; } template void point_vertex_adapter::rewind(unsigned) const { first_ = true; } template geometry_types point_vertex_adapter::type () const { return geometry_types::Point; } // line_string adapter template line_string_vertex_adapter::line_string_vertex_adapter(line_string const& line) : line_(line), current_index_(0), end_index_(line.size()) {} template unsigned line_string_vertex_adapter::vertex(coordinate_type * x, coordinate_type * y) const { if (current_index_ != end_index_) { point const& coord = line_[current_index_++]; *x = coord.x; *y = coord.y; if (current_index_ == 1) { return mapnik::SEG_MOVETO; } else { return mapnik::SEG_LINETO; } } return mapnik::SEG_END; } template void line_string_vertex_adapter::rewind(unsigned) const { current_index_ = 0; } template geometry_types line_string_vertex_adapter::type() const { return geometry_types::LineString; } template polygon_vertex_adapter::polygon_vertex_adapter(polygon const& poly) : poly_(poly), rings_itr_(0), rings_end_(poly_.size()), current_index_(0), end_index_(poly_.empty() ? 0 : poly_[0].size()), start_loop_(true) {} template void polygon_vertex_adapter::rewind(unsigned) const { rings_itr_ = 0; rings_end_ = poly_.size(); current_index_ = 0; end_index_ = poly_.empty() ? 0 : poly_[0].size(); start_loop_ = true; } template unsigned polygon_vertex_adapter::vertex(coordinate_type * x, coordinate_type * y) const { if (rings_itr_ == rings_end_) { return mapnik::SEG_END; } if (current_index_ < end_index_) { point const& coord = poly_[rings_itr_][current_index_++]; *x = coord.x; *y = coord.y; if (start_loop_) { start_loop_= false; return mapnik::SEG_MOVETO; } if (current_index_ == end_index_) { *x = 0; *y = 0; return mapnik::SEG_CLOSE; } return mapnik::SEG_LINETO; } else if (++rings_itr_ != rings_end_) { current_index_ = 0; end_index_ = poly_[rings_itr_].size(); point const& coord = poly_[rings_itr_][current_index_++]; *x = coord.x; *y = coord.y; return mapnik::SEG_MOVETO; } return mapnik::SEG_END; } template geometry_types polygon_vertex_adapter::type () const { return geometry_types::Polygon; } // ring adapter template ring_vertex_adapter::ring_vertex_adapter(linear_ring const& ring) : ring_(ring), current_index_(0), end_index_(ring_.size()), start_loop_(true) {} template void ring_vertex_adapter::rewind(unsigned) const { current_index_ = 0; end_index_ = ring_.size(); start_loop_ = true; } template unsigned ring_vertex_adapter::vertex(coordinate_type * x, coordinate_type * y) const { if (current_index_ < end_index_) { auto const& coord = ring_[current_index_++]; *x = coord.x; *y = coord.y; if (start_loop_) { start_loop_= false; return mapnik::SEG_MOVETO; } if (current_index_ == end_index_) { *x = 0; *y = 0; return mapnik::SEG_CLOSE; } return mapnik::SEG_LINETO; } return mapnik::SEG_END; } template geometry_types ring_vertex_adapter::type () const { return geometry_types::Polygon; } template struct point_vertex_adapter; template struct line_string_vertex_adapter; template struct polygon_vertex_adapter; template struct ring_vertex_adapter; }}