2016-09-06 17:15:11 +02:00
|
|
|
#include "catch.hpp"
|
|
|
|
#include "fake_path.hpp"
|
|
|
|
|
|
|
|
// mapnik
|
|
|
|
#include <mapnik/extend_converter.hpp>
|
|
|
|
|
|
|
|
// stl
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
namespace offset_test {
|
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
TEST_CASE("extend converter")
|
|
|
|
{
|
|
|
|
SECTION("empty")
|
2016-09-06 17:15:11 +02:00
|
|
|
{
|
2022-01-26 23:25:53 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
fake_path path = {};
|
|
|
|
mapnik::extend_converter<fake_path> c(path, 1000);
|
|
|
|
double x, y;
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_END);
|
2022-11-10 16:57:38 +01:00
|
|
|
}
|
|
|
|
catch (std::exception const& ex)
|
2022-01-26 23:25:53 +01:00
|
|
|
{
|
|
|
|
std::cerr << ex.what() << "\n";
|
|
|
|
REQUIRE(false);
|
|
|
|
}
|
2016-09-06 17:15:11 +02:00
|
|
|
}
|
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
SECTION("one point")
|
2016-09-06 17:15:11 +02:00
|
|
|
{
|
2022-01-26 23:25:53 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
fake_path path = {0, 0};
|
|
|
|
mapnik::extend_converter<fake_path> c(path, 1000);
|
|
|
|
double x, y;
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_MOVETO);
|
|
|
|
REQUIRE(x == 0);
|
|
|
|
REQUIRE(y == 0);
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_END);
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_END);
|
2022-11-10 16:57:38 +01:00
|
|
|
}
|
|
|
|
catch (std::exception const& ex)
|
2022-01-26 23:25:53 +01:00
|
|
|
{
|
|
|
|
std::cerr << ex.what() << "\n";
|
|
|
|
REQUIRE(false);
|
|
|
|
}
|
2016-09-06 17:15:11 +02:00
|
|
|
}
|
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
SECTION("two points")
|
2016-09-06 17:15:11 +02:00
|
|
|
{
|
2022-01-26 23:25:53 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
fake_path path = {0, 0, 1, 0};
|
|
|
|
mapnik::extend_converter<fake_path> c(path, 1000);
|
|
|
|
double x, y;
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_MOVETO);
|
|
|
|
REQUIRE(x == -1000);
|
|
|
|
REQUIRE(y == 0);
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_LINETO);
|
|
|
|
REQUIRE(x == 1001);
|
|
|
|
REQUIRE(y == 0);
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_END);
|
2022-11-10 16:57:38 +01:00
|
|
|
}
|
|
|
|
catch (std::exception const& ex)
|
2022-01-26 23:25:53 +01:00
|
|
|
{
|
|
|
|
std::cerr << ex.what() << "\n";
|
|
|
|
REQUIRE(false);
|
|
|
|
}
|
2016-09-06 17:15:11 +02:00
|
|
|
}
|
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
SECTION("three points")
|
2016-09-06 17:15:11 +02:00
|
|
|
{
|
2022-01-26 23:25:53 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
fake_path path = {0, 0, 1, 0, 2, 0};
|
|
|
|
mapnik::extend_converter<fake_path> c(path, 1000);
|
|
|
|
double x, y;
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_MOVETO);
|
|
|
|
REQUIRE(x == -1000);
|
|
|
|
REQUIRE(y == 0);
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_LINETO);
|
|
|
|
REQUIRE(x == 1);
|
|
|
|
REQUIRE(y == 0);
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_LINETO);
|
|
|
|
REQUIRE(x == 1002);
|
|
|
|
REQUIRE(y == 0);
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_END);
|
2022-11-10 16:57:38 +01:00
|
|
|
}
|
|
|
|
catch (std::exception const& ex)
|
2022-01-26 23:25:53 +01:00
|
|
|
{
|
|
|
|
std::cerr << ex.what() << "\n";
|
|
|
|
REQUIRE(false);
|
|
|
|
}
|
2016-09-06 17:15:11 +02:00
|
|
|
}
|
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
SECTION("more points")
|
2016-09-06 17:15:11 +02:00
|
|
|
{
|
2022-01-26 23:25:53 +01:00
|
|
|
try
|
|
|
|
{
|
|
|
|
fake_path path = {0, 0, 1, 0, 2, 0, 3, 0, 4, 0, 5, 0};
|
|
|
|
mapnik::extend_converter<fake_path> c(path, 1000);
|
|
|
|
double x, y;
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_MOVETO);
|
|
|
|
REQUIRE(x == -1000);
|
|
|
|
REQUIRE(y == 0);
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_LINETO);
|
|
|
|
REQUIRE(x == 1);
|
|
|
|
REQUIRE(y == 0);
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_LINETO);
|
|
|
|
REQUIRE(x == 2);
|
|
|
|
REQUIRE(y == 0);
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_LINETO);
|
|
|
|
REQUIRE(x == 3);
|
|
|
|
REQUIRE(y == 0);
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_LINETO);
|
|
|
|
REQUIRE(x == 4);
|
|
|
|
REQUIRE(y == 0);
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_LINETO);
|
|
|
|
REQUIRE(x == 1005);
|
|
|
|
REQUIRE(y == 0);
|
|
|
|
REQUIRE(c.vertex(&x, &y) == mapnik::SEG_END);
|
2022-11-10 16:57:38 +01:00
|
|
|
}
|
|
|
|
catch (std::exception const& ex)
|
2022-01-26 23:25:53 +01:00
|
|
|
{
|
|
|
|
std::cerr << ex.what() << "\n";
|
|
|
|
REQUIRE(false);
|
|
|
|
}
|
2016-09-06 17:15:11 +02:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2022-01-26 23:25:53 +01:00
|
|
|
} // namespace offset_test
|