A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
rectangle.h
Go to the documentation of this file.
1/*
2 * Copyright (c) 2007 INRIA
3 *
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License version 2 as
6 * published by the Free Software Foundation;
7 *
8 * This program is distributed in the hope that it will be useful,
9 * but WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
11 * GNU General Public License for more details.
12 *
13 * You should have received a copy of the GNU General Public License
14 * along with this program; if not, write to the Free Software
15 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
16 *
17 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
18 */
19#ifndef RECTANGLE_H
20#define RECTANGLE_H
21
22#include "ns3/attribute-helper.h"
23#include "ns3/attribute.h"
24#include "ns3/vector.h"
25
26namespace ns3
27{
28
29/**
30 * \ingroup mobility
31 * \brief a 2d rectangle
32 * \see attribute_Rectangle
33 */
35{
36 public:
37 /**
38 * enum for naming sides
39 */
40 enum Side
41 {
50 };
51
52 /**
53 * \param _xMin x coordinates of left boundary.
54 * \param _xMax x coordinates of right boundary.
55 * \param _yMin y coordinates of bottom boundary.
56 * \param _yMax y coordinates of top boundary.
57 *
58 * Create a rectangle.
59 */
60 Rectangle(double _xMin, double _xMax, double _yMin, double _yMax);
61 /**
62 * Create a zero-sized rectangle located at coordinates (0.0,0.0)
63 */
64 Rectangle();
65 /**
66 * \param position the position to test.
67 * \return true if the input position is located within the rectangle, false otherwise.
68 *
69 * This method compares only the x and y coordinates of the input position.
70 * It ignores the z coordinate.
71 */
72 bool IsInside(const Vector& position) const;
73 /**
74 * \param position the position to test.
75 * \return true if the input position is located on the rectable border, false otherwise.
76 *
77 * This method compares only the x and y coordinates of the input position.
78 * It ignores the z coordinate.
79 */
80 bool IsOnTheBorder(const Vector& position) const;
81 /**
82 * \param position the position to test.
83 * \return the side of the rectangle the input position is closest to.
84 *
85 * This method compares only the x and y coordinates of the input position.
86 * It ignores the z coordinate.
87 *
88 * This method assumes assumes a right-handed Cartesian orientation, so that
89 * (xMin, yMin) is the BOTTOMLEFTCORNER, the TOP and BOTTOM sides are parallel to
90 * the x-axis, the LEFT and RIGHT sides are parallel to the y-axis, and the
91 * (xMax, yMax) point is the TOPRIGHTCORNER.
92 *
93 * Beware: the method has an ambiguity in the "center" of the rectangle. Assume
94 * a rectangle between the points (0, 0) and (4, 2), i.e., wider than taller.
95 * All the points on the line between (1, 1) and (3, 1) are equally closer to the
96 * TOP and BOTTOM than to the other sides of the Rectangle.
97 * These points are classified as TOPSIDE by convention.
98 *
99 * Similarly, for a Rectangle taller than wider, the "center" points will be
100 * classified as RIGHTSIDE, and for a square box, the center will return RIGHTSIDE.
101 */
102 Side GetClosestSideOrCorner(const Vector& position) const;
103 /**
104 * \param current the current position
105 * \param speed the current speed
106 * \return the intersection point between the rectangle and the current+speed vector.
107 *
108 * This method assumes that the current position is located _inside_
109 * the rectangle and checks for this with an assert.
110 * This method compares only the x and y coordinates of the input position
111 * and speed. It ignores the z coordinate.
112 */
113 Vector CalculateIntersection(const Vector& current, const Vector& speed) const;
114
115 double xMin; //!< The x coordinate of the left bound of the rectangle
116 double xMax; //!< The x coordinate of the right bound of the rectangle
117 double yMin; //!< The y coordinate of the bottom bound of the rectangle
118 double yMax; //!< The y coordinate of the top bound of the rectangle
119};
120
121std::ostream& operator<<(std::ostream& os, const Rectangle& rectangle);
122std::istream& operator>>(std::istream& is, Rectangle& rectangle);
123std::ostream& operator<<(std::ostream& os, const Rectangle::Side& side);
124
126
127} // namespace ns3
128
129#endif /* RECTANGLE_H */
a 2d rectangle
Definition: rectangle.h:35
double yMax
The y coordinate of the top bound of the rectangle.
Definition: rectangle.h:118
Side GetClosestSideOrCorner(const Vector &position) const
Definition: rectangle.cc:64
bool IsInside(const Vector &position) const
Definition: rectangle.cc:50
bool IsOnTheBorder(const Vector &position) const
Definition: rectangle.cc:57
double xMax
The x coordinate of the right bound of the rectangle.
Definition: rectangle.h:116
Vector CalculateIntersection(const Vector &current, const Vector &speed) const
Definition: rectangle.cc:152
Side
enum for naming sides
Definition: rectangle.h:41
double xMin
The x coordinate of the left bound of the rectangle.
Definition: rectangle.h:115
Rectangle()
Create a zero-sized rectangle located at coordinates (0.0,0.0)
Definition: rectangle.cc:41
double yMin
The y coordinate of the bottom bound of the rectangle.
Definition: rectangle.h:117
#define ATTRIBUTE_HELPER_HEADER(type)
Declare the attribute value, accessor and checkers for class type
Every class exported by the ns3 library is enclosed in the ns3 namespace.
std::ostream & operator<<(std::ostream &os, const Angles &a)
Definition: angles.cc:159
std::istream & operator>>(std::istream &is, Angles &a)
Definition: angles.cc:183