/***************************************************************************** * * This file is part of Mapnik (c++ mapping toolkit) * * Copyright (C) 2006 Artem Pavlenko * * 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, * but WITHOUT ANY WARRANTY; without even the implied warranty of * 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 * *****************************************************************************/ //$Id: envelope.cpp 17 2005-03-08 23:58:43Z pavlenko $ #include "envelope.hpp" namespace mapnik { template Envelope::Envelope() :minx_(0),miny_(0),maxx_(-1),maxy_(-1) {} template Envelope::Envelope(T minx_,T miny_,T maxx_,T maxy_) { init(minx_,miny_,maxx_,maxy_); } template Envelope::Envelope(const coord &c0,const coord &c1) { init(c0.x,c0.y,c1.x,c1.y); } template Envelope::Envelope(const Envelope &rhs) { init(rhs.minx_,rhs.miny_,rhs.maxx_,rhs.maxy_); } template inline bool Envelope::operator==(const Envelope& other) const { return minx_==other.minx_ && miny_==other.miny_ && maxx_==other.maxx_ && maxy_==other.maxy_; } template inline T Envelope::minx() const { return minx_; } template inline T Envelope::maxx() const { return maxx_; } template inline T Envelope::miny() const { return miny_; } template inline T Envelope::maxy() const { return maxy_; } template inline T Envelope::width() const { return maxx_-minx_; } template inline T Envelope::height() const { return maxy_-miny_; } template inline void Envelope::width(T w) { T cx=center().x; minx_=static_cast(cx-w*0.5); maxx_=static_cast(cx+w*0.5); } template inline void Envelope::height(T h) { T cy=center().y; miny_=static_cast(cy-h*0.5); maxy_=static_cast(cy+h*0.5); } template inline coord Envelope::center() const { return coord(static_cast(0.5*(minx_+maxx_)), static_cast(0.5*(miny_+maxy_))); } template inline void Envelope::expand_to_include(const coord& c) { expand_to_include(c.x,c.y); } template inline void Envelope::expand_to_include(T x,T y) { if (xmaxx_) maxx_=x; if (ymaxy_) maxy_=y; } template void Envelope::expand_to_include(const Envelope &other) { if (other.minx_maxx_) maxx_=other.maxx_; if (other.miny_maxy_) maxy_=other.maxy_; } template inline bool Envelope::contains(const coord &c) const { return contains(c.x,c.y); } template inline bool Envelope::contains(T x,T y) const { return x>=minx_ && x<=maxx_ && y>=miny_ && y<=maxy_; } template inline bool Envelope::contains(const Envelope &other) const { return other.minx_>=minx_ && other.maxx_<=maxx_ && other.miny_>=miny_ && other.maxy_<=maxy_; } template inline bool Envelope::intersects(const coord &c) const { return intersects(c.x,c.y); } template bool Envelope::intersects(T x,T y) const { return !(x>maxx_ || xmaxy_ || y inline bool Envelope::intersects(const Envelope &other) const { return !(other.minx_>maxx_ || other.maxx_maxy_ || other.maxy_ inline Envelope Envelope::intersect(const EnvelopeType& other) const { 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 Envelope(x0,y0,x1,y1); } template inline void Envelope::re_center(T cx,T cy) { T dx=cx-center().x; T dy=cy-center().y; minx_+=dx; miny_+=dy; maxx_+=dx; maxy_+=dy; } template inline void Envelope::init(T x0,T y0,T x1,T y1) { if (x0; template class Envelope; }