box2d<T> - expose value_type typedef + init(x, y) convinient method

This commit is contained in:
artemp 2016-03-24 14:50:46 +00:00
parent 2239c805e5
commit 9bb20ce685
2 changed files with 25 additions and 15 deletions

View file

@ -50,7 +50,8 @@ template <typename T> class MAPNIK_DECL box2d
boost::multipliable2<box2d<T>, T > > > > boost::multipliable2<box2d<T>, T > > > >
{ {
public: public:
using box2d_type = box2d<T>; using value_type = T;
using box2d_type = box2d<value_type>;
private: private:
T minx_; T minx_;
T miny_; T miny_;
@ -99,6 +100,7 @@ public:
void re_center(T cx,T cy); void re_center(T cx,T cy);
void re_center(coord<T,2> const& c); void re_center(coord<T,2> const& c);
void init(T x0,T y0,T x1,T y1); void init(T x0,T y0,T x1,T y1);
void init(T x, T y);
void clip(box2d_type const& other); void clip(box2d_type const& other);
void pad(T padding); void pad(T padding);
bool from_string(std::string const& str); bool from_string(std::string const& str);

View file

@ -303,22 +303,32 @@ void box2d<T>::init(T x0,T y0,T x1,T y1)
{ {
if (x0 < x1) if (x0 < x1)
{ {
minx_=x0;maxx_=x1; minx_ = x0;
maxx_ = x1;
} }
else else
{ {
minx_=x1;maxx_=x0; minx_ = x1;
maxx_ = x0;
} }
if (y0 < y1) if (y0 < y1)
{ {
miny_=y0;maxy_=y1; miny_ = y0;
maxy_ = y1;
} }
else else
{ {
miny_=y1;maxy_=y0; miny_ = y1;
maxy_ = y0;
} }
} }
template <typename T>
void box2d<T>::init(T x, T y)
{
init(x, y, x, y);
}
template <typename T> template <typename T>
void box2d<T>::clip(box2d_type const& other) void box2d<T>::clip(box2d_type const& other)
{ {
@ -337,7 +347,6 @@ void box2d<T>::pad(T padding)
maxy_ += padding; maxy_ += padding;
} }
template <typename T> template <typename T>
bool box2d<T>::from_string(std::string const& str) bool box2d<T>::from_string(std::string const& str)
{ {
@ -346,8 +355,7 @@ bool box2d<T>::from_string(std::string const& str)
boost::spirit::ascii::space_type space; boost::spirit::ascii::space_type space;
bool r = boost::spirit::qi::phrase_parse(str.begin(), bool r = boost::spirit::qi::phrase_parse(str.begin(),
str.end(), str.end(),
double_ >> -lit(',') >> double_ >> -lit(',') double_ >> -lit(',') >> double_ >> -lit(',') >> double_ >> -lit(',') >> double_,
>> double_ >> -lit(',') >> double_,
space, space,
*this); *this);
return r; return r;