00001 /* -*- Mode: C++; c-file-style: "gnu"; indent-tabs-mode:nil; -*- */ 00002 /* 00003 * Copyright (c) 2007 INRIA 00004 * 00005 * This program is free software; you can redistribute it and/or modify 00006 * it under the terms of the GNU General Public License version 2 as 00007 * published by the Free Software Foundation; 00008 * 00009 * This program is distributed in the hope that it will be useful, 00010 * but WITHOUT ANY WARRANTY; without even the implied warranty of 00011 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 00012 * GNU General Public License for more details. 00013 * 00014 * You should have received a copy of the GNU General Public License 00015 * along with this program; if not, write to the Free Software 00016 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 00017 * 00018 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 00019 */ 00020 #ifndef RECTANGLE_H 00021 #define RECTANGLE_H 00022 00023 #include "ns3/attribute.h" 00024 #include "ns3/attribute-helper.h" 00025 00026 namespace ns3 { 00027 00028 class Vector; 00029 00030 /** 00031 * \brief a 2d rectangle 00032 */ 00033 class Rectangle 00034 { 00035 public: 00036 enum Side { 00037 RIGHT, 00038 LEFT, 00039 TOP, 00040 BOTTOM 00041 }; 00042 /** 00043 * \param _xMin x coordinates of left boundary. 00044 * \param _xMax x coordinates of right boundary. 00045 * \param _yMin y coordinates of bottom boundary. 00046 * \param _yMax y coordinates of top boundary. 00047 * 00048 * Create a rectangle. 00049 */ 00050 Rectangle (double _xMin, double _xMax, 00051 double _yMin, double _yMax); 00052 /** 00053 * Create a zero-sized rectangle located at coordinates (0.0,0.0) 00054 */ 00055 Rectangle (); 00056 /** 00057 * \param position the position to test. 00058 * \returns true if the input position is located within the rectangle, 00059 * false otherwise. 00060 * 00061 * This method compares only the x and y coordinates of the input position. 00062 * It ignores the z coordinate. 00063 */ 00064 bool IsInside (const Vector &position) const; 00065 /** 00066 * \param position the position to test. 00067 * \returns the side of the rectangle the input position is closest to. 00068 * 00069 * This method compares only the x and y coordinates of the input position. 00070 * It ignores the z coordinate. 00071 */ 00072 Side GetClosestSide (const Vector &position) const; 00073 /** 00074 * \param current the current position 00075 * \param speed the current speed 00076 * \returns the intersection point between the rectangle and the current+speed vector. 00077 * 00078 * This method assumes that the current position is located _inside_ 00079 * the rectangle and checks for this with an assert. 00080 * This method compares only the x and y coordinates of the input position 00081 * and speed. It ignores the z coordinate. 00082 */ 00083 Vector CalculateIntersection (const Vector ¤t, const Vector &speed) const; 00084 00085 /* The x coordinate of the left bound of the rectangle */ 00086 double xMin; 00087 /* The x coordinate of the right bound of the rectangle */ 00088 double xMax; 00089 /* The y coordinate of the bottom bound of the rectangle */ 00090 double yMin; 00091 /* The y coordinate of the top bound of the rectangle */ 00092 double yMax; 00093 }; 00094 00095 std::ostream &operator << (std::ostream &os, const Rectangle &rectangle); 00096 std::istream &operator >> (std::istream &is, Rectangle &rectangle); 00097 00098 /** 00099 * \class ns3::RectangleValue 00100 * \brief hold objects of type ns3::Rectangle 00101 */ 00102 00103 ATTRIBUTE_HELPER_HEADER (Rectangle); 00104 00105 } // namespace ns3 00106 00107 #endif /* RECTANGLE_H */