remove coord<T, int>
usage from box2d<T>
This commit is contained in:
parent
b17dae8381
commit
b669115b2c
22 changed files with 148 additions and 164 deletions
|
@ -25,7 +25,7 @@
|
||||||
|
|
||||||
// mapnik
|
// mapnik
|
||||||
#include <mapnik/config.hpp>
|
#include <mapnik/config.hpp>
|
||||||
#include <mapnik/coord.hpp>
|
#include <mapnik/geometry.hpp>
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#include <mapnik/warning_ignore.hpp>
|
#include <mapnik/warning_ignore.hpp>
|
||||||
|
@ -68,7 +68,7 @@ public:
|
||||||
|
|
||||||
box2d();
|
box2d();
|
||||||
box2d(T minx,T miny,T maxx,T maxy);
|
box2d(T minx,T miny,T maxx,T maxy);
|
||||||
box2d(coord<T,2> const& c0, coord<T,2> const& c1);
|
box2d(geometry::point<T> const& c0, geometry::point<T> const& c1);
|
||||||
box2d(box2d_type const& rhs);
|
box2d(box2d_type const& rhs);
|
||||||
box2d(box2d_type const& rhs, agg::trans_affine const& tr);
|
box2d(box2d_type const& rhs, agg::trans_affine const& tr);
|
||||||
// move
|
// move
|
||||||
|
@ -94,20 +94,20 @@ public:
|
||||||
T height() const;
|
T height() const;
|
||||||
void width(T w);
|
void width(T w);
|
||||||
void height(T h);
|
void height(T h);
|
||||||
coord<T,2> center() const;
|
geometry::point<T> center() const;
|
||||||
void expand_to_include(T x,T y);
|
void expand_to_include(T x,T y);
|
||||||
void expand_to_include(coord<T,2> const& c);
|
void expand_to_include(geometry::point<T> const& c);
|
||||||
void expand_to_include(box2d_type const& other);
|
void expand_to_include(box2d_type const& other);
|
||||||
bool contains(coord<T,2> const& c) const;
|
bool contains(geometry::point<T> const& c) const;
|
||||||
bool contains(T x,T y) const;
|
bool contains(T x,T y) const;
|
||||||
bool contains(box2d_type const& other) const;
|
bool contains(box2d_type const& other) const;
|
||||||
bool intersects(coord<T,2> const& c) const;
|
bool intersects(geometry::point<T> const& c) const;
|
||||||
bool intersects(T x,T y) const;
|
bool intersects(T x,T y) const;
|
||||||
bool intersects(box2d_type const& other) const;
|
bool intersects(box2d_type const& other) const;
|
||||||
box2d_type intersect(box2d_type const& other) const;
|
box2d_type intersect(box2d_type const& other) const;
|
||||||
bool operator==(box2d_type const& other) const;
|
bool operator==(box2d_type const& other) const;
|
||||||
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(geometry::point<T> 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 init(T x, T y);
|
||||||
void clip(box2d_type const& other);
|
void clip(box2d_type const& other);
|
||||||
|
|
|
@ -25,17 +25,17 @@
|
||||||
#include <mapnik/safe_cast.hpp>
|
#include <mapnik/safe_cast.hpp>
|
||||||
|
|
||||||
// stl
|
// stl
|
||||||
#include <stdexcept>
|
|
||||||
#include <sstream>
|
|
||||||
#include <iomanip>
|
#include <iomanip>
|
||||||
|
#include <sstream>
|
||||||
|
#include <stdexcept>
|
||||||
|
|
||||||
#include <mapnik/config.hpp>
|
#include <mapnik/config.hpp>
|
||||||
|
|
||||||
#pragma GCC diagnostic push
|
#pragma GCC diagnostic push
|
||||||
#include <mapnik/warning_ignore.hpp>
|
|
||||||
#include <boost/fusion/include/adapt_adt.hpp>
|
#include <boost/fusion/include/adapt_adt.hpp>
|
||||||
#include <boost/spirit/include/qi.hpp>
|
#include <boost/spirit/include/qi.hpp>
|
||||||
#include <boost/spirit/include/support_adapt_adt_attributes.hpp>
|
#include <boost/spirit/include/support_adapt_adt_attributes.hpp>
|
||||||
|
#include <mapnik/warning_ignore.hpp>
|
||||||
#pragma GCC diagnostic pop
|
#pragma GCC diagnostic pop
|
||||||
|
|
||||||
// agg
|
// agg
|
||||||
|
@ -44,28 +44,26 @@
|
||||||
BOOST_FUSION_ADAPT_TPL_ADT(
|
BOOST_FUSION_ADAPT_TPL_ADT(
|
||||||
(T),
|
(T),
|
||||||
(mapnik::box2d)(T),
|
(mapnik::box2d)(T),
|
||||||
(T, T, obj.minx(), obj.set_minx(mapnik::safe_cast<T>(val)))
|
(T, T, obj.minx(), obj.set_minx(mapnik::safe_cast<T>(val)))(T, T, obj.miny(), obj.set_miny(mapnik::safe_cast<T>(val)))(T, T, obj.maxx(), obj.set_maxx(mapnik::safe_cast<T>(val)))(T, T, obj.maxy(), obj.set_maxy(mapnik::safe_cast<T>(val))))
|
||||||
(T, T, obj.miny(), obj.set_miny(mapnik::safe_cast<T>(val)))
|
|
||||||
(T, T, obj.maxx(), obj.set_maxx(mapnik::safe_cast<T>(val)))
|
|
||||||
(T, T, obj.maxy(), obj.set_maxy(mapnik::safe_cast<T>(val))))
|
|
||||||
|
|
||||||
namespace mapnik
|
namespace mapnik {
|
||||||
{
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
box2d<T>::box2d()
|
box2d<T>::box2d()
|
||||||
:minx_( std::numeric_limits<T>::max()),
|
: minx_(std::numeric_limits<T>::max()),
|
||||||
miny_( std::numeric_limits<T>::max()),
|
miny_(std::numeric_limits<T>::max()),
|
||||||
maxx_(-std::numeric_limits<T>::max()),
|
maxx_(-std::numeric_limits<T>::max()),
|
||||||
maxy_(-std::numeric_limits<T>::max()) {}
|
maxy_(-std::numeric_limits<T>::max())
|
||||||
|
|
||||||
template <typename T>
|
|
||||||
box2d<T>::box2d(T minx,T miny,T maxx,T maxy)
|
|
||||||
{
|
{
|
||||||
init(minx,miny,maxx,maxy);
|
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
box2d<T>::box2d(coord<T,2> const& c0, coord<T,2> const& c1)
|
box2d<T>::box2d(T minx, T miny, T maxx, T maxy)
|
||||||
|
{
|
||||||
|
init(minx, miny, maxx, maxy);
|
||||||
|
}
|
||||||
|
|
||||||
|
template <typename T>
|
||||||
|
box2d<T>::box2d(geometry::point<T> const& c0, geometry::point<T> const& c1)
|
||||||
{
|
{
|
||||||
init(c0.x,c0.y,c1.x,c1.y);
|
init(c0.x,c0.y,c1.x,c1.y);
|
||||||
}
|
}
|
||||||
|
@ -75,14 +73,18 @@ box2d<T>::box2d(box2d_type const& rhs)
|
||||||
: minx_(rhs.minx_),
|
: minx_(rhs.minx_),
|
||||||
miny_(rhs.miny_),
|
miny_(rhs.miny_),
|
||||||
maxx_(rhs.maxx_),
|
maxx_(rhs.maxx_),
|
||||||
maxy_(rhs.maxy_) {}
|
maxy_(rhs.maxy_)
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
box2d<T>::box2d(box2d_type && rhs)
|
box2d<T>::box2d(box2d_type&& rhs)
|
||||||
: minx_(std::move(rhs.minx_)),
|
: minx_(std::move(rhs.minx_)),
|
||||||
miny_(std::move(rhs.miny_)),
|
miny_(std::move(rhs.miny_)),
|
||||||
maxx_(std::move(rhs.maxx_)),
|
maxx_(std::move(rhs.maxx_)),
|
||||||
maxy_(std::move(rhs.maxy_)) {}
|
maxy_(std::move(rhs.maxy_))
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
box2d<T>& box2d<T>::operator=(box2d_type other)
|
box2d<T>& box2d<T>::operator=(box2d_type other)
|
||||||
|
@ -111,10 +113,10 @@ box2d<T>::box2d(box2d_type const& rhs, agg::trans_affine const& tr)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool box2d<T>::operator==(box2d<T> const& other) const
|
bool box2d<T>::operator==(box2d<T> const& other) const
|
||||||
{
|
{
|
||||||
return minx_==other.minx_ &&
|
return minx_ == other.minx_ &&
|
||||||
miny_==other.miny_ &&
|
miny_ == other.miny_ &&
|
||||||
maxx_==other.maxx_ &&
|
maxx_ == other.maxx_ &&
|
||||||
maxy_==other.maxy_;
|
maxy_ == other.maxy_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -141,25 +143,25 @@ T box2d<T>::maxy() const
|
||||||
return maxy_;
|
return maxy_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
void box2d<T>::set_minx(T v)
|
void box2d<T>::set_minx(T v)
|
||||||
{
|
{
|
||||||
minx_ = v;
|
minx_ = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
void box2d<T>::set_miny(T v)
|
void box2d<T>::set_miny(T v)
|
||||||
{
|
{
|
||||||
miny_ = v;
|
miny_ = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
void box2d<T>::set_maxx(T v)
|
void box2d<T>::set_maxx(T v)
|
||||||
{
|
{
|
||||||
maxx_ = v;
|
maxx_ = v;
|
||||||
}
|
}
|
||||||
|
|
||||||
template<typename T>
|
template <typename T>
|
||||||
void box2d<T>::set_maxy(T v)
|
void box2d<T>::set_maxy(T v)
|
||||||
{
|
{
|
||||||
maxy_ = v;
|
maxy_ = v;
|
||||||
|
@ -168,100 +170,100 @@ void box2d<T>::set_maxy(T v)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T box2d<T>::width() const
|
T box2d<T>::width() const
|
||||||
{
|
{
|
||||||
return maxx_-minx_;
|
return maxx_ - minx_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T box2d<T>::height() const
|
T box2d<T>::height() const
|
||||||
{
|
{
|
||||||
return maxy_-miny_;
|
return maxy_ - miny_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void box2d<T>::width(T w)
|
void box2d<T>::width(T w)
|
||||||
{
|
{
|
||||||
T cx=center().x;
|
T cx = center().x;
|
||||||
minx_=static_cast<T>(cx-w*0.5);
|
minx_ = static_cast<T>(cx - w * 0.5);
|
||||||
maxx_=static_cast<T>(cx+w*0.5);
|
maxx_ = static_cast<T>(cx + w * 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void box2d<T>::height(T h)
|
void box2d<T>::height(T h)
|
||||||
{
|
{
|
||||||
T cy=center().y;
|
T cy = center().y;
|
||||||
miny_=static_cast<T>(cy-h*0.5);
|
miny_ = static_cast<T>(cy - h * 0.5);
|
||||||
maxy_=static_cast<T>(cy+h*0.5);
|
maxy_ = static_cast<T>(cy + h * 0.5);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
coord<T,2> box2d<T>::center() const
|
geometry::point<T> box2d<T>::center() const
|
||||||
{
|
{
|
||||||
return coord<T,2>(static_cast<T>(0.5*(minx_+maxx_)),
|
return geometry::point<T>(static_cast<T>(0.5 * (minx_ + maxx_)),
|
||||||
static_cast<T>(0.5*(miny_+maxy_)));
|
static_cast<T>(0.5 * (miny_ + maxy_)));
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void box2d<T>::expand_to_include(coord<T,2> const& c)
|
void box2d<T>::expand_to_include(geometry::point<T> const& c)
|
||||||
{
|
{
|
||||||
expand_to_include(c.x,c.y);
|
expand_to_include(c.x,c.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void box2d<T>::expand_to_include(T x,T y)
|
void box2d<T>::expand_to_include(T x, T y)
|
||||||
{
|
{
|
||||||
if (x<minx_) minx_=x;
|
if (x < minx_) minx_ = x;
|
||||||
if (x>maxx_) maxx_=x;
|
if (x > maxx_) maxx_ = x;
|
||||||
if (y<miny_) miny_=y;
|
if (y < miny_) miny_ = y;
|
||||||
if (y>maxy_) maxy_=y;
|
if (y > maxy_) maxy_ = y;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void box2d<T>::expand_to_include(box2d<T> const& other)
|
void box2d<T>::expand_to_include(box2d<T> const& other)
|
||||||
{
|
{
|
||||||
if (other.minx_<minx_) minx_=other.minx_;
|
if (other.minx_ < minx_) minx_ = other.minx_;
|
||||||
if (other.maxx_>maxx_) maxx_=other.maxx_;
|
if (other.maxx_ > maxx_) maxx_ = other.maxx_;
|
||||||
if (other.miny_<miny_) miny_=other.miny_;
|
if (other.miny_ < miny_) miny_ = other.miny_;
|
||||||
if (other.maxy_>maxy_) maxy_=other.maxy_;
|
if (other.maxy_ > maxy_) maxy_ = other.maxy_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool box2d<T>::contains(coord<T,2> const& c) const
|
bool box2d<T>::contains(geometry::point<T> const& c) const
|
||||||
{
|
{
|
||||||
return contains(c.x,c.y);
|
return contains(c.x,c.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool box2d<T>::contains(T x,T y) const
|
bool box2d<T>::contains(T x, T y) const
|
||||||
{
|
{
|
||||||
return x>=minx_ && x<=maxx_ && y>=miny_ && y<=maxy_;
|
return x >= minx_ && x <= maxx_ && y >= miny_ && y <= maxy_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool box2d<T>::contains(box2d<T> const& other) const
|
bool box2d<T>::contains(box2d<T> const& other) const
|
||||||
{
|
{
|
||||||
return other.minx_>=minx_ &&
|
return other.minx_ >= minx_ &&
|
||||||
other.maxx_<=maxx_ &&
|
other.maxx_ <= maxx_ &&
|
||||||
other.miny_>=miny_ &&
|
other.miny_ >= miny_ &&
|
||||||
other.maxy_<=maxy_;
|
other.maxy_ <= maxy_;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool box2d<T>::intersects(coord<T,2> const& c) const
|
bool box2d<T>::intersects(geometry::point<T> const& c) const
|
||||||
{
|
{
|
||||||
return intersects(c.x,c.y);
|
return intersects(c.x,c.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool box2d<T>::intersects(T x,T y) const
|
bool box2d<T>::intersects(T x, T y) const
|
||||||
{
|
{
|
||||||
return !(x>maxx_ || x<minx_ || y>maxy_ || y<miny_);
|
return !(x > maxx_ || x < minx_ || y > maxy_ || y < miny_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool box2d<T>::intersects(box2d<T> const& other) const
|
bool box2d<T>::intersects(box2d<T> const& other) const
|
||||||
{
|
{
|
||||||
return !(other.minx_>maxx_ || other.maxx_<minx_ ||
|
return !(other.minx_ > maxx_ || other.maxx_ < minx_ ||
|
||||||
other.miny_>maxy_ || other.maxy_<miny_);
|
other.miny_ > maxy_ || other.maxy_ < miny_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -269,11 +271,11 @@ box2d<T> box2d<T>::intersect(box2d_type const& other) const
|
||||||
{
|
{
|
||||||
if (intersects(other))
|
if (intersects(other))
|
||||||
{
|
{
|
||||||
T x0=std::max(minx_,other.minx_);
|
T x0 = std::max(minx_, other.minx_);
|
||||||
T y0=std::max(miny_,other.miny_);
|
T y0 = std::max(miny_, other.miny_);
|
||||||
T x1=std::min(maxx_,other.maxx_);
|
T x1 = std::min(maxx_, other.maxx_);
|
||||||
T y1=std::min(maxy_,other.maxy_);
|
T y1 = std::min(maxy_, other.maxy_);
|
||||||
return box2d<T>(x0,y0,x1,y1);
|
return box2d<T>(x0, y0, x1, y1);
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
|
@ -282,18 +284,18 @@ box2d<T> box2d<T>::intersect(box2d_type const& other) const
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void box2d<T>::re_center(T cx,T cy)
|
void box2d<T>::re_center(T cx, T cy)
|
||||||
{
|
{
|
||||||
T dx=cx-center().x;
|
T dx = cx - center().x;
|
||||||
T dy=cy-center().y;
|
T dy = cy - center().y;
|
||||||
minx_+=dx;
|
minx_ += dx;
|
||||||
miny_+=dy;
|
miny_ += dy;
|
||||||
maxx_+=dx;
|
maxx_ += dx;
|
||||||
maxy_+=dy;
|
maxy_ += dy;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
void box2d<T>::re_center(coord<T,2> const& c)
|
void box2d<T>::re_center(geometry::point<T> const& c)
|
||||||
{
|
{
|
||||||
re_center(c.x,c.y);
|
re_center(c.x,c.y);
|
||||||
}
|
}
|
||||||
|
@ -364,7 +366,7 @@ bool box2d<T>::from_string(std::string const& str)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
bool box2d<T>::valid() const
|
bool box2d<T>::valid() const
|
||||||
{
|
{
|
||||||
return (minx_ <= maxx_ && miny_ <= maxy_) ;
|
return (minx_ <= maxx_ && miny_ <= maxy_);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
|
@ -393,22 +395,21 @@ std::string box2d<T>::to_string() const
|
||||||
return s.str();
|
return s.str();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
box2d<T>& box2d<T>::operator+=(box2d<T> const& other)
|
box2d<T>& box2d<T>::operator+=(box2d<T> const& other)
|
||||||
{
|
{
|
||||||
expand_to_include(other);
|
expand_to_include(other);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
box2d<T> box2d<T>::operator+ (T other) const
|
box2d<T> box2d<T>::operator+(T other) const
|
||||||
{
|
{
|
||||||
return box2d<T>(minx_ - other, miny_ - other, maxx_ + other, maxy_ + other);
|
return box2d<T>(minx_ - other, miny_ - other, maxx_ + other, maxy_ + other);
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
box2d<T>& box2d<T>::operator+= (T other)
|
box2d<T>& box2d<T>::operator+=(T other)
|
||||||
{
|
{
|
||||||
minx_ -= other;
|
minx_ -= other;
|
||||||
miny_ -= other;
|
miny_ -= other;
|
||||||
|
@ -417,11 +418,10 @@ box2d<T>& box2d<T>::operator+= (T other)
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
box2d<T>& box2d<T>::operator*=(T t)
|
box2d<T>& box2d<T>::operator*=(T t)
|
||||||
{
|
{
|
||||||
coord<T,2> c = center();
|
geometry::point<T> c = center();
|
||||||
T sx = static_cast<T>(0.5 * width() * t);
|
T sx = static_cast<T>(0.5 * width() * t);
|
||||||
T sy = static_cast<T>(0.5 * height() * t);
|
T sy = static_cast<T>(0.5 * height() * t);
|
||||||
minx_ = c.x - sx;
|
minx_ = c.x - sx;
|
||||||
|
@ -434,7 +434,7 @@ box2d<T>& box2d<T>::operator*=(T t)
|
||||||
template <typename T>
|
template <typename T>
|
||||||
box2d<T>& box2d<T>::operator/=(T t)
|
box2d<T>& box2d<T>::operator/=(T t)
|
||||||
{
|
{
|
||||||
coord<T,2> c = center();
|
geometry::point<T> c = center();
|
||||||
T sx = static_cast<T>(0.5 * width() / t);
|
T sx = static_cast<T>(0.5 * width() / t);
|
||||||
T sy = static_cast<T>(0.5 * height() / t);
|
T sy = static_cast<T>(0.5 * height() / t);
|
||||||
minx_ = c.x - sx;
|
minx_ = c.x - sx;
|
||||||
|
@ -445,9 +445,9 @@ box2d<T>& box2d<T>::operator/=(T t)
|
||||||
}
|
}
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
T box2d<T>::operator[] (int index) const
|
T box2d<T>::operator[](int index) const
|
||||||
{
|
{
|
||||||
switch(index)
|
switch (index)
|
||||||
{
|
{
|
||||||
case 0:
|
case 0:
|
||||||
return minx_;
|
return minx_;
|
||||||
|
|
|
@ -33,7 +33,7 @@
|
||||||
#include <mapnik/util/noncopyable.hpp>
|
#include <mapnik/util/noncopyable.hpp>
|
||||||
#include <mapnik/feature_style_processor_context.hpp>
|
#include <mapnik/feature_style_processor_context.hpp>
|
||||||
#include <mapnik/datasource_geometry_type.hpp>
|
#include <mapnik/datasource_geometry_type.hpp>
|
||||||
|
#include <mapnik/coord.hpp>
|
||||||
// stl
|
// stl
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <string>
|
#include <string>
|
||||||
|
|
|
@ -212,7 +212,7 @@ struct filter_at_point
|
||||||
{
|
{
|
||||||
box2d<double> box_;
|
box2d<double> box_;
|
||||||
explicit filter_at_point(coord2d const& pt, double tol=0)
|
explicit filter_at_point(coord2d const& pt, double tol=0)
|
||||||
: box_(pt,pt)
|
: box_(pt.x,pt.y, pt.x, pt.y)
|
||||||
{
|
{
|
||||||
box_.pad(tol);
|
box_.pad(tol);
|
||||||
}
|
}
|
||||||
|
|
|
@ -93,7 +93,7 @@ struct vector_markers_dispatch : util::noncopyable
|
||||||
protected:
|
protected:
|
||||||
static agg::trans_affine recenter(svg_path_ptr const& src)
|
static agg::trans_affine recenter(svg_path_ptr const& src)
|
||||||
{
|
{
|
||||||
coord2d center = src->bounding_box().center();
|
auto center = src->bounding_box().center();
|
||||||
return agg::trans_affine_translation(-center.x, -center.y);
|
return agg::trans_affine_translation(-center.x, -center.y);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -56,8 +56,8 @@ void render_point_symbolizer(point_symbolizer const &sym,
|
||||||
value_bool ignore_placement = get<value_bool, keys::ignore_placement>(sym, feature, common.vars_);
|
value_bool ignore_placement = get<value_bool, keys::ignore_placement>(sym, feature, common.vars_);
|
||||||
point_placement_enum placement= get<point_placement_enum, keys::point_placement_type>(sym, feature, common.vars_);
|
point_placement_enum placement= get<point_placement_enum, keys::point_placement_type>(sym, feature, common.vars_);
|
||||||
|
|
||||||
box2d<double> const& bbox = mark->bounding_box();
|
auto const& bbox = mark->bounding_box();
|
||||||
coord2d center = bbox.center();
|
auto center = bbox.center();
|
||||||
|
|
||||||
agg::trans_affine tr;
|
agg::trans_affine tr;
|
||||||
auto image_transform = get_optional<transform_type>(sym, keys::image_transform);
|
auto image_transform = get_optional<transform_type>(sym, keys::image_transform);
|
||||||
|
|
|
@ -436,7 +436,7 @@ mapnik::featureset_ptr csv_datasource::features(mapnik::query const& q) const
|
||||||
|
|
||||||
mapnik::featureset_ptr csv_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
|
mapnik::featureset_ptr csv_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
|
||||||
{
|
{
|
||||||
mapnik::box2d<double> query_bbox(pt, pt);
|
mapnik::box2d<double> query_bbox(pt.x, pt.y, pt.x, pt.y);
|
||||||
query_bbox.pad(tol);
|
query_bbox.pad(tol);
|
||||||
mapnik::query q(query_bbox);
|
mapnik::query q(query_bbox);
|
||||||
std::vector<mapnik::attribute_descriptor> const& desc = desc_.get_descriptors();
|
std::vector<mapnik::attribute_descriptor> const& desc = desc_.get_descriptors();
|
||||||
|
|
|
@ -593,7 +593,7 @@ mapnik::featureset_ptr geojson_datasource::features(mapnik::query const& q) cons
|
||||||
|
|
||||||
mapnik::featureset_ptr geojson_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
|
mapnik::featureset_ptr geojson_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
|
||||||
{
|
{
|
||||||
mapnik::box2d<double> query_bbox(pt, pt);
|
mapnik::box2d<double> query_bbox(pt.x, pt.y, pt.x, pt.y);
|
||||||
query_bbox.pad(tol);
|
query_bbox.pad(tol);
|
||||||
mapnik::query q(query_bbox);
|
mapnik::query q(query_bbox);
|
||||||
for (auto const& attr_info : desc_.get_descriptors())
|
for (auto const& attr_info : desc_.get_descriptors())
|
||||||
|
|
|
@ -594,7 +594,7 @@ featureset_ptr ogr_datasource::features_at_point(coord2d const& pt, double tol)
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
mapnik::box2d<double> bbox(pt, pt);
|
mapnik::box2d<double> bbox(pt.x, pt.y, pt.x, pt.y);
|
||||||
bbox.pad(tol);
|
bbox.pad(tol);
|
||||||
return featureset_ptr(new ogr_featureset (ctx,
|
return featureset_ptr(new ogr_featureset (ctx,
|
||||||
*layer,
|
*layer,
|
||||||
|
|
|
@ -289,7 +289,7 @@ mapnik::featureset_ptr topojson_datasource::features(mapnik::query const& q) con
|
||||||
|
|
||||||
mapnik::featureset_ptr topojson_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
|
mapnik::featureset_ptr topojson_datasource::features_at_point(mapnik::coord2d const& pt, double tol) const
|
||||||
{
|
{
|
||||||
mapnik::box2d<double> query_bbox(pt, pt);
|
mapnik::box2d<double> query_bbox(pt.x, pt.y, pt.x, pt.y);
|
||||||
query_bbox.pad(tol);
|
query_bbox.pad(tol);
|
||||||
mapnik::query q(query_bbox);
|
mapnik::query q(query_bbox);
|
||||||
for (auto const& attr_info : desc_.get_descriptors())
|
for (auto const& attr_info : desc_.get_descriptors())
|
||||||
|
|
|
@ -395,7 +395,7 @@ struct agg_render_marker_visitor
|
||||||
renderer_base renb(pixf);
|
renderer_base renb(pixf);
|
||||||
|
|
||||||
box2d<double> const& bbox = marker.get_data()->bounding_box();
|
box2d<double> const& bbox = marker.get_data()->bounding_box();
|
||||||
coord<double,2> c = bbox.center();
|
auto c = bbox.center();
|
||||||
// center the svg marker on '0,0'
|
// center the svg marker on '0,0'
|
||||||
agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y);
|
agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y);
|
||||||
// apply symbol transformation to get to map space
|
// apply symbol transformation to get to map space
|
||||||
|
|
|
@ -228,8 +228,8 @@ struct cairo_render_marker_visitor
|
||||||
agg::trans_affine marker_tr = tr_;
|
agg::trans_affine marker_tr = tr_;
|
||||||
if (recenter_)
|
if (recenter_)
|
||||||
{
|
{
|
||||||
coord<double,2> c = bbox.center();
|
auto c = bbox.center();
|
||||||
marker_tr = agg::trans_affine_translation(-c.x,-c.y);
|
marker_tr = agg::trans_affine_translation(-c.x, -c.y);
|
||||||
marker_tr *= tr_;
|
marker_tr *= tr_;
|
||||||
}
|
}
|
||||||
marker_tr *= agg::trans_affine_scaling(common_.scale_factor_);
|
marker_tr *= agg::trans_affine_scaling(common_.scale_factor_);
|
||||||
|
|
|
@ -163,8 +163,8 @@ struct grid_render_marker_visitor
|
||||||
|
|
||||||
ras_ptr_->reset();
|
ras_ptr_->reset();
|
||||||
|
|
||||||
box2d<double> const& bbox = marker.get_data()->bounding_box();
|
auto const& bbox = marker.get_data()->bounding_box();
|
||||||
coord<double,2> c = bbox.center();
|
auto c = bbox.center();
|
||||||
// center the svg marker on '0,0'
|
// center the svg marker on '0,0'
|
||||||
agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y);
|
agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y);
|
||||||
// apply symbol transformation to get to map space
|
// apply symbol transformation to get to map space
|
||||||
|
|
|
@ -41,6 +41,7 @@
|
||||||
#include <mapnik/text/font_library.hpp>
|
#include <mapnik/text/font_library.hpp>
|
||||||
#include <mapnik/util/file_io.hpp>
|
#include <mapnik/util/file_io.hpp>
|
||||||
#include <mapnik/font_engine_freetype.hpp>
|
#include <mapnik/font_engine_freetype.hpp>
|
||||||
|
#include <mapnik/geometry.hpp>
|
||||||
|
|
||||||
// stl
|
// stl
|
||||||
#include <stdexcept>
|
#include <stdexcept>
|
||||||
|
@ -499,7 +500,7 @@ void Map::set_base_path(std::string const& base)
|
||||||
|
|
||||||
void Map::zoom(double factor)
|
void Map::zoom(double factor)
|
||||||
{
|
{
|
||||||
coord2d center = current_extent_.center();
|
auto center = current_extent_.center();
|
||||||
double w = factor * current_extent_.width();
|
double w = factor * current_extent_.width();
|
||||||
double h = factor * current_extent_.height();
|
double h = factor * current_extent_.height();
|
||||||
current_extent_ = box2d<double>(center.x - 0.5 * w,
|
current_extent_ = box2d<double>(center.x - 0.5 * w,
|
||||||
|
|
|
@ -25,7 +25,6 @@
|
||||||
#include <mapnik/box2d.hpp>
|
#include <mapnik/box2d.hpp>
|
||||||
#include <mapnik/projection.hpp>
|
#include <mapnik/projection.hpp>
|
||||||
#include <mapnik/proj_transform.hpp>
|
#include <mapnik/proj_transform.hpp>
|
||||||
#include <mapnik/coord.hpp>
|
|
||||||
#include <mapnik/util/is_clockwise.hpp>
|
#include <mapnik/util/is_clockwise.hpp>
|
||||||
|
|
||||||
#ifdef MAPNIK_USE_PROJ4
|
#ifdef MAPNIK_USE_PROJ4
|
||||||
|
@ -335,7 +334,7 @@ bool proj_transform::backward (box2d<double> & box) const
|
||||||
}
|
}
|
||||||
|
|
||||||
// Returns points in clockwise order. This allows us to do anti-meridian checks.
|
// Returns points in clockwise order. This allows us to do anti-meridian checks.
|
||||||
void envelope_points(std::vector< coord<double,2> > & coords, box2d<double>& env, int points)
|
void envelope_points(std::vector<geometry::point<double>> & coords, box2d<double>& env, int points)
|
||||||
{
|
{
|
||||||
double width = env.width();
|
double width = env.width();
|
||||||
double height = env.height();
|
double height = env.height();
|
||||||
|
@ -353,21 +352,22 @@ void envelope_points(std::vector< coord<double,2> > & coords, box2d<double>& env
|
||||||
double ystep = height / steps;
|
double ystep = height / steps;
|
||||||
|
|
||||||
coords.resize(points);
|
coords.resize(points);
|
||||||
for (int i=0; i<steps; i++) {
|
for (int i = 0; i < steps; ++i)
|
||||||
|
{
|
||||||
// top: left>right
|
// top: left>right
|
||||||
coords[i] = coord<double, 2>(env.minx() + i * xstep, env.maxy());
|
coords[i] = geometry::point<double>(env.minx() + i * xstep, env.maxy());
|
||||||
// right: top>bottom
|
// right: top>bottom
|
||||||
coords[i + steps] = coord<double, 2>(env.maxx(), env.maxy() - i * ystep);
|
coords[i + steps] = geometry::point<double>(env.maxx(), env.maxy() - i * ystep);
|
||||||
// bottom: right>left
|
// bottom: right>left
|
||||||
coords[i + steps * 2] = coord<double, 2>(env.maxx() - i * xstep, env.miny());
|
coords[i + steps * 2] = geometry::point<double>(env.maxx() - i * xstep, env.miny());
|
||||||
// left: bottom>top
|
// left: bottom>top
|
||||||
coords[i + steps * 3] = coord<double, 2>(env.minx(), env.miny() + i * ystep);
|
coords[i + steps * 3] = geometry::point<double>(env.minx(), env.miny() + i * ystep);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
box2d<double> calculate_bbox(std::vector<coord<double,2> > & points) {
|
box2d<double> calculate_bbox(std::vector<geometry::point<double> > & points) {
|
||||||
std::vector<coord<double,2> >::iterator it = points.begin();
|
std::vector<geometry::point<double> >::iterator it = points.begin();
|
||||||
std::vector<coord<double,2> >::iterator it_end = points.end();
|
std::vector<geometry::point<double> >::iterator it_end = points.end();
|
||||||
|
|
||||||
box2d<double> env(*it, *(++it));
|
box2d<double> env(*it, *(++it));
|
||||||
for (; it!=it_end; ++it) {
|
for (; it!=it_end; ++it) {
|
||||||
|
@ -393,15 +393,13 @@ bool proj_transform::backward(box2d<double>& env, int points) const
|
||||||
return backward(env);
|
return backward(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<coord<double,2> > coords;
|
std::vector<geometry::point<double>> coords;
|
||||||
envelope_points(coords, env, points); // this is always clockwise
|
envelope_points(coords, env, points); // this is always clockwise
|
||||||
|
|
||||||
double z;
|
for (auto & pt : coords)
|
||||||
for (std::vector<coord<double,2> >::iterator it = coords.begin(); it!=coords.end(); ++it) {
|
{
|
||||||
z = 0;
|
double z = 0;
|
||||||
if (!backward(it->x, it->y, z)) {
|
if (!backward(pt.x, pt.y, z)) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
box2d<double> result = calculate_bbox(coords);
|
box2d<double> result = calculate_bbox(coords);
|
||||||
|
@ -432,15 +430,13 @@ bool proj_transform::forward(box2d<double>& env, int points) const
|
||||||
return forward(env);
|
return forward(env);
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<coord<double,2> > coords;
|
std::vector<geometry::point<double>> coords;
|
||||||
envelope_points(coords, env, points); // this is always clockwise
|
envelope_points(coords, env, points); // this is always clockwise
|
||||||
|
|
||||||
double z;
|
for (auto & pt : coords)
|
||||||
for (std::vector<coord<double,2> >::iterator it = coords.begin(); it!=coords.end(); ++it) {
|
{
|
||||||
z = 0;
|
double z = 0;
|
||||||
if (!forward(it->x, it->y, z)) {
|
if (!forward(pt.x, pt.y, z)) return false;
|
||||||
return false;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
box2d<double> result = calculate_bbox(coords);
|
box2d<double> result = calculate_bbox(coords);
|
||||||
|
|
|
@ -187,7 +187,7 @@ struct render_marker_symbolizer_visitor
|
||||||
box2d<double> const& bbox = mark.bounding_box();
|
box2d<double> const& bbox = mark.bounding_box();
|
||||||
mapnik::image_rgba8 const& marker = mark.get_data();
|
mapnik::image_rgba8 const& marker = mark.get_data();
|
||||||
// - clamp sizes to > 4 pixels of interactivity
|
// - clamp sizes to > 4 pixels of interactivity
|
||||||
coord2d center = bbox.center();
|
auto center = bbox.center();
|
||||||
agg::trans_affine_translation recenter(-center.x, -center.y);
|
agg::trans_affine_translation recenter(-center.x, -center.y);
|
||||||
agg::trans_affine marker_trans = recenter * image_tr;
|
agg::trans_affine marker_trans = recenter * image_tr;
|
||||||
raster_dispatch_type rasterizer_dispatch(marker,
|
raster_dispatch_type rasterizer_dispatch(marker,
|
||||||
|
|
|
@ -52,9 +52,9 @@ void render_pattern<image_rgba8>(rasterizer & ras,
|
||||||
using renderer_solid = agg::renderer_scanline_aa_solid<renderer_base>;
|
using renderer_solid = agg::renderer_scanline_aa_solid<renderer_base>;
|
||||||
agg::scanline_u8 sl;
|
agg::scanline_u8 sl;
|
||||||
|
|
||||||
mapnik::box2d<double> const& bbox = marker.bounding_box() * tr;
|
auto const& bbox = marker.bounding_box() * tr;
|
||||||
mapnik::coord<double,2> c = bbox.center();
|
auto c = bbox.center();
|
||||||
agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y);
|
agg::trans_affine mtx = agg::trans_affine_translation(-c.x, -c.y);
|
||||||
mtx.translate(0.5 * bbox.width(), 0.5 * bbox.height());
|
mtx.translate(0.5 * bbox.width(), 0.5 * bbox.height());
|
||||||
mtx = tr * mtx;
|
mtx = tr * mtx;
|
||||||
|
|
||||||
|
|
|
@ -1 +1 @@
|
||||||
Subproject commit 5f0e6f86696a2a9a6733e42b1f400ba4ec2f8847
|
Subproject commit 047985797ab11ea34ac97e469d0871b6220ea4d3
|
|
@ -1,25 +1,9 @@
|
||||||
|
|
||||||
#include "catch.hpp"
|
#include "catch.hpp"
|
||||||
|
|
||||||
#include <mapnik/coord.hpp>
|
|
||||||
#include <mapnik/box2d.hpp>
|
#include <mapnik/box2d.hpp>
|
||||||
#include "agg_trans_affine.h"
|
#include "agg_trans_affine.h"
|
||||||
|
|
||||||
TEST_CASE("box2d") {
|
TEST_CASE("box2d") {
|
||||||
SECTION("coord init") {
|
|
||||||
auto c = mapnik::coord2d(100, 100);
|
|
||||||
|
|
||||||
REQUIRE(c.x == 100);
|
|
||||||
REQUIRE(c.y == 100);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("coord multiplication") {
|
|
||||||
auto c = mapnik::coord2d(100, 100);
|
|
||||||
c *= 2;
|
|
||||||
|
|
||||||
REQUIRE(c.x == 200);
|
|
||||||
REQUIRE(c.y == 200);
|
|
||||||
}
|
|
||||||
|
|
||||||
SECTION("envelope init") {
|
SECTION("envelope init") {
|
||||||
auto e = mapnik::box2d<double>(100, 100, 200, 200);
|
auto e = mapnik::box2d<double>(100, 100, 200, 200);
|
||||||
|
@ -171,9 +155,9 @@ SECTION("mapnik::box2d intersects")
|
||||||
mapnik::box2d<double> b2(100.001,100,200,200);
|
mapnik::box2d<double> b2(100.001,100,200,200);
|
||||||
CHECK(!b0.intersects(b2));
|
CHECK(!b0.intersects(b2));
|
||||||
CHECK(!b2.intersects(b0));
|
CHECK(!b2.intersects(b0));
|
||||||
// coord
|
// geometry::point<T>
|
||||||
CHECK(b0.intersects(mapnik::coord<double,2>(100,100)));
|
CHECK(b0.intersects(mapnik::geometry::point<double>(100,100)));
|
||||||
CHECK(!b0.intersects(mapnik::coord<double,2>(100.001,100)));
|
CHECK(!b0.intersects(mapnik::geometry::point<double>(100.001,100)));
|
||||||
}
|
}
|
||||||
|
|
||||||
SECTION("mapnik::box2d intersect")
|
SECTION("mapnik::box2d intersect")
|
||||||
|
@ -192,7 +176,7 @@ SECTION("mapnik::box2d re_center")
|
||||||
mapnik::box2d<double> b(0, 0, 100, 100);
|
mapnik::box2d<double> b(0, 0, 100, 100);
|
||||||
b.re_center(0, 0);
|
b.re_center(0, 0);
|
||||||
CHECK(b == mapnik::box2d<double>(-50, -50, 50, 50));
|
CHECK(b == mapnik::box2d<double>(-50, -50, 50, 50));
|
||||||
b.re_center(mapnik::coord2d(50,50));
|
b.re_center(mapnik::geometry::point<double>(50,50));
|
||||||
CHECK(b == mapnik::box2d<double>(0, 0, 100, 100));
|
CHECK(b == mapnik::box2d<double>(0, 0, 100, 100));
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -283,7 +283,8 @@ TEST_CASE("csv") {
|
||||||
CHECK(count_features(all_features(ds)) == 2);
|
CHECK(count_features(all_features(ds)) == 2);
|
||||||
|
|
||||||
auto fs = all_features(ds);
|
auto fs = all_features(ds);
|
||||||
auto fs2 = ds->features_at_point(ds->envelope().center(),10000);
|
auto pt = ds->envelope().center();
|
||||||
|
auto fs2 = ds->features_at_point(mapnik::coord<double, 2>(pt.x, pt.y), 10000);
|
||||||
REQUIRE(fs != nullptr);
|
REQUIRE(fs != nullptr);
|
||||||
auto feature = fs->next();
|
auto feature = fs->next();
|
||||||
auto feature2 = fs2->next();
|
auto feature2 = fs2->next();
|
||||||
|
|
|
@ -284,7 +284,8 @@ TEST_CASE("geojson") {
|
||||||
query.add_property_name(field.get_name());
|
query.add_property_name(field.get_name());
|
||||||
}
|
}
|
||||||
auto features = ds->features(query);
|
auto features = ds->features(query);
|
||||||
auto features2 = ds->features_at_point(ds->envelope().center(),0);
|
auto pt = ds->envelope().center();
|
||||||
|
auto features2 = ds->features_at_point(mapnik::coord<double, 2>(pt.x, pt.y), 0);
|
||||||
REQUIRE(features != nullptr);
|
REQUIRE(features != nullptr);
|
||||||
REQUIRE(features2 != nullptr);
|
REQUIRE(features2 != nullptr);
|
||||||
auto feature = features->next();
|
auto feature = features->next();
|
||||||
|
@ -341,7 +342,8 @@ TEST_CASE("geojson") {
|
||||||
query.add_property_name(field.get_name());
|
query.add_property_name(field.get_name());
|
||||||
}
|
}
|
||||||
auto features = ds->features(query);
|
auto features = ds->features(query);
|
||||||
auto features2 = ds->features_at_point(ds->envelope().center(),10);
|
auto pt = ds->envelope().center();
|
||||||
|
auto features2 = ds->features_at_point(mapnik::coord<double, 2>(pt.x, pt.y), 10);
|
||||||
auto bounding_box = ds->envelope();
|
auto bounding_box = ds->envelope();
|
||||||
mapnik::box2d<double> bbox;
|
mapnik::box2d<double> bbox;
|
||||||
mapnik::value_integer count = 0;
|
mapnik::value_integer count = 0;
|
||||||
|
|
|
@ -86,10 +86,10 @@ struct main_marker_visitor
|
||||||
pixfmt pixf(buf);
|
pixfmt pixf(buf);
|
||||||
renderer_base renb(pixf);
|
renderer_base renb(pixf);
|
||||||
|
|
||||||
mapnik::box2d<double> const& bbox = marker.get_data()->bounding_box();
|
auto const& bbox = marker.get_data()->bounding_box();
|
||||||
mapnik::coord<double,2> c = bbox.center();
|
auto c = bbox.center();
|
||||||
// center the svg marker on '0,0'
|
// center the svg marker on '0,0'
|
||||||
agg::trans_affine mtx = agg::trans_affine_translation(-c.x,-c.y);
|
agg::trans_affine mtx = agg::trans_affine_translation(-c.x, -c.y);
|
||||||
// render the marker at the center of the marker box
|
// render the marker at the center of the marker box
|
||||||
mtx.translate(0.5 * im.width(), 0.5 * im.height());
|
mtx.translate(0.5 * im.width(), 0.5 * im.height());
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue