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 > > > >
|
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);
|
||||||
|
|
|
@ -299,33 +299,43 @@ void box2d<T>::re_center(coord<T,2> const& c)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
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
|
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)
|
||||||
{
|
{
|
||||||
minx_ = std::max(minx_,other.minx());
|
minx_ = std::max(minx_, other.minx());
|
||||||
miny_ = std::max(miny_,other.miny());
|
miny_ = std::max(miny_, other.miny());
|
||||||
maxx_ = std::min(maxx_,other.maxx());
|
maxx_ = std::min(maxx_, other.maxx());
|
||||||
maxy_ = std::min(maxy_,other.maxy());
|
maxy_ = std::min(maxy_, other.maxy());
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -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;
|
||||||
|
|
Loading…
Reference in a new issue