2015-03-28 06:16:49 +00:00
|
|
|
#include "catch.hpp"
|
|
|
|
|
|
|
|
#include <mapnik/vertex_adapters.hpp>
|
2017-03-27 15:14:51 +00:00
|
|
|
#include <mapnik/geometry/correct.hpp>
|
2015-03-28 06:16:49 +00:00
|
|
|
|
|
|
|
TEST_CASE("vertex_adapters") {
|
|
|
|
|
|
|
|
SECTION("polygon") {
|
2015-04-09 20:22:51 +00:00
|
|
|
mapnik::geometry::polygon<double> g;
|
2016-06-29 11:37:32 +00:00
|
|
|
g.emplace_back();
|
|
|
|
g.back().emplace_back(1,1);
|
|
|
|
g.back().emplace_back(2,2);
|
|
|
|
g.back().emplace_back(100,100);
|
|
|
|
g.back().emplace_back(1,1);
|
2015-03-28 06:16:49 +00:00
|
|
|
|
2015-04-09 20:22:51 +00:00
|
|
|
mapnik::geometry::polygon_vertex_adapter<double> va(g);
|
2015-03-28 06:16:49 +00:00
|
|
|
double x,y;
|
|
|
|
unsigned cmd;
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_MOVETO );
|
|
|
|
REQUIRE( x == 1 );
|
|
|
|
REQUIRE( y == 1 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == 2 );
|
|
|
|
REQUIRE( y == 2 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == 100 );
|
|
|
|
REQUIRE( y == 100 );
|
|
|
|
|
|
|
|
// close
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_CLOSE );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 0 );
|
|
|
|
|
|
|
|
// end
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_END );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 0 );
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("polygon with hole") {
|
2015-04-09 20:22:51 +00:00
|
|
|
mapnik::geometry::polygon<double> g;
|
2016-06-29 11:37:32 +00:00
|
|
|
g.emplace_back();
|
|
|
|
g.back().emplace_back(0,0);
|
|
|
|
g.back().emplace_back(-10,0);
|
|
|
|
g.back().emplace_back(-10,10);
|
|
|
|
g.back().emplace_back(0,10);
|
|
|
|
g.back().emplace_back(0,0);
|
2015-04-09 20:22:51 +00:00
|
|
|
std::vector<mapnik::geometry::linear_ring<double> > interior_rings;
|
|
|
|
mapnik::geometry::linear_ring<double> hole;
|
2016-06-27 09:23:13 +00:00
|
|
|
hole.emplace_back(-7,7);
|
|
|
|
hole.emplace_back(-7,3);
|
|
|
|
hole.emplace_back(-3,3);
|
|
|
|
hole.emplace_back(-3,7);
|
|
|
|
hole.emplace_back(-7,7);
|
2016-06-29 11:37:32 +00:00
|
|
|
g.push_back(std::move(hole));
|
2015-03-28 06:16:49 +00:00
|
|
|
|
2015-04-09 20:22:51 +00:00
|
|
|
mapnik::geometry::linear_ring<double> hole_in_hole;
|
2016-06-27 09:23:13 +00:00
|
|
|
hole_in_hole.emplace_back(-6,4);
|
|
|
|
hole_in_hole.emplace_back(-6,6);
|
|
|
|
hole_in_hole.emplace_back(-4,6);
|
|
|
|
hole_in_hole.emplace_back(-4,4);
|
|
|
|
hole_in_hole.emplace_back(-6,4);
|
2016-06-29 11:37:32 +00:00
|
|
|
g.push_back(std::move(hole_in_hole));
|
2015-03-28 06:16:49 +00:00
|
|
|
|
2015-04-09 20:22:51 +00:00
|
|
|
mapnik::geometry::polygon_vertex_adapter<double> va(g);
|
2015-03-28 06:16:49 +00:00
|
|
|
double x,y;
|
|
|
|
unsigned cmd;
|
|
|
|
|
|
|
|
// exterior ring
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_MOVETO );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 0 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -10 );
|
|
|
|
REQUIRE( y == 0 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -10 );
|
|
|
|
REQUIRE( y == 10 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 10 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_CLOSE );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 0 );
|
|
|
|
|
2015-04-13 16:47:51 +00:00
|
|
|
// exterior ring via ring_vertex_adapter
|
2016-06-29 11:37:32 +00:00
|
|
|
mapnik::geometry::ring_vertex_adapter<double> va2(g.front());
|
2015-04-13 16:47:51 +00:00
|
|
|
cmd = va2.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_MOVETO );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 0 );
|
|
|
|
|
|
|
|
cmd = va2.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -10 );
|
|
|
|
REQUIRE( y == 0 );
|
|
|
|
|
|
|
|
cmd = va2.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -10 );
|
|
|
|
REQUIRE( y == 10 );
|
|
|
|
|
|
|
|
cmd = va2.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 10 );
|
|
|
|
|
|
|
|
cmd = va2.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_CLOSE );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 0 );
|
|
|
|
|
|
|
|
// since ring adapter is only for exterior, next should be END
|
|
|
|
cmd = va2.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_END );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 0 );
|
|
|
|
|
|
|
|
// first hole for polygon_adapter
|
2015-03-28 06:16:49 +00:00
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_MOVETO );
|
|
|
|
REQUIRE( x == -7 );
|
|
|
|
REQUIRE( y == 7 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -7 );
|
|
|
|
REQUIRE( y == 3 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -3 );
|
|
|
|
REQUIRE( y == 3 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -3 );
|
|
|
|
REQUIRE( y == 7 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_CLOSE );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 0 );
|
|
|
|
|
|
|
|
// second hole
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_MOVETO );
|
|
|
|
REQUIRE( x == -6 );
|
|
|
|
REQUIRE( y == 4 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -6 );
|
|
|
|
REQUIRE( y == 6 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -4 );
|
|
|
|
REQUIRE( y == 6 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -4 );
|
|
|
|
REQUIRE( y == 4 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
2015-03-29 06:55:20 +00:00
|
|
|
REQUIRE( cmd == mapnik::SEG_CLOSE );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 0 );
|
2015-03-28 06:16:49 +00:00
|
|
|
|
|
|
|
mapnik::geometry::correct(g);
|
|
|
|
|
|
|
|
va.rewind(0);
|
|
|
|
|
|
|
|
// exterior ring: flipped winding order from correct
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_MOVETO );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 0 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 10 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -10 );
|
|
|
|
REQUIRE( y == 10 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -10 );
|
|
|
|
REQUIRE( y == 0 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_CLOSE );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 0 );
|
|
|
|
|
|
|
|
// first hole: flipped winding order from correct
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_MOVETO );
|
|
|
|
REQUIRE( x == -7 );
|
|
|
|
REQUIRE( y == 7 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -3 );
|
|
|
|
REQUIRE( y == 7 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -3 );
|
|
|
|
REQUIRE( y == 3 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -7 );
|
|
|
|
REQUIRE( y == 3 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_CLOSE );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 0 );
|
|
|
|
|
|
|
|
// second hole: correct appears not to have changed winding order
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_MOVETO );
|
|
|
|
REQUIRE( x == -6 );
|
|
|
|
REQUIRE( y == 4 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -6 );
|
|
|
|
REQUIRE( y == 6 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -4 );
|
|
|
|
REQUIRE( y == 6 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_LINETO );
|
|
|
|
REQUIRE( x == -4 );
|
|
|
|
REQUIRE( y == 4 );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
2015-03-29 06:55:20 +00:00
|
|
|
REQUIRE( cmd == mapnik::SEG_CLOSE );
|
|
|
|
REQUIRE( x == 0 );
|
|
|
|
REQUIRE( y == 0 );
|
2015-03-28 06:16:49 +00:00
|
|
|
}
|
|
|
|
|
2018-01-23 15:18:44 +00:00
|
|
|
SECTION("polygon with empty exterior ring") {
|
|
|
|
mapnik::geometry::polygon<double> g;
|
|
|
|
g.emplace_back();
|
|
|
|
|
|
|
|
mapnik::geometry::polygon_vertex_adapter<double> va(g);
|
2018-02-04 08:46:14 +00:00
|
|
|
double x = 0, y = 0;
|
2018-01-23 15:18:44 +00:00
|
|
|
unsigned cmd;
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
CHECK( cmd == mapnik::SEG_END );
|
|
|
|
CHECK( x == Approx(0) );
|
|
|
|
CHECK( y == Approx(0) );
|
|
|
|
}
|
|
|
|
|
|
|
|
SECTION("polygon with empty interior ring") {
|
|
|
|
mapnik::geometry::polygon<double> g;
|
|
|
|
g.emplace_back();
|
|
|
|
g.back().emplace_back(-1, -1);
|
|
|
|
g.back().emplace_back( 1, -1);
|
|
|
|
g.back().emplace_back( 1, 1);
|
|
|
|
g.back().emplace_back(-1, 1);
|
|
|
|
g.back().emplace_back(-1, -1);
|
|
|
|
|
|
|
|
// Emplace empty interior ring
|
|
|
|
g.emplace_back();
|
|
|
|
|
|
|
|
mapnik::geometry::polygon_vertex_adapter<double> va(g);
|
|
|
|
double x,y;
|
|
|
|
unsigned cmd;
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
CHECK( cmd == mapnik::SEG_MOVETO );
|
|
|
|
CHECK( x == Approx(-1) );
|
|
|
|
CHECK( y == Approx(-1) );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
CHECK( cmd == mapnik::SEG_LINETO );
|
|
|
|
CHECK( x == Approx(1) );
|
|
|
|
CHECK( y == Approx(-1) );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
CHECK( cmd == mapnik::SEG_LINETO );
|
|
|
|
CHECK( x == Approx(1) );
|
|
|
|
CHECK( y == Approx(1) );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
CHECK( cmd == mapnik::SEG_LINETO );
|
|
|
|
CHECK( x == Approx(-1) );
|
|
|
|
CHECK( y == Approx(1) );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
CHECK( cmd == mapnik::SEG_CLOSE );
|
|
|
|
CHECK( x == Approx(0) );
|
|
|
|
CHECK( y == Approx(0) );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
CHECK( cmd == mapnik::SEG_CLOSE );
|
|
|
|
CHECK( x == Approx(0) );
|
|
|
|
CHECK( y == Approx(0) );
|
|
|
|
|
|
|
|
cmd = va.vertex(&x,&y);
|
|
|
|
REQUIRE( cmd == mapnik::SEG_END );
|
|
|
|
REQUIRE( x == Approx(0) );
|
|
|
|
REQUIRE( y == Approx(0) );
|
|
|
|
}
|
|
|
|
|
2015-03-28 06:16:49 +00:00
|
|
|
}
|