/***************************************************************************** * * 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 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 #if !defined(__SUNPRO_CC) inline #endif bool Envelope::operator==(const Envelope& other) const { return minx_==other.minx_ && miny_==other.miny_ && maxx_==other.maxx_ && maxy_==other.maxy_; } template #if !defined(__SUNPRO_CC) inline #endif T Envelope::minx() const { return minx_; } template #if !defined(__SUNPRO_CC) inline #endif T Envelope::maxx() const { return maxx_; } template #if !defined(__SUNPRO_CC) inline #endif T Envelope::miny() const { return miny_; } template #if !defined(__SUNPRO_CC) inline #endif T Envelope::maxy() const { return maxy_; } template #if !defined(__SUNPRO_CC) inline #endif T Envelope::width() const { return maxx_-minx_; } template #if !defined(__SUNPRO_CC) inline #endif T Envelope::height() const { return maxy_-miny_; } template #if !defined(__SUNPRO_CC) inline #endif void Envelope::width(T w) { T cx=center().x; minx_=static_cast(cx-w*0.5); maxx_=static_cast(cx+w*0.5); } template #if !defined(__SUNPRO_CC) inline #endif void Envelope::height(T h) { T cy=center().y; miny_=static_cast(cy-h*0.5); maxy_=static_cast(cy+h*0.5); } template #if !defined(__SUNPRO_CC) inline #endif coord Envelope::center() const { return coord(static_cast(0.5*(minx_+maxx_)), static_cast(0.5*(miny_+maxy_))); } template #if !defined(__SUNPRO_CC) inline #endif void Envelope::expand_to_include(const coord& c) { expand_to_include(c.x,c.y); } template #if !defined(__SUNPRO_CC) inline #endif 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 #if !defined(__SUNPRO_CC) inline #endif bool Envelope::contains(const coord &c) const { return contains(c.x,c.y); } template #if !defined(__SUNPRO_CC) inline #endif bool Envelope::contains(T x,T y) const { return x>=minx_ && x<=maxx_ && y>=miny_ && y<=maxy_; } template #if !defined(__SUNPRO_CC) inline #endif bool Envelope::contains(const Envelope &other) const { return other.minx_>=minx_ && other.maxx_<=maxx_ && other.miny_>=miny_ && other.maxy_<=maxy_; } template #if !defined(__SUNPRO_CC) inline #endif bool Envelope::intersects(const coord &c) const { return intersects(c.x,c.y); } template #if !defined(__SUNPRO_CC) inline #endif bool Envelope::intersects(T x,T y) const { return !(x>maxx_ || xmaxy_ || y #if !defined(__SUNPRO_CC) inline #endif bool Envelope::intersects(const Envelope &other) const { return !(other.minx_>maxx_ || other.maxx_maxy_ || other.maxy_ #if !defined(__SUNPRO_CC) inline #endif 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 #if !defined(__SUNPRO_CC) inline #endif 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 #if !defined(__SUNPRO_CC) inline #endif void Envelope::init(T x0,T y0,T x1,T y1) { if (x0 Envelope& Envelope::operator+=(Envelope const& other) { expand_to_include(other); return *this; } template Envelope& Envelope::operator-=(Envelope const& other) { // not sure what to do here. intersect? return *this; } template Envelope& Envelope::operator*=(T t) { minx_ *= t; miny_ *= t; maxx_ *= t; maxy_ *= t; return *this; } template Envelope& Envelope::operator/=(T t) { minx_ /= t; miny_ /= t; maxx_ /= t; maxy_ /= t; return *this; } template class Envelope; template class Envelope; }