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
|
|
|
*
|
2010-11-14 15:38:43 +01:00
|
|
|
* Copyright (C) 2010 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
|
|
|
//$Id: box2d.hpp 39 2005-04-10 20:39:53Z pavlenko $
|
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>
|
2007-10-08 20:10:31 +02:00
|
|
|
// boost
|
|
|
|
#include <boost/operators.hpp>
|
|
|
|
// stl
|
|
|
|
#include <iomanip>
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2006-10-04 13:22:18 +02:00
|
|
|
namespace mapnik {
|
2009-03-01 22:09:09 +01:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
/*!
|
|
|
|
* A spatial envelope (i.e. bounding box) which also defines some basic operators.
|
|
|
|
*/
|
2011-06-07 23:16:03 +02:00
|
|
|
template <typename T> class MAPNIK_DECL box2d
|
|
|
|
: boost::equality_comparable<box2d<T> ,
|
|
|
|
boost::addable<box2d<T>,
|
2011-10-19 16:14:01 +02:00
|
|
|
boost::dividable2<box2d<T>, T,
|
|
|
|
boost::multipliable2<box2d<T>, T > > > >
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
public:
|
|
|
|
typedef box2d<T> box2d_type;
|
|
|
|
private:
|
|
|
|
T minx_;
|
|
|
|
T miny_;
|
|
|
|
T maxx_;
|
|
|
|
T maxy_;
|
|
|
|
public:
|
|
|
|
box2d();
|
|
|
|
box2d(T minx,T miny,T maxx,T maxy);
|
|
|
|
box2d(const coord<T,2>& c0,const coord<T,2>& c1);
|
|
|
|
box2d(const box2d_type& rhs);
|
|
|
|
T minx() const;
|
|
|
|
T miny() const;
|
|
|
|
T maxx() const;
|
|
|
|
T maxy() const;
|
|
|
|
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);
|
|
|
|
void expand_to_include(const coord<T,2>& c);
|
|
|
|
void expand_to_include(const box2d_type& other);
|
|
|
|
bool contains(const coord<T,2> &c) const;
|
|
|
|
bool contains(T x,T y) const;
|
|
|
|
bool contains(const box2d_type &other) const;
|
|
|
|
bool intersects(const coord<T,2> &c) const;
|
|
|
|
bool intersects(T x,T y) const;
|
|
|
|
bool intersects(const box2d_type &other) const;
|
|
|
|
box2d_type intersect(const box2d_type& other) const;
|
|
|
|
bool operator==(const box2d_type &other) const;
|
|
|
|
void re_center(T cx,T cy);
|
2010-08-19 23:35:27 +02:00
|
|
|
void re_center(const coord<T,2>& c);
|
2010-06-02 13:03:30 +02:00
|
|
|
void init(T x0,T y0,T x1,T y1);
|
2011-04-13 21:19:23 +02:00
|
|
|
void clip(const box2d_type &other);
|
2010-11-14 15:38:43 +01:00
|
|
|
bool from_string(const std::string& s);
|
2011-04-04 05:50:09 +02:00
|
|
|
bool valid() const;
|
2006-10-16 15:31:52 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
// define some operators
|
|
|
|
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;
|
2010-06-02 13:03:30 +02:00
|
|
|
};
|
2005-08-31 21:43:37 +02: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);
|
|
|
|
s <<"box2d(" << std::setprecision(16)
|
|
|
|
<< e.minx() << "," << e.miny() <<","
|
|
|
|
<< e.maxx() << "," << e.maxy() <<")";
|
|
|
|
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
|