diff --git a/bindings/python/mapnik_proj_transform.cpp b/bindings/python/mapnik_proj_transform.cpp index 23f55aa1b..2da9ebb43 100644 --- a/bindings/python/mapnik_proj_transform.cpp +++ b/bindings/python/mapnik_proj_transform.cpp @@ -61,26 +61,16 @@ mapnik::coord2d backward_transform_c(mapnik::proj_transform& t, mapnik::coord2d mapnik::box2d forward_transform_env(mapnik::proj_transform& t, mapnik::box2d const & box) { - double minx = box.minx(); - double miny = box.miny(); - double maxx = box.maxx(); - double maxy = box.maxy(); - double z = 0.0; - t.forward(minx,miny,z); - t.forward(maxx,maxy,z); - return mapnik::box2d(minx,miny,maxx,maxy); + mapnik::box2d new_box = box; + t.forward(new_box); + return new_box; } mapnik::box2d backward_transform_env(mapnik::proj_transform& t, mapnik::box2d const & box) { - double minx = box.minx(); - double miny = box.miny(); - double maxx = box.maxx(); - double maxy = box.maxy(); - double z = 0.0; - t.backward(minx,miny,z); - t.backward(maxx,maxy,z); - return mapnik::box2d(minx,miny,maxx,maxy); + mapnik::box2d new_box = box; + t.backward(new_box); + return new_box; } } diff --git a/include/mapnik/proj_transform.hpp b/include/mapnik/proj_transform.hpp index 78bfa3a5e..ce6920ea1 100644 --- a/include/mapnik/proj_transform.hpp +++ b/include/mapnik/proj_transform.hpp @@ -41,6 +41,8 @@ public: bool equal() const; bool forward (double& x, double& y , double& z) const; bool backward (double& x, double& y , double& z) const; + bool forward (box2d & box) const; + bool backward (box2d & box) const; mapnik::projection const& source() const; mapnik::projection const& dest() const; diff --git a/src/proj_transform.cpp b/src/proj_transform.cpp index 0783cf821..3868d6628 100644 --- a/src/proj_transform.cpp +++ b/src/proj_transform.cpp @@ -105,6 +105,37 @@ bool proj_transform::backward (double & x, double & y , double & z) const return true; } +bool proj_transform::forward (box2d & box) const +{ + if (is_source_equal_dest_) + return true; + double minx = box.minx(); + double miny = box.miny(); + double maxx = box.maxx(); + double maxy = box.maxy(); + double z = 0.0; + bool ok0 = forward(minx,miny,z); + bool ok1 = forward(maxx,maxy,z); + box.init(minx,miny,maxx,maxy); + return ok0 & ok1; +} + +bool proj_transform::backward (box2d & box) const +{ + if (is_source_equal_dest_) + return true; + + double minx = box.minx(); + double miny = box.miny(); + double maxx = box.maxx(); + double maxy = box.maxy(); + double z = 0.0; + bool ok0 = backward(minx,miny,z); + bool ok1 = backward(maxx,maxy,z); + box.init(minx,miny,maxx,maxy); + return ok0 & ok1; +} + mapnik::projection const& proj_transform::source() const { return source_;