Doh, fixing stupid C++ that I wrote after properly writing a unit test
This commit is contained in:
parent
90de0d65cb
commit
3e24c5a417
3 changed files with 77 additions and 17 deletions
|
@ -264,10 +264,14 @@ bool proj_transform::forward (box2d<double> & box) const
|
||||||
if (is_source_equal_dest_)
|
if (is_source_equal_dest_)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
double llx, ulx = box.minx();
|
double llx = box.minx();
|
||||||
double lly, lry = box.miny();
|
double ulx = box.minx();
|
||||||
double lrx, urx = box.maxx();
|
double lly = box.miny();
|
||||||
double uly, ury = box.maxy();
|
double lry = box.miny();
|
||||||
|
double lrx = box.maxx();
|
||||||
|
double urx = box.maxx();
|
||||||
|
double uly = box.maxy();
|
||||||
|
double ury = box.maxy();
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
if (!forward(llx,lly,z))
|
if (!forward(llx,lly,z))
|
||||||
return false;
|
return false;
|
||||||
|
@ -277,10 +281,15 @@ bool proj_transform::forward (box2d<double> & box) const
|
||||||
return false;
|
return false;
|
||||||
if (!forward(urx,ury,z))
|
if (!forward(urx,ury,z))
|
||||||
return false;
|
return false;
|
||||||
box.init(std::min(ulx, llx),
|
|
||||||
std::min(lly, lry),
|
double minx = std::min(ulx, llx);
|
||||||
std::max(urx, lrx),
|
double miny = std::min(lly, lry);
|
||||||
std::max(uly, ury));
|
double maxx = std::max(urx, lrx);
|
||||||
|
double maxy = std::max(ury, uly);
|
||||||
|
box.init(minx,
|
||||||
|
miny,
|
||||||
|
maxx,
|
||||||
|
maxy);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -289,10 +298,14 @@ bool proj_transform::backward (box2d<double> & box) const
|
||||||
if (is_source_equal_dest_)
|
if (is_source_equal_dest_)
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
double llx, ulx = box.minx();
|
double llx = box.minx();
|
||||||
double lly, lry = box.miny();
|
double ulx = box.minx();
|
||||||
double lrx, urx = box.maxx();
|
double lly = box.miny();
|
||||||
double uly, ury = box.maxy();
|
double lry = box.miny();
|
||||||
|
double lrx = box.maxx();
|
||||||
|
double urx = box.maxx();
|
||||||
|
double uly = box.maxy();
|
||||||
|
double ury = box.maxy();
|
||||||
double z = 0.0;
|
double z = 0.0;
|
||||||
if (!backward(llx,lly,z))
|
if (!backward(llx,lly,z))
|
||||||
return false;
|
return false;
|
||||||
|
@ -302,10 +315,14 @@ bool proj_transform::backward (box2d<double> & box) const
|
||||||
return false;
|
return false;
|
||||||
if (!backward(urx,ury,z))
|
if (!backward(urx,ury,z))
|
||||||
return false;
|
return false;
|
||||||
box.init(std::min(ulx, llx),
|
double minx = std::min(ulx, llx);
|
||||||
std::min(lly, lry),
|
double miny = std::min(lly, lry);
|
||||||
std::max(urx, lrx),
|
double maxx = std::max(urx, lrx);
|
||||||
std::max(uly, ury));
|
double maxy = std::max(ury, uly);
|
||||||
|
box.init(minx,
|
||||||
|
miny,
|
||||||
|
maxx,
|
||||||
|
maxy);
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -58,10 +58,15 @@ SECTION("test rgba8 overflow") {
|
||||||
mapnik::image_rgba8 im(4,4);
|
mapnik::image_rgba8 im(4,4);
|
||||||
mapnik::color c(128,128,128,128); // This color is premultiplied
|
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::fill(im, c); // Because c1 is not premultiplied it will make the image not premultiplied
|
||||||
|
mapnik::color out;
|
||||||
|
out = mapnik::get_pixel<mapnik::color>(im, 0, 0);
|
||||||
|
CHECK(static_cast<int>(out.red()) == 128);
|
||||||
|
CHECK(static_cast<int>(out.green()) == 128);
|
||||||
|
CHECK(static_cast<int>(out.blue()) == 128);
|
||||||
|
CHECK(static_cast<int>(out.alpha()) == 128);
|
||||||
|
|
||||||
mapnik::multiply_alpha(im, 2.5);
|
mapnik::multiply_alpha(im, 2.5);
|
||||||
|
|
||||||
mapnik::color out;
|
|
||||||
out = mapnik::get_pixel<mapnik::color>(im, 0, 0);
|
out = mapnik::get_pixel<mapnik::color>(im, 0, 0);
|
||||||
CHECK(static_cast<int>(out.red()) == 128);
|
CHECK(static_cast<int>(out.red()) == 128);
|
||||||
CHECK(static_cast<int>(out.green()) == 128);
|
CHECK(static_cast<int>(out.green()) == 128);
|
||||||
|
|
38
test/unit/projection/proj_transform.cpp
Normal file
38
test/unit/projection/proj_transform.cpp
Normal file
|
@ -0,0 +1,38 @@
|
||||||
|
#include "catch.hpp"
|
||||||
|
|
||||||
|
#include <mapnik/projection.hpp>
|
||||||
|
#include <mapnik/proj_transform.hpp>
|
||||||
|
#include <mapnik/box2d.hpp>
|
||||||
|
|
||||||
|
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<double> 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
|
Loading…
Reference in a new issue