From 5471f519cd050e43e2fe58cf6c1fac1966dd7a2f Mon Sep 17 00:00:00 2001 From: artemp Date: Tue, 19 Jan 2016 12:15:50 +0000 Subject: [PATCH] box2d - add missing tests --- test/unit/core/box2d_test.cpp | 59 +++++++++++++++++++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/test/unit/core/box2d_test.cpp b/test/unit/core/box2d_test.cpp index 87f2e1475..14cbb48f6 100644 --- a/test/unit/core/box2d_test.cpp +++ b/test/unit/core/box2d_test.cpp @@ -2,6 +2,7 @@ #include #include +#include "agg_trans_affine.h" TEST_CASE("box2d") { SECTION("coord init") { @@ -159,4 +160,62 @@ SECTION("envelope clipping") { REQUIRE(e1 == e2); } +SECTION("mapnik::box2d intersects") +{ + mapnik::box2d b0(0,0,100,100); + // another box2d + mapnik::box2d b1(100,100,200,200); + CHECK(b0.intersects(b1)); + CHECK(b1.intersects(b0)); + mapnik::box2d b2(100.001,100,200,200); + CHECK(!b0.intersects(b2)); + CHECK(!b2.intersects(b0)); + // coord + CHECK(b0.intersects(mapnik::coord(100,100))); + CHECK(!b0.intersects(mapnik::coord(100.001,100))); +} + +SECTION("mapnik::box2d intersect") +{ + mapnik::box2d b0(0,0,100,100); + mapnik::box2d b1(100,100,200,200); + CHECK(b0.intersect(b1) == mapnik::box2d(100,100,100,100)); + CHECK(b1.intersect(b0) == mapnik::box2d(100,100,100,100)); + mapnik::box2d b2(100.001,100,200,200); + CHECK(b0.intersect(b2) == mapnik::box2d()); + CHECK(b2.intersect(b0) == mapnik::box2d()); +} + +SECTION("mapnik::box2d re_center") +{ + mapnik::box2d b(0, 0, 100, 100); + b.re_center(0, 0); + CHECK(b == mapnik::box2d(-50, -50, 50, 50)); + b.re_center(mapnik::coord2d(50,50)); + CHECK(b == mapnik::box2d(0, 0, 100, 100)); +} + +SECTION("mapnik::box2d operator+=") +{ + mapnik::box2d b(0, 0, 50, 50); + b += mapnik::box2d(100, 100, 200, 200); + CHECK(b == mapnik::box2d(0, 0, 200, 200)); + b += 100; + CHECK(b == mapnik::box2d(-100, -100, 300, 300)); +} + +SECTION("mapnik::box2d operator*= operator=/ ") +{ + mapnik::box2d b(0, 0, 100, 100); + b *= 2.0; + CHECK(b == mapnik::box2d(-50, -50, 150, 150)); + b /= 2.0; + CHECK(b == mapnik::box2d(0, 0, 100, 100)); + + agg::trans_affine tr; + tr.translate(-50,-50); + tr.scale(2.0); + b *= tr; + CHECK(b == mapnik::box2d(-100, -100, 100, 100)); +} } // TEST_CASE