add a clip method to mapnik::box2d
This commit is contained in:
parent
e1b00387ca
commit
903d1b49ef
4 changed files with 51 additions and 0 deletions
|
@ -84,6 +84,9 @@ box2d<double> (box2d<double>::*intersect)(box2d<double> const&) const = &box2d<d
|
|||
void (box2d<double>::*re_center_p1)(double,double) = &box2d<double>::re_center;
|
||||
void (box2d<double>::*re_center_p2)(coord<double,2> const& ) = &box2d<double>::re_center;
|
||||
|
||||
// clip
|
||||
void (box2d<double>::*clip)(box2d<double> const&) = &box2d<double>::clip;
|
||||
|
||||
void export_envelope()
|
||||
{
|
||||
using namespace boost::python;
|
||||
|
@ -144,6 +147,20 @@ void export_envelope()
|
|||
">>> e\n"
|
||||
"Box2d(10.0, 10.0, 110.0, 110.0)\n"
|
||||
)
|
||||
.def("clip", clip,
|
||||
(arg("other")),
|
||||
"Clip the envelope based on the bounds of another envelope.\n"
|
||||
"\n "
|
||||
"Example:\n"
|
||||
">>> e = Box2d(0, 0, 100, 100)\n"
|
||||
">>> e.center(Coord60, 60)\n"
|
||||
">>> e.center()\n"
|
||||
"Coord(60.0,60.0)\n"
|
||||
">>> (e.width(), e.height())\n"
|
||||
"(100.0, 100.0)\n"
|
||||
">>> e\n"
|
||||
"Box2d(10.0, 10.0, 110.0, 110.0)\n"
|
||||
)
|
||||
.def("width", width_p1,
|
||||
(arg("new_width")),
|
||||
"Sets the width to new_width of the envelope preserving its center.\n"
|
||||
|
|
|
@ -79,6 +79,7 @@ public:
|
|||
void re_center(T cx,T cy);
|
||||
void re_center(const coord<T,2>& c);
|
||||
void init(T x0,T y0,T x1,T y1);
|
||||
void clip(const box2d_type &other);
|
||||
bool from_string(const std::string& s);
|
||||
bool valid() const;
|
||||
|
||||
|
|
|
@ -307,6 +307,19 @@ void box2d<T>::init(T x0,T y0,T x1,T y1)
|
|||
}
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
#if !defined(__SUNPRO_CC)
|
||||
inline
|
||||
#endif
|
||||
void box2d<T>::clip(const box2d_type& other)
|
||||
{
|
||||
minx_ = std::max(minx_,other.minx());
|
||||
miny_ = std::max(miny_,other.miny());
|
||||
maxx_ = std::min(maxx_,other.maxx());
|
||||
maxy_ = std::min(maxy_,other.maxy());
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
#if !defined(__SUNPRO_CC)
|
||||
inline
|
||||
|
|
|
@ -674,3 +674,23 @@ def test_envelope_multiplication():
|
|||
|
||||
eq_(c.x, 150)
|
||||
eq_(c.y, 150)
|
||||
|
||||
# Box2d clipping
|
||||
def test_envelope_pickle():
|
||||
e1 = mapnik2.Box2d(-180,-90,180,90)
|
||||
e2 = mapnik2.Box2d(-120,40,-110,48)
|
||||
e1.clip(e2)
|
||||
eq_(e1,e2)
|
||||
|
||||
# madagascar in merc
|
||||
e1 = mapnik2.Box2d(4772116.5490, -2744395.0631, 5765186.4203, -1609458.0673)
|
||||
e2 = mapnik2.Box2d(5124338.3753, -2240522.1727, 5207501.8621, -2130452.8520)
|
||||
e1.clip(e2)
|
||||
eq_(e1,e2)
|
||||
|
||||
# nz in lon/lat
|
||||
e1 = mapnik2.Box2d(163.8062, -47.1897, 179.3628, -33.9069)
|
||||
e2 = mapnik2.Box2d(173.7378, -39.6395, 174.4849, -38.9252)
|
||||
e1.clip(e2)
|
||||
eq_(e1,e2)
|
||||
|
||||
|
|
Loading…
Reference in a new issue