geometry - move point/line_string/polygon into separate headers

This commit is contained in:
artemp 2016-04-11 12:23:11 +02:00
parent c6425b8027
commit 90f06093ae
7 changed files with 190 additions and 76 deletions

View file

@ -23,88 +23,18 @@
#ifndef MAPNIK_GEOMETRY_HPP
#define MAPNIK_GEOMETRY_HPP
// mapnik
#include <mapnik/geometry/point.hpp>
#include <mapnik/geometry/line_string.hpp>
#include <mapnik/geometry/polygon.hpp>
#include <mapnik/util/variant.hpp>
// stl
#include <vector>
#include <type_traits>
#include <cstddef>
namespace mapnik { namespace geometry {
template <typename T>
struct point
{
using value_type = T;
point() {}
point(T x_, T y_)
: x(x_), y(y_)
{}
value_type x;
value_type y;
};
template <typename T>
bool operator==(point<T> const& lhs, point<T> const& rhs)
{
return lhs.x == rhs.x && lhs.y == rhs.y;
}
template <typename T>
bool operator!=(point<T> const& lhs, point<T> const& rhs)
{
return !(lhs == rhs);
}
template <typename T>
struct line_string : std::vector<point<T> >
{
line_string() = default;
explicit line_string(std::size_t size)
: std::vector<point<T> >(size) {}
inline std::size_t num_points() const { return std::vector<point<T>>::size(); }
inline void add_coord(T x, T y) { std::vector<point<T>>::template emplace_back(x,y);}
};
template <typename T>
struct linear_ring : line_string<T>
{
linear_ring() = default;
explicit linear_ring(std::size_t size)
: line_string<T>(size) {}
linear_ring(line_string<T> && other)
: line_string<T>(std::move(other)) {}
linear_ring(line_string<T> const& other)
: line_string<T>(other) {}
};
template <typename T>
using rings_container = std::vector<linear_ring<T>>;
template <typename T, template <typename> class InteriorRings = rings_container>
struct polygon
{
linear_ring<T> exterior_ring;
using rings_container = InteriorRings<T>;
rings_container interior_rings;
inline void set_exterior_ring(linear_ring<T> && ring)
{
exterior_ring = std::move(ring);
}
inline void add_hole(linear_ring<T> && ring)
{
interior_rings.emplace_back(std::move(ring));
}
inline bool empty() const { return exterior_ring.empty(); }
inline std::size_t num_rings() const
{
return 1 + interior_rings.size();
}
};
template <typename T>
struct multi_point : line_string<T> {};

View file

@ -0,0 +1,45 @@
/*****************************************************************************
*
* 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
*
*****************************************************************************/
#ifndef MAPNIK_GEOMETRY_LINE_STRING_HPP
#define MAPNIK_GEOMETRY_LINE_STRING_HPP
// mapnik
#include <mapnik/geometry/point.hpp>
// stl
#include <vector>
namespace mapnik { namespace geometry {
template <typename T>
struct line_string : std::vector<point<T> >
{
line_string() = default;
explicit line_string(std::size_t size)
: std::vector<point<T> >(size) {}
inline std::size_t num_points() const { return std::vector<point<T>>::size(); }
inline void add_coord(T x, T y) { std::vector<point<T>>::template emplace_back(x,y);}
};
}}
#endif // MAPNIK_GEOMETRY_LINE_STRING_HPP

View file

@ -0,0 +1,54 @@
/*****************************************************************************
*
* 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
*
*****************************************************************************/
#ifndef MAPNIK_GEOMETRY_POINT_HPP
#define MAPNIK_GEOMETRY_POINT_HPP
namespace mapnik { namespace geometry {
template <typename T>
struct point
{
using value_type = T;
point() {}
point(T x_, T y_)
: x(x_), y(y_)
{}
value_type x;
value_type y;
};
template <typename T>
bool operator==(point<T> const& lhs, point<T> const& rhs)
{
return lhs.x == rhs.x && lhs.y == rhs.y;
}
template <typename T>
bool operator!=(point<T> const& lhs, point<T> const& rhs)
{
return lhs.x != rhs.x || lhs.y != rhs.y;
}
}}
#endif // MAPNIK_GEOMETRY_POINT_HPP

View file

@ -0,0 +1,76 @@
/*****************************************************************************
*
* 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
*
*****************************************************************************/
#ifndef MAPNIK_GEOMETRY_POLYGON_HPP
#define MAPNIK_GEOMETRY_POLYGON_HPP
// mapnik
#include <mapnik/geometry/line_string.hpp>
// stl
#include <vector>
namespace mapnik { namespace geometry {
template <typename T>
struct linear_ring : line_string<T>
{
linear_ring() = default;
explicit linear_ring(std::size_t size)
: line_string<T>(size) {}
linear_ring(line_string<T> && other)
: line_string<T>(std::move(other)) {}
linear_ring(line_string<T> const& other)
: line_string<T>(other) {}
};
template <typename T>
using rings_container = std::vector<linear_ring<T>>;
template <typename T, template <typename> class InteriorRings = rings_container>
struct polygon
{
linear_ring<T> exterior_ring;
using rings_container = InteriorRings<T>;
rings_container interior_rings;
inline void set_exterior_ring(linear_ring<T> && ring)
{
exterior_ring = std::move(ring);
}
inline void add_hole(linear_ring<T> && ring)
{
interior_rings.emplace_back(std::move(ring));
}
inline bool empty() const { return exterior_ring.empty(); }
inline std::size_t num_rings() const
{
return 1 + interior_rings.size();
}
};
}}
#endif // MAPNIK_GEOMETRY_POLYGON_HPP

View file

@ -65,8 +65,10 @@ placement_finder::placement_finder(feature_impl const& feature,
bool placement_finder::next_position()
{
std::cerr << "next_position()" << std::endl;
if (info_.next())
{
std::cerr << "info_.next()" << std::endl;
// parent layout, has top-level ownership of a new evaluated_format_properties_ptr (TODO is this good enough to stay in scope???)
// but does not take ownership of the text_symbolizer_properties (info_.properties)
text_layout_ptr layout = std::make_shared<text_layout>(font_manager_,

View file

@ -34,6 +34,7 @@ namespace mapnik
bool text_placement_info_list::next() const
{
std::cerr << " state=" << state << " next()" << std::endl;
if (state == 0)
{
properties = parent_->defaults;
@ -95,6 +96,7 @@ text_placements_ptr text_placements_list::from_xml(xml_node const& node, fontset
{
auto list = std::make_shared<text_placements_list>();
list->defaults.from_xml(node, fontsets, is_shield);
int count = 0;
for( auto const& child : node)
{
if (child.is_text() || !child.is("Placement")) continue;

View file

@ -351,6 +351,7 @@ bool text_symbolizer_helper::next_line_placement() const
if (geo_itr_ == geometries_to_process_.end())
{
//Just processed the last geometry. Try next placement.
std::cerr << "Just processed the last geometry. Try next placement." << std::endl;
if (!finder_.next_position()) return false; //No more placements
//Start again from begin of list
geo_itr_ = geometries_to_process_.begin();
@ -360,10 +361,14 @@ bool text_symbolizer_helper::next_line_placement() const
if (mapnik::util::apply_visitor(apply_line_placement_visitor(converter_, adapter_), *geo_itr_))
{
//Found a placement
std::cerr << "Found placement!" << std::endl;
geo_itr_ = geometries_to_process_.erase(geo_itr_);
return true;
}
else
{
std::cerr << "ELSE?" << std::endl;
}
// No placement for this geometry. Keep it in geometries_to_process_ for next try.
++geo_itr_;
}