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
|
|
|
*
|
2015-06-16 12:49:16 +02:00
|
|
|
* Copyright (C) 2015 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.
|
2005-06-14 17:06:59 +02:00
|
|
|
*
|
2006-03-31 12:32:02 +02:00
|
|
|
* 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
|
|
|
|
2012-04-06 22:39:13 +02:00
|
|
|
// mapnik
|
2009-12-16 21:02:06 +01:00
|
|
|
#include <mapnik/box2d.hpp>
|
2015-06-16 05:25:39 +02:00
|
|
|
#include <mapnik/safe_cast.hpp>
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-09-16 16:41:29 +02:00
|
|
|
// stl
|
|
|
|
#include <stdexcept>
|
2014-09-29 22:49:56 +02:00
|
|
|
#include <sstream>
|
|
|
|
#include <iomanip>
|
2010-09-16 16:41:29 +02:00
|
|
|
|
2015-11-08 02:53:09 +01:00
|
|
|
#include <mapnik/config.hpp>
|
|
|
|
|
2014-10-22 01:37:27 +02:00
|
|
|
#pragma GCC diagnostic push
|
2015-11-08 02:53:09 +01:00
|
|
|
#include <mapnik/warning_ignore.hpp>
|
2013-09-19 04:04:20 +02:00
|
|
|
#include <boost/fusion/include/adapt_adt.hpp>
|
2012-04-06 22:39:13 +02:00
|
|
|
#include <boost/spirit/include/qi.hpp>
|
2013-09-19 04:04:20 +02:00
|
|
|
#include <boost/spirit/include/support_adapt_adt_attributes.hpp>
|
2014-10-22 01:37:27 +02:00
|
|
|
#pragma GCC diagnostic pop
|
2010-11-14 15:38:43 +01:00
|
|
|
|
2012-03-06 18:12:45 +01:00
|
|
|
// agg
|
|
|
|
#include "agg_trans_affine.h"
|
|
|
|
|
2013-09-19 04:04:20 +02:00
|
|
|
BOOST_FUSION_ADAPT_TPL_ADT(
|
|
|
|
(T),
|
|
|
|
(mapnik::box2d)(T),
|
2015-06-16 05:25:39 +02:00
|
|
|
(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))))
|
2013-09-19 04:04:20 +02:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
namespace mapnik
|
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
box2d<T>::box2d()
|
2015-11-11 16:50:56 +01:00
|
|
|
:minx_( std::numeric_limits<T>::max()),
|
|
|
|
miny_( std::numeric_limits<T>::max()),
|
|
|
|
maxx_(-std::numeric_limits<T>::max()),
|
|
|
|
maxy_(-std::numeric_limits<T>::max()) {}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
2013-01-03 21:37:45 +01:00
|
|
|
box2d<T>::box2d(T minx,T miny,T maxx,T maxy)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2013-01-03 21:37:45 +01:00
|
|
|
init(minx,miny,maxx,maxy);
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
2013-09-19 04:04:20 +02:00
|
|
|
box2d<T>::box2d(coord<T,2> const& c0, coord<T,2> const& c1)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
init(c0.x,c0.y,c1.x,c1.y);
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
2013-09-19 04:04:20 +02:00
|
|
|
box2d<T>::box2d(box2d_type const& rhs)
|
2011-04-14 21:26:49 +02:00
|
|
|
: minx_(rhs.minx_),
|
|
|
|
miny_(rhs.miny_),
|
|
|
|
maxx_(rhs.maxx_),
|
|
|
|
maxy_(rhs.maxy_) {}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2013-09-20 05:19:01 +02:00
|
|
|
template <typename T>
|
|
|
|
box2d<T>::box2d(box2d_type && rhs)
|
|
|
|
: minx_(std::move(rhs.minx_)),
|
|
|
|
miny_(std::move(rhs.miny_)),
|
|
|
|
maxx_(std::move(rhs.maxx_)),
|
|
|
|
maxy_(std::move(rhs.maxy_)) {}
|
|
|
|
|
2012-03-06 18:12:45 +01:00
|
|
|
template <typename T>
|
2013-09-19 04:04:20 +02:00
|
|
|
box2d<T>& box2d<T>::operator=(box2d_type other)
|
|
|
|
{
|
2014-05-27 12:21:13 +02:00
|
|
|
swap(*this, other);
|
2013-09-19 04:04:20 +02:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
box2d<T>::box2d(box2d_type const& rhs, agg::trans_affine const& tr)
|
2012-03-06 18:12:45 +01:00
|
|
|
{
|
|
|
|
double x0 = rhs.minx_, y0 = rhs.miny_;
|
|
|
|
double x1 = rhs.maxx_, y1 = rhs.miny_;
|
|
|
|
double x2 = rhs.maxx_, y2 = rhs.maxy_;
|
|
|
|
double x3 = rhs.minx_, y3 = rhs.maxy_;
|
|
|
|
tr.transform(&x0, &y0);
|
|
|
|
tr.transform(&x1, &y1);
|
|
|
|
tr.transform(&x2, &y2);
|
|
|
|
tr.transform(&x3, &y3);
|
2013-09-19 04:04:20 +02:00
|
|
|
init(static_cast<T>(x0), static_cast<T>(y0),
|
|
|
|
static_cast<T>(x2), static_cast<T>(y2));
|
|
|
|
expand_to_include(static_cast<T>(x1), static_cast<T>(y1));
|
|
|
|
expand_to_include(static_cast<T>(x3), static_cast<T>(y3));
|
2012-03-06 18:12:45 +01:00
|
|
|
}
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
2013-09-19 04:04:20 +02:00
|
|
|
bool box2d<T>::operator==(box2d<T> const& other) const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
return minx_==other.minx_ &&
|
|
|
|
miny_==other.miny_ &&
|
|
|
|
maxx_==other.maxx_ &&
|
|
|
|
maxy_==other.maxy_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
T box2d<T>::minx() const
|
|
|
|
{
|
|
|
|
return minx_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
T box2d<T>::maxx() const
|
|
|
|
{
|
|
|
|
return maxx_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
T box2d<T>::miny() const
|
|
|
|
{
|
|
|
|
return miny_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
T box2d<T>::maxy() const
|
|
|
|
{
|
|
|
|
return maxy_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2013-03-06 22:09:15 +01:00
|
|
|
template<typename T>
|
|
|
|
void box2d<T>::set_minx(T v)
|
|
|
|
{
|
|
|
|
minx_ = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void box2d<T>::set_miny(T v)
|
|
|
|
{
|
|
|
|
miny_ = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void box2d<T>::set_maxx(T v)
|
|
|
|
{
|
|
|
|
maxx_ = v;
|
|
|
|
}
|
|
|
|
|
|
|
|
template<typename T>
|
|
|
|
void box2d<T>::set_maxy(T v)
|
|
|
|
{
|
|
|
|
maxy_ = v;
|
|
|
|
}
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
T box2d<T>::width() const
|
|
|
|
{
|
|
|
|
return maxx_-minx_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
T box2d<T>::height() const
|
|
|
|
{
|
|
|
|
return maxy_-miny_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
void box2d<T>::width(T w)
|
|
|
|
{
|
|
|
|
T cx=center().x;
|
|
|
|
minx_=static_cast<T>(cx-w*0.5);
|
|
|
|
maxx_=static_cast<T>(cx+w*0.5);
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
void box2d<T>::height(T h)
|
|
|
|
{
|
|
|
|
T cy=center().y;
|
|
|
|
miny_=static_cast<T>(cy-h*0.5);
|
|
|
|
maxy_=static_cast<T>(cy+h*0.5);
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
coord<T,2> box2d<T>::center() const
|
|
|
|
{
|
|
|
|
return coord<T,2>(static_cast<T>(0.5*(minx_+maxx_)),
|
|
|
|
static_cast<T>(0.5*(miny_+maxy_)));
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
2013-09-19 04:04:20 +02:00
|
|
|
void box2d<T>::expand_to_include(coord<T,2> const& c)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
expand_to_include(c.x,c.y);
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
void box2d<T>::expand_to_include(T x,T y)
|
|
|
|
{
|
|
|
|
if (x<minx_) minx_=x;
|
|
|
|
if (x>maxx_) maxx_=x;
|
|
|
|
if (y<miny_) miny_=y;
|
|
|
|
if (y>maxy_) maxy_=y;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
2013-09-19 04:04:20 +02:00
|
|
|
void box2d<T>::expand_to_include(box2d<T> const& other)
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
if (other.minx_<minx_) minx_=other.minx_;
|
|
|
|
if (other.maxx_>maxx_) maxx_=other.maxx_;
|
|
|
|
if (other.miny_<miny_) miny_=other.miny_;
|
|
|
|
if (other.maxy_>maxy_) maxy_=other.maxy_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
2013-09-19 04:04:20 +02:00
|
|
|
bool box2d<T>::contains(coord<T,2> const& c) const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
return contains(c.x,c.y);
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
bool box2d<T>::contains(T x,T y) const
|
|
|
|
{
|
|
|
|
return x>=minx_ && x<=maxx_ && y>=miny_ && y<=maxy_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
2013-09-19 04:04:20 +02:00
|
|
|
bool box2d<T>::contains(box2d<T> const& other) const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
return other.minx_>=minx_ &&
|
|
|
|
other.maxx_<=maxx_ &&
|
|
|
|
other.miny_>=miny_ &&
|
|
|
|
other.maxy_<=maxy_;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
2013-09-19 04:04:20 +02:00
|
|
|
bool box2d<T>::intersects(coord<T,2> const& c) const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
return intersects(c.x,c.y);
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
bool box2d<T>::intersects(T x,T y) const
|
|
|
|
{
|
|
|
|
return !(x>maxx_ || x<minx_ || y>maxy_ || y<miny_);
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
2013-09-19 04:04:20 +02:00
|
|
|
bool box2d<T>::intersects(box2d<T> const& other) const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
|
|
|
return !(other.minx_>maxx_ || other.maxx_<minx_ ||
|
|
|
|
other.miny_>maxy_ || other.maxy_<miny_);
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
2013-09-19 04:04:20 +02:00
|
|
|
box2d<T> box2d<T>::intersect(box2d_type const& other) const
|
2010-06-02 13:03:30 +02:00
|
|
|
{
|
2015-11-11 16:50:56 +01:00
|
|
|
if (intersects(other))
|
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
T x0=std::max(minx_,other.minx_);
|
|
|
|
T y0=std::max(miny_,other.miny_);
|
|
|
|
T x1=std::min(maxx_,other.maxx_);
|
|
|
|
T y1=std::min(maxy_,other.maxy_);
|
|
|
|
return box2d<T>(x0,y0,x1,y1);
|
2015-11-11 16:50:56 +01:00
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
return box2d<T>();
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
void box2d<T>::re_center(T cx,T cy)
|
|
|
|
{
|
|
|
|
T dx=cx-center().x;
|
|
|
|
T dy=cy-center().y;
|
|
|
|
minx_+=dx;
|
|
|
|
miny_+=dy;
|
|
|
|
maxx_+=dx;
|
|
|
|
maxy_+=dy;
|
|
|
|
}
|
2005-06-14 17:06:59 +02:00
|
|
|
|
2010-08-19 23:35:27 +02:00
|
|
|
template <typename T>
|
2013-09-19 04:04:20 +02:00
|
|
|
void box2d<T>::re_center(coord<T,2> const& c)
|
2010-08-19 23:35:27 +02:00
|
|
|
{
|
|
|
|
re_center(c.x,c.y);
|
|
|
|
}
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
void box2d<T>::init(T x0,T y0,T x1,T y1)
|
|
|
|
{
|
|
|
|
if (x0<x1)
|
2005-06-14 17:06:59 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
minx_=x0;maxx_=x1;
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
else
|
2006-10-16 15:31:52 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
minx_=x1;maxx_=x0;
|
2006-10-16 15:31:52 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
if (y0<y1)
|
2006-10-16 15:31:52 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
miny_=y0;maxy_=y1;
|
2006-10-16 15:31:52 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
else
|
2006-10-16 15:31:52 +02:00
|
|
|
{
|
2010-06-02 13:03:30 +02:00
|
|
|
miny_=y1;maxy_=y0;
|
2006-10-16 15:31:52 +02:00
|
|
|
}
|
2010-06-02 13:03:30 +02:00
|
|
|
}
|
2010-11-14 15:38:43 +01:00
|
|
|
|
2011-04-13 21:19:23 +02:00
|
|
|
template <typename T>
|
2013-09-19 04:04:20 +02:00
|
|
|
void box2d<T>::clip(box2d_type const& other)
|
2011-04-13 21:19:23 +02:00
|
|
|
{
|
2012-02-02 02:53:35 +01:00
|
|
|
minx_ = std::max(minx_,other.minx());
|
|
|
|
miny_ = std::max(miny_,other.miny());
|
|
|
|
maxx_ = std::min(maxx_,other.maxx());
|
|
|
|
maxy_ = std::min(maxy_,other.maxy());
|
2011-04-13 21:19:23 +02:00
|
|
|
}
|
|
|
|
|
2012-12-11 22:56:25 +01:00
|
|
|
template <typename T>
|
|
|
|
void box2d<T>::pad(T padding)
|
|
|
|
{
|
|
|
|
minx_ -= padding;
|
|
|
|
miny_ -= padding;
|
|
|
|
maxx_ += padding;
|
|
|
|
maxy_ += padding;
|
|
|
|
}
|
2011-04-13 21:19:23 +02:00
|
|
|
|
2013-09-19 04:04:20 +02:00
|
|
|
|
2010-11-14 15:38:43 +01:00
|
|
|
template <typename T>
|
2013-09-19 04:04:20 +02:00
|
|
|
bool box2d<T>::from_string(std::string const& str)
|
2010-11-14 15:38:43 +01:00
|
|
|
{
|
2014-01-26 23:00:58 +01:00
|
|
|
boost::spirit::qi::lit_type lit;
|
|
|
|
boost::spirit::qi::double_type double_;
|
|
|
|
boost::spirit::ascii::space_type space;
|
2013-09-19 04:04:20 +02:00
|
|
|
bool r = boost::spirit::qi::phrase_parse(str.begin(),
|
|
|
|
str.end(),
|
|
|
|
double_ >> -lit(',') >> double_ >> -lit(',')
|
|
|
|
>> double_ >> -lit(',') >> double_,
|
|
|
|
space,
|
|
|
|
*this);
|
|
|
|
return r;
|
2010-11-14 15:38:43 +01:00
|
|
|
}
|
2011-04-04 05:50:09 +02:00
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
bool box2d<T>::valid() const
|
|
|
|
{
|
|
|
|
return (minx_ <= maxx_ && miny_ <= maxy_) ;
|
|
|
|
}
|
|
|
|
|
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
|
|
|
template <typename T>
|
|
|
|
void box2d<T>::move(T x, T y)
|
|
|
|
{
|
|
|
|
minx_ += x;
|
|
|
|
maxx_ += x;
|
|
|
|
miny_ += y;
|
|
|
|
maxy_ += y;
|
|
|
|
}
|
|
|
|
|
2014-09-29 22:49:56 +02:00
|
|
|
template <typename T>
|
|
|
|
std::string box2d<T>::to_string() const
|
|
|
|
{
|
|
|
|
std::ostringstream s;
|
2016-03-07 13:51:50 +01:00
|
|
|
if (valid())
|
|
|
|
{
|
|
|
|
s << "box2d(" << std::fixed << std::setprecision(16)
|
|
|
|
<< minx_ << ',' << miny_ << ','
|
|
|
|
<< maxx_ << ',' << maxy_ << ')';
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
s << "box2d(INVALID)";
|
|
|
|
}
|
2014-09-29 22:49:56 +02:00
|
|
|
return s.str();
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template <typename T>
|
|
|
|
box2d<T>& box2d<T>::operator+=(box2d<T> const& other)
|
|
|
|
{
|
|
|
|
expand_to_include(other);
|
|
|
|
return *this;
|
|
|
|
}
|
2011-04-04 05:50:09 +02:00
|
|
|
|
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
|
|
|
template <typename T>
|
|
|
|
box2d<T> box2d<T>::operator+ (T other) const
|
|
|
|
{
|
|
|
|
return box2d<T>(minx_ - other, miny_ - other, maxx_ + other, maxy_ + other);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
box2d<T>& box2d<T>::operator+= (T other)
|
|
|
|
{
|
|
|
|
minx_ -= other;
|
|
|
|
miny_ -= other;
|
|
|
|
maxx_ += other;
|
|
|
|
maxy_ += other;
|
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
|
|
|
|
template <typename T>
|
2010-06-02 13:03:30 +02:00
|
|
|
box2d<T>& box2d<T>::operator*=(T t)
|
|
|
|
{
|
|
|
|
coord<T,2> c = center();
|
|
|
|
T sx = static_cast<T>(0.5 * width() * t);
|
|
|
|
T sy = static_cast<T>(0.5 * height() * t);
|
|
|
|
minx_ = c.x - sx;
|
|
|
|
maxx_ = c.x + sx;
|
|
|
|
miny_ = c.y - sy;
|
|
|
|
maxy_ = c.y + sy;
|
|
|
|
return *this;
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
|
|
|
template <typename T>
|
2010-06-02 13:03:30 +02:00
|
|
|
box2d<T>& box2d<T>::operator/=(T t)
|
|
|
|
{
|
|
|
|
coord<T,2> c = center();
|
|
|
|
T sx = static_cast<T>(0.5 * width() / t);
|
|
|
|
T sy = static_cast<T>(0.5 * height() / t);
|
|
|
|
minx_ = c.x - sx;
|
|
|
|
maxx_ = c.x + sx;
|
|
|
|
miny_ = c.y - sy;
|
|
|
|
maxy_ = c.y + sy;
|
|
|
|
return *this;
|
|
|
|
}
|
2010-09-16 16:41:29 +02:00
|
|
|
|
2012-02-02 02:53:35 +01:00
|
|
|
template <typename T>
|
2010-09-16 16:41:29 +02:00
|
|
|
T box2d<T>::operator[] (int index) const
|
|
|
|
{
|
|
|
|
switch(index)
|
|
|
|
{
|
|
|
|
case 0:
|
|
|
|
return minx_;
|
|
|
|
case 1:
|
|
|
|
return miny_;
|
|
|
|
case 2:
|
|
|
|
return maxx_;
|
|
|
|
case 3:
|
|
|
|
return maxy_;
|
|
|
|
case -4:
|
|
|
|
return minx_;
|
|
|
|
case -3:
|
|
|
|
return miny_;
|
|
|
|
case -2:
|
|
|
|
return maxx_;
|
|
|
|
case -1:
|
|
|
|
return maxy_;
|
|
|
|
default:
|
|
|
|
throw std::out_of_range("index out of range, max value is 3, min value is -4 ");
|
|
|
|
}
|
|
|
|
}
|
2012-02-02 02:53:35 +01:00
|
|
|
|
2012-03-06 18:12:45 +01:00
|
|
|
template <typename T>
|
|
|
|
box2d<T> box2d<T>::operator*(agg::trans_affine const& tr) const
|
|
|
|
{
|
|
|
|
return box2d<T>(*this, tr);
|
|
|
|
}
|
|
|
|
|
|
|
|
template <typename T>
|
|
|
|
box2d<T>& box2d<T>::operator*=(agg::trans_affine const& tr)
|
|
|
|
{
|
|
|
|
double x0 = minx_, y0 = miny_;
|
|
|
|
double x1 = maxx_, y1 = miny_;
|
|
|
|
double x2 = maxx_, y2 = maxy_;
|
|
|
|
double x3 = minx_, y3 = maxy_;
|
|
|
|
tr.transform(&x0, &y0);
|
|
|
|
tr.transform(&x1, &y1);
|
|
|
|
tr.transform(&x2, &y2);
|
|
|
|
tr.transform(&x3, &y3);
|
2013-09-19 04:04:20 +02:00
|
|
|
init(static_cast<T>(x0), static_cast<T>(y0),
|
|
|
|
static_cast<T>(x2), static_cast<T>(y2));
|
|
|
|
expand_to_include(static_cast<T>(x1), static_cast<T>(y1));
|
|
|
|
expand_to_include(static_cast<T>(x3), static_cast<T>(y3));
|
2012-03-06 18:12:45 +01:00
|
|
|
return *this;
|
|
|
|
}
|
|
|
|
|
2010-06-02 13:03:30 +02:00
|
|
|
template class box2d<int>;
|
|
|
|
template class box2d<double>;
|
2014-05-27 12:21:13 +02:00
|
|
|
|
2005-06-14 17:06:59 +02:00
|
|
|
}
|