geometry - move point/line_string/polygon into separate headers

This commit is contained in:
artemp 2016-04-11 12:23:11 +02:00
parent 0025f70a6b
commit 0f711c0863
5 changed files with 181 additions and 75 deletions

View file

@ -23,88 +23,18 @@
#ifndef MAPNIK_GEOMETRY_HPP #ifndef MAPNIK_GEOMETRY_HPP
#define 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> #include <mapnik/util/variant.hpp>
// stl
#include <vector> #include <vector>
#include <type_traits> #include <type_traits>
#include <cstddef> #include <cstddef>
namespace mapnik { namespace geometry { 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> template <typename T>
struct multi_point : line_string<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

@ -95,6 +95,7 @@ text_placements_ptr text_placements_list::from_xml(xml_node const& node, fontset
{ {
auto list = std::make_shared<text_placements_list>(); auto list = std::make_shared<text_placements_list>();
list->defaults.from_xml(node, fontsets, is_shield); list->defaults.from_xml(node, fontsets, is_shield);
int count = 0;
for( auto const& child : node) for( auto const& child : node)
{ {
if (child.is_text() || !child.is("Placement")) continue; if (child.is_text() || !child.is("Placement")) continue;