add proj_transform forward/backward box2d implementation

This commit is contained in:
Dane Springmeyer 2011-04-13 19:40:44 +00:00
parent daf5cff723
commit 383d8a3f15
3 changed files with 39 additions and 16 deletions

View file

@ -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;
}
}

View file

@ -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<double> & box) const;
bool backward (box2d<double> & box) const;
mapnik::projection const& source() const;
mapnik::projection const& dest() const;

View file

@ -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_;