2015-03-22 18:41:44 +00:00
|
|
|
#include "catch.hpp"
|
|
|
|
|
2015-03-24 12:32:05 +00:00
|
|
|
#include <mapnik/geometry.hpp>
|
2015-03-22 18:41:44 +00:00
|
|
|
#include <mapnik/hit_test_filter.hpp>
|
2017-03-27 15:14:51 +00:00
|
|
|
#include <mapnik/geometry/correct.hpp>
|
2015-03-22 18:41:44 +00:00
|
|
|
|
|
|
|
TEST_CASE("geometry ops") {
|
|
|
|
|
2015-04-09 20:22:51 +00:00
|
|
|
SECTION("hit_test_filter - double") {
|
2015-03-24 13:21:28 +00:00
|
|
|
using namespace mapnik::geometry;
|
2015-03-22 18:41:44 +00:00
|
|
|
{
|
2015-04-09 20:22:51 +00:00
|
|
|
geometry<double> geom(point<double>(0,0));
|
2015-03-24 12:32:05 +00:00
|
|
|
REQUIRE( mapnik::hit_test(geom,0,0,0) );
|
2015-03-22 18:41:44 +00:00
|
|
|
}
|
|
|
|
{
|
2015-04-09 20:22:51 +00:00
|
|
|
geometry<double> geom(point<double>(0,0));
|
2015-03-24 12:32:05 +00:00
|
|
|
REQUIRE( mapnik::hit_test(geom,1,0,1) );
|
2015-03-22 18:41:44 +00:00
|
|
|
}
|
|
|
|
{
|
2015-04-09 20:22:51 +00:00
|
|
|
geometry<double> geom(point<double>(0,0));
|
2015-03-24 12:32:05 +00:00
|
|
|
REQUIRE( mapnik::hit_test(geom,0,1,1) );
|
2015-03-22 18:41:44 +00:00
|
|
|
}
|
|
|
|
{
|
2015-04-09 20:22:51 +00:00
|
|
|
geometry<double> geom(point<double>(0,0));
|
2015-03-24 12:32:05 +00:00
|
|
|
REQUIRE( mapnik::hit_test(geom,1,1,1.5) );
|
2015-03-22 18:41:44 +00:00
|
|
|
}
|
|
|
|
{
|
2015-04-09 20:22:51 +00:00
|
|
|
line_string<double> line;
|
2016-06-27 09:23:13 +00:00
|
|
|
line.emplace_back(0,0);
|
|
|
|
line.emplace_back(1,1);
|
|
|
|
line.emplace_back(2,2);
|
2015-04-09 20:22:51 +00:00
|
|
|
geometry<double> geom(line);
|
2015-03-24 12:32:05 +00:00
|
|
|
REQUIRE( mapnik::hit_test(geom,0,0,1.5) );
|
2015-03-22 18:41:44 +00:00
|
|
|
}
|
|
|
|
{
|
2015-04-09 20:22:51 +00:00
|
|
|
line_string<double> line;
|
2016-06-27 09:23:13 +00:00
|
|
|
line.emplace_back(0,0);
|
|
|
|
line.emplace_back(1,1);
|
|
|
|
line.emplace_back(2,2);
|
2015-04-09 20:22:51 +00:00
|
|
|
multi_line_string<double> multi_line;
|
2015-03-22 18:41:44 +00:00
|
|
|
multi_line.emplace_back(std::move(line));
|
2015-04-09 20:22:51 +00:00
|
|
|
geometry<double> geom(multi_line);
|
2015-03-24 12:32:05 +00:00
|
|
|
REQUIRE( mapnik::hit_test(geom,0,0,1.5) );
|
2015-03-22 18:41:44 +00:00
|
|
|
}
|
|
|
|
{
|
2015-04-09 20:22:51 +00:00
|
|
|
polygon<double> poly;
|
|
|
|
linear_ring<double> ring;
|
2016-06-27 09:23:13 +00:00
|
|
|
ring.emplace_back(0,0);
|
|
|
|
ring.emplace_back(-10,0);
|
|
|
|
ring.emplace_back(-10,10);
|
|
|
|
ring.emplace_back(0,10);
|
|
|
|
ring.emplace_back(0,0);
|
2016-06-29 11:37:32 +00:00
|
|
|
poly.push_back(std::move(ring));
|
2015-04-09 20:22:51 +00:00
|
|
|
geometry<double> geom(poly);
|
2015-03-22 18:41:44 +00:00
|
|
|
REQUIRE( mapnik::hit_test(geom,-5,5,0) );
|
|
|
|
|
2015-04-09 20:22:51 +00:00
|
|
|
multi_polygon<double> mp;
|
2015-03-22 18:41:44 +00:00
|
|
|
mp.push_back(poly);
|
2015-04-09 20:22:51 +00:00
|
|
|
geometry<double> geom_mp(mp);
|
2015-03-22 18:41:44 +00:00
|
|
|
REQUIRE( mapnik::hit_test(geom_mp,-5,5,0) );
|
|
|
|
|
|
|
|
correct(geom);
|
|
|
|
REQUIRE( mapnik::hit_test(geom,-5,5,0) );
|
|
|
|
correct(geom_mp);
|
|
|
|
REQUIRE( mapnik::hit_test(geom_mp,-5,5,0) );
|
|
|
|
|
2015-04-09 20:22:51 +00:00
|
|
|
geometry_collection<double> gc;
|
|
|
|
REQUIRE( !mapnik::hit_test(geometry<double>(gc),-5,5,0) );
|
2015-03-22 18:41:44 +00:00
|
|
|
gc.push_back(geom_mp);
|
2015-04-09 20:22:51 +00:00
|
|
|
REQUIRE( mapnik::hit_test(geometry<double>(gc),-5,5,0) );
|
|
|
|
REQUIRE( !mapnik::hit_test(geometry<double>(gc),-50,-50,0) );
|
|
|
|
gc.emplace_back(point<double>(-50,-50));
|
|
|
|
REQUIRE( mapnik::hit_test(geometry<double>(gc),-50,-50,0) );
|
2015-03-22 18:41:44 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// polygon with hole
|
2015-04-09 20:22:51 +00:00
|
|
|
polygon<double> poly;
|
|
|
|
linear_ring<double> ring;
|
2016-06-27 09:23:13 +00:00
|
|
|
ring.emplace_back(0,0);
|
|
|
|
ring.emplace_back(-10,0);
|
|
|
|
ring.emplace_back(-10,10);
|
|
|
|
ring.emplace_back(0,10);
|
|
|
|
ring.emplace_back(0,0);
|
2016-06-29 11:37:32 +00:00
|
|
|
poly.push_back(std::move(ring));
|
2015-04-09 20:22:51 +00:00
|
|
|
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
|
|
|
poly.push_back(std::move(hole));
|
2015-04-09 20:22:51 +00:00
|
|
|
geometry<double> geom(poly);
|
2015-03-22 18:41:44 +00:00
|
|
|
REQUIRE( !mapnik::hit_test(geom,-5,5,0) );
|
|
|
|
// add another hole inside the first hole
|
|
|
|
// which should be considered a hit
|
2015-04-09 20:22:51 +00:00
|
|
|
linear_ring<double> fill;
|
2016-06-27 09:23:13 +00:00
|
|
|
fill.emplace_back(-6,4);
|
|
|
|
fill.emplace_back(-6,6);
|
|
|
|
fill.emplace_back(-4,6);
|
|
|
|
fill.emplace_back(-4,4);
|
|
|
|
fill.emplace_back(-6,4);
|
2016-06-29 11:37:32 +00:00
|
|
|
poly.push_back(std::move(fill));
|
2015-04-09 20:22:51 +00:00
|
|
|
REQUIRE( mapnik::hit_test(geometry<double>(poly),-5,5,0) );
|
2015-03-22 18:41:44 +00:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|