1 /* -*- Mode:C++; c-file-style:"gnu"; indent-tabs-mode:nil; -*- */ 2 /* 3 * Copyright (c) 2007 INRIA 4 * 5 * This program is free software; you can redistribute it and/or modify 6 * it under the terms of the GNU General Public License version 2 as 7 * published by the Free Software Foundation; 8 * 9 * This program is distributed in the hope that it will be useful, 10 * but WITHOUT ANY WARRANTY; without even the implied warranty of 11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 12 * GNU General Public License for more details. 13 * 14 * You should have received a copy of the GNU General Public License 15 * along with this program; if not, write to the Free Software 16 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA 17 * 18 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr> 19 */ 20 #ifndef RECTANGLE_H 21 #define RECTANGLE_H 22 23 #include "ns3/attribute.h" 24 #include "ns3/attribute-helper.h" 25 #include "ns3/vector.h" 26 27 namespace ns3 { 28 29 /** 30 * \ingroup mobility 31 * \brief a 2d rectangle 32 * \see attribute_Rectangle 33 */ 34 class Rectangle 35 { 36 public: 37 /** 38 * enum for naming sides 39 */ 40 enum Side { 41 RIGHT, 42 LEFT, 43 TOP, 44 BOTTOM 45 }; 46 /** 47 * \param _xMin x coordinates of left boundary. 48 * \param _xMax x coordinates of right boundary. 49 * \param _yMin y coordinates of bottom boundary. 50 * \param _yMax y coordinates of top boundary. 51 * 52 * Create a rectangle. 53 */ 54 Rectangle (double _xMin, double _xMax, 55 double _yMin, double _yMax); 56 /** 57 * Create a zero-sized rectangle located at coordinates (0.0,0.0) 58 */ 59 Rectangle (); 60 /** 61 * \param position the position to test. 62 * \return true if the input position is located within the rectangle, false otherwise. 63 * 64 * This method compares only the x and y coordinates of the input position. 65 * It ignores the z coordinate. 66 */ 67 bool IsInside (const Vector &position) const; 68 /** 69 * \param position the position to test. 70 * \return the side of the rectangle the input position is closest to. 71 * 72 * This method compares only the x and y coordinates of the input position. 73 * It ignores the z coordinate. 74 */ 75 Side GetClosestSide (const Vector &position) const; 76 /** 77 * \param current the current position 78 * \param speed the current speed 79 * \return the intersection point between the rectangle and the current+speed vector. 80 * 81 * This method assumes that the current position is located _inside_ 82 * the rectangle and checks for this with an assert. 83 * This method compares only the x and y coordinates of the input position 84 * and speed. It ignores the z coordinate. 85 */ 86 Vector CalculateIntersection (const Vector ¤t, const Vector &speed) const; 87 88 double xMin; //!< The x coordinate of the left bound of the rectangle 89 double xMax; //!< The x coordinate of the right bound of the rectangle 90 double yMin; //!< The y coordinate of the bottom bound of the rectangle 91 double yMax; //!< The y coordinate of the top bound of the rectangle 92 }; 93 94 std::ostream &operator << (std::ostream &os, const Rectangle &rectangle); 95 std::istream &operator >> (std::istream &is, Rectangle &rectangle); 96 97 ATTRIBUTE_HELPER_HEADER (Rectangle); 98 99 } // namespace ns3 100 101 #endif /* RECTANGLE_H */ 102