![]() |
User Manual, Developers Guide and API Documentation |
![]() |
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 "AxisParallelRectangle.hpp" 00029 #include "LineSegment.hpp" 00030 #include "AABoundingBox.hpp" 00031 00032 using namespace wns::geometry; 00033 00034 AxisParallelRectangle::AxisParallelRectangle() 00035 :Shape2D(Point(0,0,0),Point(0,0,0)) 00036 {} 00037 00038 AxisParallelRectangle::AxisParallelRectangle(const Point& a, const Point& b) 00039 : Shape2D(a,b) 00040 { 00041 boundingBox = AABoundingBox(a, b); 00042 } 00043 00044 AxisParallelRectangle::AxisParallelRectangle(const Point& a, const Vector& db) 00045 : Shape2D(a, a + db) 00046 { 00047 boundingBox = AABoundingBox(a, a + db); 00048 } 00049 00050 AxisParallelRectangle::AxisParallelRectangle(const wns::pyconfig::View& config) 00051 : Shape2D(wns::geometry::Point(config.getView("pointA")), 00052 wns::geometry::Point(config.getView("pointB"))) 00053 { 00054 boundingBox = AABoundingBox(wns::geometry::Point(config.getView("pointA")), 00055 wns::geometry::Point(config.getView("pointB"))); 00056 } 00057 00058 bool 00059 AxisParallelRectangle::contains(const Point& point) const 00060 { 00061 return boundingBox.contains(point); 00062 } 00063 00064 bool 00065 AxisParallelRectangle::contains(const AxisParallelRectangle& other) const 00066 { 00067 return boundingBox.contains(other.boundingBox); 00068 } 00069 00070 bool 00071 AxisParallelRectangle::intersects(const AxisParallelRectangle& other) const 00072 { 00073 return intersectsBoundingBoxOf(other); 00074 } 00075 00076 bool 00077 AxisParallelRectangle::intersects(const LineSegment& line) const 00078 { 00079 if (intersectsBoundingBoxOf(line)) { 00080 if (contains(line.getA()) || contains(line.getB())) return true; 00081 else return bordersIntersect(line); 00082 } else return false; 00083 } 00084 00085 unsigned int 00086 AxisParallelRectangle::countBorderIntersections(const LineSegment& line) const 00087 { 00088 if (intersectsBoundingBoxOf(line)) { 00089 if (contains(line.getA()) xor contains(line.getB())) return 1; 00090 else if (bordersIntersect(line)) return 2; 00091 else return 0; 00092 } else return 0; 00093 } 00094 00095 bool 00096 AxisParallelRectangle::bordersIntersect(const LineSegment& line) const 00097 { 00098 const double& x1 = boundingBox.a.getX(); 00099 const double& x2 = boundingBox.b.getX(); 00100 const double& y1 = boundingBox.a.getY(); 00101 const double& y2 = boundingBox.b.getY(); 00102 00103 const Point A(x1, y1, 0); 00104 const Point B(x2, y1, 0); 00105 const Point C(x2, y2, 0); 00106 const Point D(x1, y2, 0); 00107 00108 const LineSegment a(A, B); 00109 const LineSegment b(B, C); 00110 const LineSegment c(C, D); 00111 const LineSegment d(D, A); 00112 00113 return a.intersects(line) || b.intersects(line) 00114 || c.intersects(line) || d.intersects(line); 00115 } 00116 00117
1.5.5