box2d<T> - expose value_type typedef + init(x, y) convinient method
This commit is contained in:
parent
2239c805e5
commit
9bb20ce685
2 changed files with 25 additions and 15 deletions
|
@ -50,7 +50,8 @@ template <typename T> class MAPNIK_DECL box2d
|
|||
boost::multipliable2<box2d<T>, T > > > >
|
||||
{
|
||||
public:
|
||||
using box2d_type = box2d<T>;
|
||||
using value_type = T;
|
||||
using box2d_type = box2d<value_type>;
|
||||
private:
|
||||
T minx_;
|
||||
T miny_;
|
||||
|
@ -99,6 +100,7 @@ public:
|
|||
void re_center(T cx,T cy);
|
||||
void re_center(coord<T,2> const& c);
|
||||
void init(T x0,T y0,T x1,T y1);
|
||||
void init(T x, T y);
|
||||
void clip(box2d_type const& other);
|
||||
void pad(T padding);
|
||||
bool from_string(std::string const& str);
|
||||
|
|
|
@ -299,33 +299,43 @@ void box2d<T>::re_center(coord<T,2> const& c)
|
|||
}
|
||||
|
||||
template <typename T>
|
||||
void box2d<T>::init(T x0,T y0,T x1,T y1)
|
||||
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
|
||||
{
|
||||
minx_=x1;maxx_=x0;
|
||||
minx_ = x1;
|
||||
maxx_ = x0;
|
||||
}
|
||||
if (y0<y1)
|
||||
if (y0 < y1)
|
||||
{
|
||||
miny_=y0;maxy_=y1;
|
||||
miny_ = y0;
|
||||
maxy_ = y1;
|
||||
}
|
||||
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>
|
||||
void box2d<T>::clip(box2d_type const& 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());
|
||||
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>
|
||||
|
@ -337,7 +347,6 @@ void box2d<T>::pad(T padding)
|
|||
maxy_ += padding;
|
||||
}
|
||||
|
||||
|
||||
template <typename T>
|
||||
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;
|
||||
bool r = boost::spirit::qi::phrase_parse(str.begin(),
|
||||
str.end(),
|
||||
double_ >> -lit(',') >> double_ >> -lit(',')
|
||||
>> double_ >> -lit(',') >> double_,
|
||||
double_ >> -lit(',') >> double_ >> -lit(',') >> double_ >> -lit(',') >> double_,
|
||||
space,
|
||||
*this);
|
||||
return r;
|
||||
|
|
Loading…
Reference in a new issue