User Manual, Developers Guide and API Documentation

AABoundingBox.cpp

Go to the documentation of this file.
00001 /*******************************************************************************
00002  * This file is part of openWNS (open Wireless Network Simulator)
00003  * _____________________________________________________________________________
00004  *
00005  * Copyright (C) 2004-2007
00006  * Chair of Communication Networks (ComNets)
00007  * Kopernikusstr. 5, D-52074 Aachen, Germany
00008  * phone: ++49-241-80-27910,
00009  * fax: ++49-241-80-22242
00010  * email: info@openwns.org
00011  * www: http://www.openwns.org
00012  * _____________________________________________________________________________
00013  *
00014  * openWNS is free software; you can redistribute it and/or modify it under the
00015  * terms of the GNU Lesser General Public License version 2 as published by the
00016  * Free Software Foundation;
00017  *
00018  * openWNS is distributed in the hope that it will be useful, but WITHOUT ANY
00019  * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
00020  * A PARTICULAR PURPOSE.  See the GNU Lesser General Public License for more
00021  * details.
00022  *
00023  * You should have received a copy of the GNU Lesser General Public License
00024  * along with this program.  If not, see <http://www.gnu.org/licenses/>.
00025  *
00026  ******************************************************************************/
00027 
00028 #include "AABoundingBox.hpp"
00029 
00030 using namespace wns::geometry;
00031 
00032 AABoundingBox::AABoundingBox() :
00033     a(),
00034     b()
00035 {}
00036 
00037 AABoundingBox::AABoundingBox(const Point& a, const Point& b) :
00038     a(std::min(a.getX(), b.getX()), std::min(a.getY(), b.getY()), 0),
00039     b(std::max(a.getX(), b.getX()), std::max(a.getY(), b.getY()), 0)
00040 {}
00041 
00042 
00043 // AABoundingBox::AABoundingBox(const std::vector<Point>& vertices) :
00044 //  a(),
00045 //  b()
00046 // {
00047 //  /** @todo: minX, minY, minY, maxY aus allen Points */
00048 // }
00049 
00050 AABoundingBox::~AABoundingBox()
00051 {}
00052 
00053 
00054 bool
00055 AABoundingBox::intersects(const AABoundingBox& other) const
00056 {
00057     const double& ourX1 = a.getX();
00058     const double& ourX2 = b.getX();
00059     const double& ourY1 = a.getY();
00060     const double& ourY2 = b.getY();
00061     const double& theirX1 = other.a.getX();
00062     const double& theirX2 = other.b.getX();
00063     const double& theirY1 = other.a.getY();
00064     const double& theirY2 = other.b.getY();
00065     return (ourX2 >= theirX1)
00066     && (ourX1 <= theirX2)
00067     && (ourY2 >= theirY1)
00068     && (ourY1 <= theirY2);
00069 }
00070 
00071 bool 
00072 AABoundingBox::contains(const Point& other) const
00073 {
00074     const double& ourX1 = a.getX();
00075     const double& ourX2 = b.getX();
00076     const double& ourY1 = a.getY();
00077     const double& ourY2 = b.getY();
00078     const double& theirX = other.getX();
00079     const double& theirY = other.getY();
00080     return (ourX1 <= theirX)
00081     && (ourX2 >= theirX)
00082     && (ourY1 <= theirY)
00083     && (ourY2 >= theirY);
00084 }
00085 
00086 bool 
00087 AABoundingBox::contains(const AABoundingBox other) const
00088 {
00089     const double& ourX1 = a.getX();
00090     const double& ourX2 = b.getX();
00091     const double& ourY1 = a.getY();
00092     const double& ourY2 = b.getY();
00093     const double& theirX1 = other.a.getX();
00094     const double& theirX2 = other.b.getX();
00095     const double& theirY1 = other.a.getY();
00096     const double& theirY2 = other.b.getY();
00097     return (ourX1 <= theirX1)
00098     && (ourX2 >= theirX2)
00099     && (ourY1 <= theirY1)
00100     && (ourY2 >= theirY2);
00101 }
00102 
00103 
00104 
00105 
00106 // Operators
00107 void 
00108 AABoundingBox::operator=(const AABoundingBox& other)
00109 {
00110     a = other.a;
00111     b = other.b;
00112 }
00113 
00114 bool 
00115 AABoundingBox::operator==(const AABoundingBox& other) const
00116 {
00117     return
00118             a == other.a &&
00119             b == other.b;
00120     
00121 }
00122 
00123 bool 
00124 AABoundingBox::operator!=(const AABoundingBox& other) const
00125 {
00126     return !(*this == other);
00127 }
00128 
00129 
00130 
00131 

Generated on Mon May 21 03:31:41 2012 for openWNS by  doxygen 1.5.5