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 * SPDX-License-Identifier: GPL-2.0-only
5 *
6 * Author: Mathieu Lacage <mathieu.lacage@sophia.inria.fr>
7 */
8#ifndef RECTANGLE_H
9#define RECTANGLE_H
10
11#include "ns3/attribute-helper.h"
12#include "ns3/attribute.h"
13#include "ns3/vector.h"
14
15namespace ns3
16{
17
18/**
19 * \ingroup mobility
20 * \brief a 2d rectangle
21 * \see attribute_Rectangle
22 */
24{
25 public:
26 /**
27 * enum for naming sides
28 */
40
41 /**
42 * \param _xMin x coordinates of left boundary.
43 * \param _xMax x coordinates of right boundary.
44 * \param _yMin y coordinates of bottom boundary.
45 * \param _yMax y coordinates of top boundary.
46 *
47 * Create a rectangle.
48 */
49 Rectangle(double _xMin, double _xMax, double _yMin, double _yMax);
50 /**
51 * Create a zero-sized rectangle located at coordinates (0.0,0.0)
52 */
53 Rectangle();
54 /**
55 * \param position the position to test.
56 * \return true if the input position is located within the rectangle, false otherwise.
57 *
58 * This method compares only the x and y coordinates of the input position.
59 * It ignores the z coordinate.
60 */
61 bool IsInside(const Vector& position) const;
62 /**
63 * \param position the position to test.
64 * \return true if the input position is located on the rectable border, false otherwise.
65 *
66 * This method compares only the x and y coordinates of the input position.
67 * It ignores the z coordinate.
68 */
69 bool IsOnTheBorder(const Vector& position) const;
70 /**
71 * \param position the position to test.
72 * \return the side of the rectangle the input position is closest to.
73 *
74 * This method compares only the x and y coordinates of the input position.
75 * It ignores the z coordinate.
76 *
77 * This method assumes assumes a right-handed Cartesian orientation, so that
78 * (xMin, yMin) is the BOTTOMLEFTCORNER, the TOP and BOTTOM sides are parallel to
79 * the x-axis, the LEFT and RIGHT sides are parallel to the y-axis, and the
80 * (xMax, yMax) point is the TOPRIGHTCORNER.
81 *
82 * Beware: the method has an ambiguity in the "center" of the rectangle. Assume
83 * a rectangle between the points (0, 0) and (4, 2), i.e., wider than taller.
84 * All the points on the line between (1, 1) and (3, 1) are equally closer to the
85 * TOP and BOTTOM than to the other sides of the Rectangle.
86 * These points are classified as TOPSIDE by convention.
87 *
88 * Similarly, for a Rectangle taller than wider, the "center" points will be
89 * classified as RIGHTSIDE, and for a square box, the center will return RIGHTSIDE.
90 */
91 Side GetClosestSideOrCorner(const Vector& position) const;
92 /**
93 * \param current the current position
94 * \param speed the current speed
95 * \return the intersection point between the rectangle and the current+speed vector.
96 *
97 * This method assumes that the current position is located _inside_
98 * the rectangle and checks for this with an assert.
99 * This method compares only the x and y coordinates of the input position
100 * and speed. It ignores the z coordinate.
101 */
102 Vector CalculateIntersection(const Vector& current, const Vector& speed) const;
103
104 double xMin; //!< The x coordinate of the left bound of the rectangle
105 double xMax; //!< The x coordinate of the right bound of the rectangle
106 double yMin; //!< The y coordinate of the bottom bound of the rectangle
107 double yMax; //!< The y coordinate of the top bound of the rectangle
108};
109
110std::ostream& operator<<(std::ostream& os, const Rectangle& rectangle);
111std::istream& operator>>(std::istream& is, Rectangle& rectangle);
112std::ostream& operator<<(std::ostream& os, const Rectangle::Side& side);
113
115
116} // namespace ns3
117
118#endif /* RECTANGLE_H */
a 2d rectangle
Definition rectangle.h:24
double yMax
The y coordinate of the top bound of the rectangle.
Definition rectangle.h:107
Side GetClosestSideOrCorner(const Vector &position) const
Definition rectangle.cc:53
bool IsInside(const Vector &position) const
Definition rectangle.cc:39
bool IsOnTheBorder(const Vector &position) const
Definition rectangle.cc:46
double xMax
The x coordinate of the right bound of the rectangle.
Definition rectangle.h:105
Vector CalculateIntersection(const Vector &current, const Vector &speed) const
Definition rectangle.cc:141
Side
enum for naming sides
Definition rectangle.h:30
double xMin
The x coordinate of the left bound of the rectangle.
Definition rectangle.h:104
Rectangle()
Create a zero-sized rectangle located at coordinates (0.0,0.0)
Definition rectangle.cc:30
double yMin
The y coordinate of the bottom bound of the rectangle.
Definition rectangle.h:106
#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:148
std::istream & operator>>(std::istream &is, Angles &a)
Definition angles.cc:172