From 3e24c5a4173033bca1439d0e8275a753106068c4 Mon Sep 17 00:00:00 2001 From: Blake Thompson Date: Fri, 15 May 2015 13:21:51 -0500 Subject: [PATCH] Doh, fixing stupid C++ that I wrote after properly writing a unit test --- src/proj_transform.cpp | 49 +++++++++++++++------- test/unit/imaging/image_multiply_alpha.cpp | 7 +++- test/unit/projection/proj_transform.cpp | 38 +++++++++++++++++ 3 files changed, 77 insertions(+), 17 deletions(-) create mode 100644 test/unit/projection/proj_transform.cpp diff --git a/src/proj_transform.cpp b/src/proj_transform.cpp index 06fc7f2af..b2cb37de9 100644 --- a/src/proj_transform.cpp +++ b/src/proj_transform.cpp @@ -264,10 +264,14 @@ bool proj_transform::forward (box2d & box) const if (is_source_equal_dest_) return true; - double llx, ulx = box.minx(); - double lly, lry = box.miny(); - double lrx, urx = box.maxx(); - double uly, ury = box.maxy(); + double llx = box.minx(); + double ulx = box.minx(); + double lly = box.miny(); + double lry = box.miny(); + double lrx = box.maxx(); + double urx = box.maxx(); + double uly = box.maxy(); + double ury = box.maxy(); double z = 0.0; if (!forward(llx,lly,z)) return false; @@ -277,10 +281,15 @@ bool proj_transform::forward (box2d & box) const return false; if (!forward(urx,ury,z)) return false; - box.init(std::min(ulx, llx), - std::min(lly, lry), - std::max(urx, lrx), - std::max(uly, ury)); + + double minx = std::min(ulx, llx); + double miny = std::min(lly, lry); + double maxx = std::max(urx, lrx); + double maxy = std::max(ury, uly); + box.init(minx, + miny, + maxx, + maxy); return true; } @@ -289,10 +298,14 @@ bool proj_transform::backward (box2d & box) const if (is_source_equal_dest_) return true; - double llx, ulx = box.minx(); - double lly, lry = box.miny(); - double lrx, urx = box.maxx(); - double uly, ury = box.maxy(); + double llx = box.minx(); + double ulx = box.minx(); + double lly = box.miny(); + double lry = box.miny(); + double lrx = box.maxx(); + double urx = box.maxx(); + double uly = box.maxy(); + double ury = box.maxy(); double z = 0.0; if (!backward(llx,lly,z)) return false; @@ -302,10 +315,14 @@ bool proj_transform::backward (box2d & box) const return false; if (!backward(urx,ury,z)) return false; - box.init(std::min(ulx, llx), - std::min(lly, lry), - std::max(urx, lrx), - std::max(uly, ury)); + double minx = std::min(ulx, llx); + double miny = std::min(lly, lry); + double maxx = std::max(urx, lrx); + double maxy = std::max(ury, uly); + box.init(minx, + miny, + maxx, + maxy); return true; } diff --git a/test/unit/imaging/image_multiply_alpha.cpp b/test/unit/imaging/image_multiply_alpha.cpp index 5637078f8..20bee304a 100644 --- a/test/unit/imaging/image_multiply_alpha.cpp +++ b/test/unit/imaging/image_multiply_alpha.cpp @@ -58,10 +58,15 @@ SECTION("test rgba8 overflow") { mapnik::image_rgba8 im(4,4); mapnik::color c(128,128,128,128); // This color is premultiplied mapnik::fill(im, c); // Because c1 is not premultiplied it will make the image not premultiplied + mapnik::color out; + out = mapnik::get_pixel(im, 0, 0); + CHECK(static_cast(out.red()) == 128); + CHECK(static_cast(out.green()) == 128); + CHECK(static_cast(out.blue()) == 128); + CHECK(static_cast(out.alpha()) == 128); mapnik::multiply_alpha(im, 2.5); - mapnik::color out; out = mapnik::get_pixel(im, 0, 0); CHECK(static_cast(out.red()) == 128); CHECK(static_cast(out.green()) == 128); diff --git a/test/unit/projection/proj_transform.cpp b/test/unit/projection/proj_transform.cpp new file mode 100644 index 000000000..618b57de5 --- /dev/null +++ b/test/unit/projection/proj_transform.cpp @@ -0,0 +1,38 @@ +#include "catch.hpp" + +#include +#include +#include + +TEST_CASE("projection transform") +{ + +SECTION("Test bounding box transforms - 4326 to 3857") +{ + mapnik::projection proj_4326("+init=epsg:4326"); + mapnik::projection proj_3857("+init=epsg:3857"); + mapnik::proj_transform prj_trans(proj_4326, proj_3857); + + double minx = -45.0; + double miny = 55.0; + double maxx = -40.0; + double maxy = 75.0; + + mapnik::box2d bbox(minx, miny, maxx, maxy); + + prj_trans.forward(bbox); + INFO(bbox.to_string()); + CHECK(bbox.minx() == Approx(-5009377.085697311)); + CHECK(bbox.miny() == Approx(7361866.1130511891)); + CHECK(bbox.maxx() == Approx(-4452779.631730943)); + CHECK(bbox.maxy() == Approx(12932243.1119920239)); + + prj_trans.backward(bbox); + CHECK(bbox.minx() == Approx(minx)); + CHECK(bbox.miny() == Approx(miny)); + CHECK(bbox.maxx() == Approx(maxx)); + CHECK(bbox.maxy() == Approx(maxy)); + +} // END SECTION + +} // END TEST CASE