2015-04-04 01:56:57 +02:00
|
|
|
#include "catch.hpp"
|
|
|
|
|
2015-05-06 07:04:49 +02:00
|
|
|
#include <mapnik/config.hpp>
|
2015-04-04 01:56:57 +02:00
|
|
|
#include <mapnik/geometry.hpp>
|
2015-05-06 07:04:49 +02:00
|
|
|
#include <mapnik/geometry_adapters.hpp>
|
2015-04-04 01:56:57 +02:00
|
|
|
#include <mapnik/geometry_envelope.hpp>
|
|
|
|
#include <mapnik/geometry_correct.hpp>
|
|
|
|
|
|
|
|
TEST_CASE("geometry ops - envelope") {
|
|
|
|
|
2015-04-09 22:22:51 +02:00
|
|
|
SECTION("envelope_test - double") {
|
2015-04-04 01:56:57 +02:00
|
|
|
using namespace mapnik::geometry;
|
|
|
|
{
|
2015-04-09 22:22:51 +02:00
|
|
|
geometry<double> geom(point<double>(1,2));
|
2015-04-04 01:56:57 +02:00
|
|
|
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
|
|
|
|
REQUIRE( bbox.minx() == 1 );
|
|
|
|
REQUIRE( bbox.miny() == 2 );
|
|
|
|
REQUIRE( bbox.maxx() == 1 );
|
|
|
|
REQUIRE( bbox.maxy() == 2 );
|
|
|
|
}
|
|
|
|
{
|
|
|
|
// Test empty geom
|
2015-06-02 15:48:02 +02:00
|
|
|
geometry<double> geom = mapnik::geometry::geometry_empty();
|
2015-04-04 19:24:00 +02:00
|
|
|
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
|
|
|
|
REQUIRE_FALSE( bbox.valid() );
|
2015-04-04 01:56:57 +02:00
|
|
|
}
|
|
|
|
{
|
2015-04-09 22:22:51 +02:00
|
|
|
line_string<double> line;
|
2015-04-04 01:56:57 +02:00
|
|
|
line.add_coord(0,0);
|
|
|
|
line.add_coord(1,1);
|
|
|
|
line.add_coord(2,2);
|
2015-04-09 22:22:51 +02:00
|
|
|
geometry<double> geom(line);
|
2015-04-04 01:56:57 +02:00
|
|
|
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
|
|
|
|
REQUIRE( bbox.minx() == 0 );
|
|
|
|
REQUIRE( bbox.miny() == 0 );
|
|
|
|
REQUIRE( bbox.maxx() == 2 );
|
|
|
|
REQUIRE( bbox.maxy() == 2 );
|
|
|
|
}
|
|
|
|
{
|
2015-04-09 22:22:51 +02:00
|
|
|
line_string<double> line;
|
2015-04-04 01:56:57 +02:00
|
|
|
line.add_coord(0,0);
|
|
|
|
line.add_coord(1,1);
|
|
|
|
line.add_coord(2,2);
|
2015-04-09 22:22:51 +02:00
|
|
|
line_string<double> line2;
|
2015-04-04 01:56:57 +02:00
|
|
|
line2.add_coord(0,0);
|
|
|
|
line2.add_coord(-1,-1);
|
|
|
|
line2.add_coord(-2,-2);
|
2015-04-09 22:22:51 +02:00
|
|
|
multi_line_string<double> multi_line;
|
2015-04-04 01:56:57 +02:00
|
|
|
multi_line.emplace_back(std::move(line));
|
|
|
|
multi_line.emplace_back(std::move(line2));
|
2015-04-09 22:22:51 +02:00
|
|
|
geometry<double> geom(multi_line);
|
2015-04-04 01:56:57 +02:00
|
|
|
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
|
|
|
|
REQUIRE( bbox.minx() == -2 );
|
|
|
|
REQUIRE( bbox.miny() == -2 );
|
|
|
|
REQUIRE( bbox.maxx() == 2 );
|
|
|
|
REQUIRE( bbox.maxy() == 2 );
|
|
|
|
}
|
|
|
|
{
|
2015-04-09 22:22:51 +02:00
|
|
|
polygon<double> poly;
|
|
|
|
linear_ring<double> ring;
|
2015-04-04 01:56:57 +02:00
|
|
|
ring.add_coord(0,0);
|
|
|
|
ring.add_coord(-10,0);
|
|
|
|
ring.add_coord(-10,10);
|
|
|
|
ring.add_coord(0,10);
|
|
|
|
ring.add_coord(0,0);
|
|
|
|
poly.set_exterior_ring(std::move(ring));
|
2015-04-09 22:22:51 +02:00
|
|
|
geometry<double> geom(poly);
|
2015-04-04 01:56:57 +02:00
|
|
|
mapnik::box2d<double> bbox = mapnik::geometry::envelope(geom);
|
|
|
|
REQUIRE( bbox.minx() == -10 );
|
|
|
|
REQUIRE( bbox.miny() == 0 );
|
|
|
|
REQUIRE( bbox.maxx() == 0 );
|
|
|
|
REQUIRE( bbox.maxy() == 10 );
|
|
|
|
|
2015-04-09 22:22:51 +02:00
|
|
|
multi_polygon<double> mp;
|
2015-04-04 01:56:57 +02:00
|
|
|
mp.push_back(poly);
|
2015-04-09 22:22:51 +02:00
|
|
|
geometry<double> geom_mp(mp);
|
2015-04-04 01:56:57 +02:00
|
|
|
bbox = mapnik::geometry::envelope(geom_mp);
|
|
|
|
REQUIRE( bbox.minx() == -10 );
|
|
|
|
REQUIRE( bbox.miny() == 0 );
|
|
|
|
REQUIRE( bbox.maxx() == 0 );
|
|
|
|
REQUIRE( bbox.maxy() == 10 );
|
|
|
|
|
|
|
|
correct(geom);
|
|
|
|
bbox = mapnik::geometry::envelope(geom);
|
|
|
|
REQUIRE( bbox.minx() == -10 );
|
|
|
|
REQUIRE( bbox.miny() == 0 );
|
|
|
|
REQUIRE( bbox.maxx() == 0 );
|
|
|
|
REQUIRE( bbox.maxy() == 10 );
|
|
|
|
correct(geom_mp);
|
|
|
|
bbox = mapnik::geometry::envelope(geom_mp);
|
|
|
|
REQUIRE( bbox.minx() == -10 );
|
|
|
|
REQUIRE( bbox.miny() == 0 );
|
|
|
|
REQUIRE( bbox.maxx() == 0 );
|
|
|
|
REQUIRE( bbox.maxy() == 10 );
|
|
|
|
|
2015-04-09 22:22:51 +02:00
|
|
|
geometry_collection<double> gc;
|
2015-04-04 01:56:57 +02:00
|
|
|
bbox = mapnik::geometry::envelope(gc);
|
|
|
|
REQUIRE_FALSE( bbox.valid() );
|
|
|
|
gc.push_back(geom_mp);
|
|
|
|
bbox = mapnik::geometry::envelope(gc);
|
|
|
|
REQUIRE( bbox.minx() == -10 );
|
|
|
|
REQUIRE( bbox.miny() == 0 );
|
|
|
|
REQUIRE( bbox.maxx() == 0 );
|
|
|
|
REQUIRE( bbox.maxy() == 10 );
|
2015-04-09 22:22:51 +02:00
|
|
|
gc.emplace_back(point<double>(-50,-50));
|
2015-04-04 01:56:57 +02:00
|
|
|
bbox = mapnik::geometry::envelope(gc);
|
|
|
|
REQUIRE( bbox.minx() == -50 );
|
|
|
|
REQUIRE( bbox.miny() == -50 );
|
|
|
|
REQUIRE( bbox.maxx() == 0 );
|
|
|
|
REQUIRE( bbox.maxy() == 10 );
|
|
|
|
}
|
|
|
|
|
|
|
|
{
|
|
|
|
// polygon with hole
|
2015-04-09 22:22:51 +02:00
|
|
|
polygon<double> poly;
|
|
|
|
linear_ring<double> ring;
|
2015-04-04 01:56:57 +02:00
|
|
|
ring.add_coord(0,0);
|
|
|
|
ring.add_coord(-10,0);
|
|
|
|
ring.add_coord(-10,10);
|
|
|
|
ring.add_coord(0,10);
|
|
|
|
ring.add_coord(0,0);
|
|
|
|
poly.set_exterior_ring(std::move(ring));
|
2015-04-09 22:22:51 +02:00
|
|
|
linear_ring<double> hole;
|
2015-04-04 01:56:57 +02:00
|
|
|
hole.add_coord(-7,7);
|
|
|
|
hole.add_coord(-7,3);
|
|
|
|
hole.add_coord(-3,3);
|
|
|
|
hole.add_coord(-3,7);
|
|
|
|
hole.add_coord(-7,7);
|
|
|
|
poly.add_hole(std::move(hole));
|
2015-04-09 22:22:51 +02:00
|
|
|
geometry<double> geom(poly);
|
2015-04-04 01:56:57 +02:00
|
|
|
mapnik::box2d<double> bbox = mapnik::geometry::envelope(poly);
|
|
|
|
REQUIRE( bbox.minx() == -10 );
|
|
|
|
REQUIRE( bbox.miny() == 0 );
|
|
|
|
REQUIRE( bbox.maxx() == 0 );
|
|
|
|
REQUIRE( bbox.maxy() == 10 );
|
|
|
|
// add another hole inside the first hole
|
|
|
|
// which should be considered a hit
|
2015-04-09 22:22:51 +02:00
|
|
|
linear_ring<double> fill;
|
2015-04-04 01:56:57 +02:00
|
|
|
fill.add_coord(-6,4);
|
|
|
|
fill.add_coord(-6,6);
|
|
|
|
fill.add_coord(-4,6);
|
|
|
|
fill.add_coord(-4,4);
|
|
|
|
fill.add_coord(-6,4);
|
|
|
|
poly.add_hole(std::move(fill));
|
|
|
|
bbox = mapnik::geometry::envelope(poly);
|
|
|
|
REQUIRE( bbox.minx() == -10 );
|
|
|
|
REQUIRE( bbox.miny() == 0 );
|
|
|
|
REQUIRE( bbox.maxx() == 0 );
|
|
|
|
REQUIRE( bbox.maxy() == 10 );
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|