#include "catch.hpp" #include "geometry_equal.hpp" #include #include #include #include #include #include #include #include TEST_CASE("geometry strategy tests") { SECTION("proj and view strategy") { using namespace mapnik::geometry; mapnik::box2d e(-20037508.342789,-20037508.342789,20037508.342789,20037508.342789); mapnik::view_transform vt(256, 256, e); mapnik::view_strategy vs(vt); mapnik::unview_strategy uvs(vt); mapnik::projection source("+init=epsg:4326"); mapnik::projection dest("+init=epsg:3857"); mapnik::proj_transform proj_trans(source, dest); mapnik::proj_transform proj_trans_rev(dest, source); mapnik::proj_strategy ps(proj_trans); mapnik::proj_strategy ps_rev(proj_trans_rev); { // Test first that proj strategy works properly point p1(-97.553098,35.523105); point r1(-1.08596e+07, 4.2352e+06); point p3 = transform(p1, ps); assert_g_equal(r1, p3); } { // Test next that view_strategy works point p1(-1.08596e+07, 4.2352e+06); point r1(58.6287 , 100.945); point p3 = transform(p1, vs); assert_g_equal(r1, p3); } { // Test next that view_strategy works as single process in strategy group point p1(-1.08596e+07, 4.2352e+06); point r1(58.6287 , 100.945); using sg_type = strategy_group; sg_type sg(vs); point p3 = transform(p1, sg); assert_g_equal(r1, p3); } { // Test that both work grouped together in strategy group using sg_type = strategy_group; sg_type sg(ps, vs); point p1(-97.553098,35.523105); point r1(58.6287 , 100.945); point p3 = transform(p1, sg); assert_g_equal(r1, p3); } { // Test that both work grouped together passing in geometry using sg_type = strategy_group; sg_type sg(ps, vs); geometry p1(point(-97.553098,35.523105)); point r1(58.6287 , 100.945); geometry p2 = transform(p1, sg); REQUIRE(p2.is >()); point p3 = mapnik::util::get >(p2); assert_g_equal(r1, p3); } { // Test that it works pulling back int using sg_type = strategy_group; sg_type sg(ps, vs); geometry p1(point(-97.553098,35.523105)); point r1(58 , 100); geometry p2 = transform(p1, sg); REQUIRE(p2.is >()); point p3 = mapnik::util::get >(p2); assert_g_equal(r1, p3); } { // Test with scaling as well. This would be like projection from 4326 to a vector tile. mapnik::geometry::scale_rounding_strategy ss(16); using sg_type = strategy_group; sg_type sg(ps, vs, ss); geometry p1(point(-97.553098,35.523105)); point r1(938 , 1615); geometry p2 = transform(p1, sg); REQUIRE(p2.is >()); point p3 = mapnik::util::get >(p2); assert_g_equal(r1, p3); } { // Test the entire process in reverse! This would be like converting a vector tile coordinate to 4326. mapnik::geometry::scale_strategy ss(1.0/16.0); using sg_type = strategy_group_first; sg_type sg(ss, uvs, ps_rev); geometry p1(point(938 , 1615)); point r1(-97.5586 , 35.5322); geometry p2 = transform(p1, sg); REQUIRE(p2.is >()); point p3 = mapnik::util::get >(p2); assert_g_equal(r1, p3); } { // Test with scaling + offset as well. This would be like projection from 4326 to a vector tile. mapnik::geometry::scale_rounding_strategy ss(16, 20); using sg_type = strategy_group; sg_type sg(ps, vs, ss); geometry p1(point(-97.553098,35.523105)); point r1(958 , 1635); geometry p2 = transform(p1, sg); REQUIRE(p2.is >()); point p3 = mapnik::util::get >(p2); assert_g_equal(r1, p3); } { // Test the entire scaling plus offset in reverse process in reverse! This would be like converting a vector tile coordinate to 4326. mapnik::geometry::scale_strategy ss(1.0/16.0, -20.0/16.0); using sg_type = strategy_group_first; sg_type sg(ss, uvs, ps_rev); geometry p1(point(958 , 1635)); point r1(-97.5586 , 35.5322); geometry p2 = transform(p1, sg); REQUIRE(p2.is >()); point p3 = mapnik::util::get >(p2); assert_g_equal(r1, p3); } } // END SECTION SECTION("scaling strategies - double to double") { using namespace mapnik::geometry; { scale_strategy ss(10.0); point p(-90.3, 35.5); point r(-903.0, 355.0); point o = transform(p, ss); assert_g_equal(r, o); } { scale_strategy ss(0.5, -2.0); point p(-90.3, 35.5); point r(-47.15, 15.75); point o = transform(p, ss); assert_g_equal(r, o); } { scale_rounding_strategy ss(0.5, -2.0); point p(-90.3, 35.5); point r(-47.0, 16.0); point o = transform(p, ss); assert_g_equal(r, o); } } // END SECTION SECTION("scaling strategies - double to int64") { using namespace mapnik::geometry; { scale_strategy ss(10.0); point p(-90.31, 35.58); point r(-903, 355); point o = transform(p, ss); assert_g_equal(r, o); } { scale_strategy ss(0.5, -2.0); point p(-90.3, 35.5); point r(-47, 15); point o = transform(p, ss); assert_g_equal(r, o); } { scale_rounding_strategy ss(0.5, -2.0); point p(-90.3, 35.5); point r(-47, 16); point o = transform(p, ss); assert_g_equal(r, o); } } // END SECTION } // END TEST CASE