Skip to content

Commit

Permalink
add proj_transform forward/backward box2d implementation
Browse files Browse the repository at this point in the history
  • Loading branch information
Dane Springmeyer committed Apr 13, 2011
1 parent daf5cff commit 383d8a3
Show file tree
Hide file tree
Showing 3 changed files with 39 additions and 16 deletions.
22 changes: 6 additions & 16 deletions bindings/python/mapnik_proj_transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -61,26 +61,16 @@ mapnik::coord2d backward_transform_c(mapnik::proj_transform& t, mapnik::coord2d

mapnik::box2d<double> forward_transform_env(mapnik::proj_transform& t, mapnik::box2d<double> 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<double>(minx,miny,maxx,maxy);
mapnik::box2d<double> new_box = box;
t.forward(new_box);
return new_box;
}

mapnik::box2d<double> backward_transform_env(mapnik::proj_transform& t, mapnik::box2d<double> 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<double>(minx,miny,maxx,maxy);
mapnik::box2d<double> new_box = box;
t.backward(new_box);
return new_box;
}
}

Expand Down
2 changes: 2 additions & 0 deletions include/mapnik/proj_transform.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,8 @@ class MAPNIK_DECL proj_transform : private boost::noncopyable
bool equal() const;
bool forward (double& x, double& y , double& z) const;
bool backward (double& x, double& y , double& z) const;
bool forward (box2d<double> & box) const;
bool backward (box2d<double> & box) const;
mapnik::projection const& source() const;
mapnik::projection const& dest() const;

Expand Down
31 changes: 31 additions & 0 deletions src/proj_transform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -105,6 +105,37 @@ bool proj_transform::backward (double & x, double & y , double & z) const
return true;
}

bool proj_transform::forward (box2d<double> & 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<double> & 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_;
Expand Down

0 comments on commit 383d8a3

Please sign in to comment.