2006-03-31 12:32:02 +02:00
|
|
|
/*****************************************************************************
|
2012-02-02 02:53:35 +01:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* This file is part of Mapnik (c++ mapping toolkit)
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2011-10-23 15:04:25 +02:00
|
|
|
* Copyright (C) 2011 Artem Pavlenko
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* This library is free software; you can redistribute it and/or
|
|
|
|
* modify it under the terms of the GNU Lesser General Public
|
|
|
|
* License as published by the Free Software Foundation; either
|
|
|
|
* version 2.1 of the License, or (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This library is distributed in the hope that it will be useful,
|
2005-06-14 17:06:59 +02:00
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
2006-03-31 12:32:02 +02:00
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
|
|
* Lesser General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU Lesser General Public
|
|
|
|
* License along with this library; if not, write to the Free Software
|
|
|
|
* Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
*****************************************************************************/
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2009-12-16 21:02:06 +01:00
|
|
|
#ifndef MAPNIK_BOX2D_HPP
|
|
|
|
#define MAPNIK_BOX2D_HPP
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
// mapnik
|
|
|
|
#include <mapnik/config.hpp>
|
|
|
|
#include <mapnik/coord.hpp>
|
2011-10-23 16:09:47 +02:00
|
|
|
|
2007-10-08 20:10:31 +02:00
|
|
|
// boost
|
|
|
|
#include <boost/operators.hpp>
|
2011-10-23 16:09:47 +02:00
|
|
|
|
2007-10-08 20:10:31 +02:00
|
|
|
// stl
|
|
|
|
#include <iomanip>
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2012-03-06 18:12:45 +01:00
|
|
|
// agg
|
|
|
|
// forward declare so that apps using mapnik do not need agg headers
|
|
|
|
namespace agg {
|
|
|
|
struct trans_affine;
|
|
|
|
}
|
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
namespace mapnik {
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
/*!
|
|
|
|
* A spatial envelope (i.e. bounding box) which also defines some basic operators.
|
|
|
|
*/
|
2012-02-02 02:53:35 +01:00
|
|
|
template <typename T> class MAPNIK_DECL box2d
|
2011-06-07 23:16:03 +02:00
|
|
|
: boost::equality_comparable<box2d<T> ,
|
2012-02-02 02:53:35 +01:00
|
|
|
boost::addable<box2d<T>,
|
|
|
|
boost::dividable2<box2d<T>, T,
|
|
|
|
boost::multipliable2<box2d<T>, T > > > >
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
public:
|
2014-07-07 19:23:15 +02:00
|
|
|
using box2d_type = box2d<T>;
|
2010-06-02 13:03:30 +02:00
|
|
|
private:
|
|
|
|
T minx_;
|
|
|
|
T miny_;
|
|
|
|
T maxx_;
|
|
|
|
T maxy_;
|
2014-05-27 12:21:13 +02:00
|
|
|
friend inline void swap(box2d_type & lhs, box2d_type & rhs)
|
|
|
|
{
|
|
|
|
using std::swap;
|
|
|
|
swap(lhs.minx_, rhs.minx_);
|
|
|
|
swap(lhs.miny_, rhs.miny_);
|
|
|
|
swap(lhs.maxx_, rhs.maxx_);
|
|
|
|
swap(lhs.maxy_, rhs.maxy_);
|
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
public:
|
|
|
|
box2d();
|
|
|
|
box2d(T minx,T miny,T maxx,T maxy);
|
2013-09-19 04:04:20 +02:00
|
|
|
box2d(coord<T,2> const& c0, coord<T,2> const& c1);
|
|
|
|
box2d(box2d_type const& rhs);
|
|
|
|
box2d(box2d_type const& rhs, agg::trans_affine const& tr);
|
2013-09-20 05:19:01 +02:00
|
|
|
box2d(box2d_type&& rhs);
|
2013-09-19 04:04:20 +02:00
|
|
|
box2d_type& operator=(box2d_type other);
|
2010-06-02 13:03:30 +02:00
|
|
|
T minx() const;
|
|
|
|
T miny() const;
|
|
|
|
T maxx() const;
|
|
|
|
T maxy() const;
|
2013-03-06 22:09:15 +01:00
|
|
|
void set_minx(T v);
|
|
|
|
void set_miny(T v);
|
|
|
|
void set_maxx(T v);
|
|
|
|
void set_maxy(T v);
|
2010-06-02 13:03:30 +02:00
|
|
|
T width() const;
|
|
|
|
T height() const;
|
|
|
|
void width(T w);
|
|
|
|
void height(T h);
|
|
|
|
coord<T,2> center() const;
|
|
|
|
void expand_to_include(T x,T y);
|
2013-09-19 04:04:20 +02:00
|
|
|
void expand_to_include(coord<T,2> const& c);
|
|
|
|
void expand_to_include(box2d_type const& other);
|
|
|
|
bool contains(coord<T,2> const& c) const;
|
2010-06-02 13:03:30 +02:00
|
|
|
bool contains(T x,T y) const;
|
2013-09-19 04:04:20 +02:00
|
|
|
bool contains(box2d_type const& other) const;
|
|
|
|
bool intersects(coord<T,2> const& c) const;
|
2010-06-02 13:03:30 +02:00
|
|
|
bool intersects(T x,T y) const;
|
2013-09-19 04:04:20 +02:00
|
|
|
bool intersects(box2d_type const& other) const;
|
|
|
|
box2d_type intersect(box2d_type const& other) const;
|
|
|
|
bool operator==(box2d_type const& other) const;
|
2010-06-02 13:03:30 +02:00
|
|
|
void re_center(T cx,T cy);
|
2013-09-19 04:04:20 +02:00
|
|
|
void re_center(coord<T,2> const& c);
|
2010-06-02 13:03:30 +02:00
|
|
|
void init(T x0,T y0,T x1,T y1);
|
2013-09-19 04:04:20 +02:00
|
|
|
void clip(box2d_type const& other);
|
2012-12-11 22:56:25 +01:00
|
|
|
void pad(T padding);
|
2013-09-19 04:04:20 +02:00
|
|
|
bool from_string(std::string const& str);
|
2011-04-04 05:50:09 +02:00
|
|
|
bool valid() const;
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
void move(T x, T y);
|
2012-02-02 02:53:35 +01:00
|
|
|
|
|
|
|
// define some operators
|
2010-06-02 13:03:30 +02:00
|
|
|
box2d_type& operator+=(box2d_type const& other);
|
|
|
|
box2d_type& operator*=(T);
|
2010-09-16 16:41:29 +02:00
|
|
|
box2d_type& operator/=(T);
|
|
|
|
T operator[](int index) const;
|
Improved support for international text
- Implementation by @herm for GSOC 2012 (http://mapnik.org/news/2012/10/06/gsoc2012-status9/)
- C++11 port, improvements, optimizations by @artemp
- Testing and integration with master by @springmeyer
- Thank you to all the support from @behdad along the way
- Thanks for help testing @toton6868, @stephankn, @nirvn, @mfrasca, @simonsonc and many others
Refs: #2073,#2070,#2038,#2037,#1953,#1820,#1819,#1714,#1634,#1547,#1532,#1319,#1208,#1154,#1146
2013-11-22 09:06:32 +01:00
|
|
|
box2d_type operator +(T other) const; //enlarge box by given amount
|
|
|
|
box2d_type& operator +=(T other); //enlarge box by given amount
|
2012-03-06 18:12:45 +01:00
|
|
|
|
|
|
|
// compute the bounding box of this one transformed
|
|
|
|
box2d_type operator* (agg::trans_affine const& tr) const;
|
|
|
|
box2d_type& operator*=(agg::trans_affine const& tr);
|
2010-06-02 13:03:30 +02:00
|
|
|
};
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <class charT,class traits,class T>
|
|
|
|
inline std::basic_ostream<charT,traits>&
|
|
|
|
operator << (std::basic_ostream<charT,traits>& out,
|
|
|
|
const box2d<T>& e)
|
|
|
|
{
|
|
|
|
std::basic_ostringstream<charT,traits> s;
|
|
|
|
s.copyfmt(out);
|
|
|
|
s.width(0);
|
2012-08-02 01:40:06 +02:00
|
|
|
s << "box2d(" << std::fixed << std::setprecision(16)
|
2012-03-06 18:12:45 +01:00
|
|
|
<< e.minx() << ',' << e.miny() << ','
|
|
|
|
<< e.maxx() << ',' << e.maxy() << ')';
|
2010-06-02 13:03:30 +02:00
|
|
|
out << s.str();
|
|
|
|
return out;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2006-10-04 13:22:18 +02:00
|
|
|
|
2009-12-16 21:02:06 +01:00
|
|
|
#endif // MAPNIK_BOX2D_HPP
|