2015-05-22 16:12:50 +02:00
|
|
|
#include "catch.hpp"
|
|
|
|
|
|
|
|
#include <mapnik/grid_vertex_converter.hpp>
|
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
TEST_CASE("spiral_iterator")
|
|
|
|
{
|
|
|
|
SECTION("sprial 3x3")
|
|
|
|
{
|
|
|
|
mapnik::geometry::spiral_iterator si(3);
|
|
|
|
const mapnik::geometry::point<int> points[] =
|
|
|
|
{{0, 0}, {1, 0}, {1, -1}, {0, -1}, {-1, -1}, {-1, 0}, {-1, 1}, {0, 1}, {1, 1}};
|
2015-05-22 16:12:50 +02:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
const std::size_t points_size = std::extent<decltype(points)>::value;
|
2015-05-22 16:12:50 +02:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
int x, y;
|
|
|
|
std::size_t index = 0;
|
2015-05-22 16:12:50 +02:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
while (si.vertex(&x, &y))
|
|
|
|
{
|
|
|
|
REQUIRE(index < points_size);
|
2015-05-22 16:12:50 +02:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
CHECK(x == points[index].x);
|
|
|
|
CHECK(y == points[index].y);
|
2015-05-22 16:12:50 +02:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
index++;
|
|
|
|
}
|
2015-05-22 16:12:50 +02:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
CHECK(index == points_size);
|
2015-05-22 16:12:50 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
TEST_CASE("grid_vertex_converter")
|
|
|
|
{
|
|
|
|
SECTION("empty polygon")
|
|
|
|
{
|
|
|
|
mapnik::geometry::polygon<double> poly;
|
|
|
|
using path_type = mapnik::geometry::polygon_vertex_adapter<double>;
|
|
|
|
path_type path(poly);
|
|
|
|
using converter_type = mapnik::geometry::grid_vertex_converter<path_type, double>;
|
|
|
|
converter_type gvc(path, 10.0, 10.0, 1.0);
|
2015-05-22 16:12:50 +02:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
double x, y;
|
|
|
|
unsigned cmd = gvc.vertex(&x, &y);
|
2015-05-22 16:12:50 +02:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
CHECK(cmd == mapnik::SEG_END);
|
|
|
|
}
|
2015-05-22 16:12:50 +02:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
SECTION("empty polygon exterior ring")
|
|
|
|
{
|
|
|
|
mapnik::geometry::polygon<double> poly;
|
|
|
|
poly.emplace_back();
|
2015-05-22 16:12:50 +02:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
using path_type = mapnik::geometry::polygon_vertex_adapter<double>;
|
|
|
|
path_type path(poly);
|
|
|
|
using converter_type = mapnik::geometry::grid_vertex_converter<path_type, double>;
|
|
|
|
converter_type gvc(path, 10.0, 10.0, 1.0);
|
2015-05-22 16:12:50 +02:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
double x, y;
|
|
|
|
unsigned cmd = gvc.vertex(&x, &y);
|
2015-05-22 16:12:50 +02:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
CHECK(cmd == mapnik::SEG_END);
|
|
|
|
}
|
2015-05-22 16:12:50 +02:00
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
SECTION("grid of a square")
|
2015-05-22 16:12:50 +02:00
|
|
|
{
|
2022-01-26 23:25:53 +01:00
|
|
|
mapnik::geometry::polygon<double> poly;
|
|
|
|
poly.emplace_back();
|
|
|
|
auto& exterior_ring = poly.front();
|
|
|
|
exterior_ring.emplace_back(-10, -10);
|
|
|
|
exterior_ring.emplace_back(10, -10);
|
|
|
|
exterior_ring.emplace_back(10, 10);
|
|
|
|
exterior_ring.emplace_back(-10, 10);
|
|
|
|
exterior_ring.emplace_back(-10, -10);
|
|
|
|
|
|
|
|
using path_type = mapnik::geometry::polygon_vertex_adapter<double>;
|
|
|
|
path_type path(poly);
|
|
|
|
using converter_type = mapnik::geometry::grid_vertex_converter<path_type, double>;
|
|
|
|
converter_type gvc(path, 3.0, 3.0, 1.0);
|
|
|
|
|
|
|
|
const mapnik::geometry::point<double> points[] = {
|
|
|
|
{0, 0}, {3, 0}, {3, 3}, {0, 3}, {-3, 3}, {-3, 0}, {-3, -3}, {0, -3}, {3, -3}, {6, -3},
|
|
|
|
{6, 0}, {6, 3}, {6, 6}, {3, 6}, {0, 6}, {-3, 6}, {-6, 6}, {-6, 3}, {-6, 0}, {-6, -3},
|
|
|
|
{-6, -6}, {-3, -6}, {0, -6}, {3, -6}, {6, -6}, {9, -6}, {9, -3}, {9, 0}, {9, 3}, {9, 6},
|
|
|
|
{9, 9}, {6, 9}, {3, 9}, {0, 9}, {-3, 9}, {-6, 9}, {-9, 9}, {-9, 6}, {-9, 3}, {-9, 0},
|
|
|
|
{-9, -3}, {-9, -6}, {-9, -9}, {-6, -9}, {-3, -9}, {0, -9}, {3, -9}, {6, -9}, {9, -9}};
|
|
|
|
const std::size_t points_size = std::extent<decltype(points)>::value;
|
|
|
|
|
|
|
|
double x, y;
|
|
|
|
unsigned cmd = mapnik::SEG_END;
|
|
|
|
std::size_t index = 0;
|
|
|
|
|
|
|
|
while ((cmd = gvc.vertex(&x, &y)) != mapnik::SEG_END)
|
|
|
|
{
|
|
|
|
REQUIRE(index < points_size);
|
|
|
|
|
|
|
|
CHECK(cmd == mapnik::SEG_MOVETO);
|
|
|
|
CHECK(x == Approx(points[index].x));
|
|
|
|
CHECK(y == Approx(points[index].y));
|
|
|
|
|
|
|
|
index++;
|
|
|
|
}
|
|
|
|
|
|
|
|
CHECK(index == points_size);
|
|
|
|
CHECK(cmd == mapnik::SEG_END);
|
2015-05-22 16:12:50 +02:00
|
|
|
}
|
|
|
|
}
|