A Discrete-Event Network Simulator
API
Loading...
Searching...
No Matches
vector.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 NS3_VECTOR_H
20#define NS3_VECTOR_H
21
22#include "attribute-helper.h"
23#include "attribute.h"
24
25/**
26 * \file
27 * \ingroup geometry
28 * ns3::Vector, ns3::Vector2D and ns3::Vector3D declarations.
29 */
30
31namespace ns3
32{
33
34/**
35 * \ingroup core
36 * \defgroup geometry Geometry primitives
37 * \brief Primitives for geometry, such as vectors and angles.
38 */
39
40/**
41 * \ingroup geometry
42 * \brief a 3d vector
43 * \see attribute_Vector3D
44 */
46{
47 public:
48 /**
49 * \param [in] _x X coordinate of vector
50 * \param [in] _y Y coordinate of vector
51 * \param [in] _z Z coordinate of vector
52 *
53 * Create vector (_x, _y, _z)
54 */
55 Vector3D(double _x, double _y, double _z);
56 /** Create vector (0.0, 0.0, 0.0) */
57 Vector3D();
58
59 double x; //!< x coordinate of vector
60 double y; //!< y coordinate of vector
61 double z; //!< z coordinate of vector
62
63 /**
64 * Compute the length (magnitude) of the vector.
65 * \returns the vector length.
66 */
67 double GetLength() const;
68
69 /**
70 * Compute the squared length of the vector.
71 * \returns the vector length squared.
72 */
73 double GetLengthSquared() const;
74
75 /**
76 * \brief Calculate the Cartesian distance between two points.
77 * \param [in] a One point
78 * \param [in] b Another point
79 * \returns The distance between \pname{a} and \pname{b}.
80 */
81 friend double CalculateDistance(const Vector3D& a, const Vector3D& b);
82
83 /**
84 * \brief Calculate the squared Cartesian distance between two points.
85 * \param [in] a One point
86 * \param [in] b Another point
87 * \returns The distance between \pname{a} and \pname{b}.
88 */
89 friend double CalculateDistanceSquared(const Vector3D& a, const Vector3D& b);
90
91 /**
92 * Output streamer.
93 * Vectors are written as "x:y:z".
94 *
95 * \param [in,out] os The stream.
96 * \param [in] vector The vector to stream
97 * \return The stream.
98 */
99 friend std::ostream& operator<<(std::ostream& os, const Vector3D& vector);
100
101 /**
102 * Input streamer.
103 *
104 * Vectors are expected to be in the form "x:y:z".
105 *
106 * \param [in,out] is The stream.
107 * \param [in] vector The vector.
108 * \returns The stream.
109 */
110 friend std::istream& operator>>(std::istream& is, Vector3D& vector);
111
112 /**
113 * Less than comparison operator
114 * \param [in] a lhs vector
115 * \param [in] b rhs vector
116 * \returns \c true if \pname{a} is less than \pname{b}
117 */
118 friend bool operator<(const Vector3D& a, const Vector3D& b);
119
120 /**
121 * Less than or equal to comparison operator
122 * \param [in] a lhs vector
123 * \param [in] b rhs vector
124 * \returns \c true if \pname{a} is less than or equal to \pname{b}.
125 */
126 friend bool operator<=(const Vector3D& a, const Vector3D& b);
127
128 /**
129 * Greater than comparison operator
130 * \param [in] a lhs vector
131 * \param [in] b rhs vector
132 * \returns \c true if \pname{a} is greater than \pname{b}.
133 */
134 friend bool operator>(const Vector3D& a, const Vector3D& b);
135
136 /**
137 * Greater than or equal to comparison operator
138 * \param [in] a lhs vector
139 * \param [in] b rhs vector
140 * \returns \c true if \pname{a} is greater than or equal to \pname{b}.
141 */
142 friend bool operator>=(const Vector3D& a, const Vector3D& b);
143
144 /**
145 * Equality operator.
146 * \param [in] a lhs vector.
147 * \param [in] b rhs vector.
148 * \returns \c true if \pname{a} is equal to \pname{b}.
149 */
150 friend bool operator==(const Vector3D& a, const Vector3D& b);
151
152 /**
153 * Inequality operator.
154 * \param [in] a lhs vector.
155 * \param [in] b rhs vector.
156 * \returns \c true if \pname{a} is not equal to \pname{b}.
157 */
158 friend bool operator!=(const Vector3D& a, const Vector3D& b);
159
160 /**
161 * Addition operator.
162 * \param [in] a lhs vector.
163 * \param [in] b rhs vector.
164 * \returns The vector sum of \pname{a} and \pname{b}.
165 */
166 friend Vector3D operator+(const Vector3D& a, const Vector3D& b);
167
168 /**
169 * Subtraction operator.
170 * \param [in] a lhs vector.
171 * \param [in] b rhs vector.
172 * \returns The vector difference of \pname{a} and \pname{b}.
173 */
174 friend Vector3D operator-(const Vector3D& a, const Vector3D& b);
175};
176
177/**
178 * \ingroup geometry
179 * \brief a 2d vector
180 * \see attribute_Vector2D
181 */
183{
184 public:
185 /**
186 * \param [in] _x X coordinate of vector
187 * \param [in] _y Y coordinate of vector
188 *
189 * Create vector (_x, _y)
190 */
191 Vector2D(double _x, double _y);
192 /** Constructor: (0.0, 0.0) */
193 Vector2D();
194 double x; //!< x coordinate of vector
195 double y; //!< y coordinate of vector
196
197 // works: /** \copydoc ns3::Vector3D::GetLength() */
198 /** \copydoc Vector3D::GetLength() */
199 double GetLength() const;
200
201 /** \copydoc Vector3D::GetLengthSquared() */
202 double GetLengthSquared() const;
203
204 /**
205 * \brief Calculate the Cartesian distance between two points.
206 * \param [in] a One point
207 * \param [in] b Another point
208 * \returns The distance between \pname{a} and \pname{b}.
209 */
210 friend double CalculateDistance(const Vector2D& a, const Vector2D& b);
211
212 /**
213 * \brief Calculate the squared Cartesian distance between two points.
214 * \param [in] a One point
215 * \param [in] b Another point
216 * \returns The distance between \pname{a} and \pname{b}.
217 */
218 friend double CalculateDistanceSquared(const Vector2D& a, const Vector2D& b);
219
220 /**
221 * Output streamer.
222 * Vectors are written as "x:y".
223 *
224 * \param [in,out] os The stream.
225 * \param [in] vector The vector to stream
226 * \return The stream.
227 */
228 friend std::ostream& operator<<(std::ostream& os, const Vector2D& vector);
229
230 /**
231 * Input streamer.
232 *
233 * Vectors are expected to be in the form "x:y".
234 *
235 * \param [in,out] is The stream.
236 * \param [in] vector The vector.
237 * \returns The stream.
238 */
239 friend std::istream& operator>>(std::istream& is, Vector2D& vector);
240
241 /**
242 * Less than comparison operator
243 * \param [in] a lhs vector
244 * \param [in] b rhs vector
245 * \returns \c true if \pname{a} is less than \pname{b}
246 */
247 friend bool operator<(const Vector2D& a, const Vector2D& b);
248
249 /**
250 * Less than or equal to comparison operator
251 * \param [in] a lhs vector
252 * \param [in] b rhs vector
253 * \returns \c true if \pname{a} is less than or equal to \pname{b}.
254 */
255 friend bool operator<=(const Vector2D& a, const Vector2D& b);
256
257 /**
258 * Greater than comparison operator
259 * \param [in] a lhs vector
260 * \param [in] b rhs vector
261 * \returns \c true if \pname{a} is greater than \pname{b}.
262 */
263 friend bool operator>(const Vector2D& a, const Vector2D& b);
264
265 /**
266 * Greater than or equal to comparison operator
267 * \param [in] a lhs vector
268 * \param [in] b rhs vector
269 * \returns \c true if \pname{a} is greater than or equal to \pname{b}.
270 */
271 friend bool operator>=(const Vector2D& a, const Vector2D& b);
272
273 /**
274 * Equality operator.
275 * \param [in] a lhs vector.
276 * \param [in] b rhs vector.
277 * \returns \c true if \pname{a} is equal to \pname{b}.
278 */
279 friend bool operator==(const Vector2D& a, const Vector2D& b);
280
281 /**
282 * Inequality operator.
283 * \param [in] a lhs vector.
284 * \param [in] b rhs vector.
285 * \returns \c true if \pname{a} is not equal to \pname{b}.
286 */
287 friend bool operator!=(const Vector2D& a, const Vector2D& b);
288
289 /**
290 * Addition operator.
291 * \param [in] a lhs vector.
292 * \param [in] b rhs vector.
293 * \returns The vector sum of \pname{a} and \pname{b}.
294 */
295 friend Vector2D operator+(const Vector2D& a, const Vector2D& b);
296
297 /**
298 * Subtraction operator.
299 * \param [in] a lhs vector.
300 * \param [in] b rhs vector.
301 * \returns The vector difference of \pname{a} and \pname{b}.
302 */
303 friend Vector2D operator-(const Vector2D& a, const Vector2D& b);
304};
305
306double CalculateDistance(const Vector3D& a, const Vector3D& b);
307double CalculateDistance(const Vector2D& a, const Vector2D& b);
308double CalculateDistanceSquared(const Vector3D& a, const Vector3D& b);
309double CalculateDistanceSquared(const Vector2D& a, const Vector2D& b);
310std::ostream& operator<<(std::ostream& os, const Vector3D& vector);
311std::ostream& operator<<(std::ostream& os, const Vector2D& vector);
312std::istream& operator>>(std::istream& is, Vector3D& vector);
313std::istream& operator>>(std::istream& is, Vector2D& vector);
314bool operator<(const Vector3D& a, const Vector3D& b);
315bool operator<(const Vector2D& a, const Vector2D& b);
316
319
320/**
321 * \ingroup attribute_Vector3D
322 * \relates Vector3D
323 * Vector alias typedef for compatibility with mobility models
324 */
326
327/**
328 * \ingroup attribute_Vector3D
329 * \relates Vector3D
330 * Vector alias typedef for compatibility with mobility models
331 */
333
334/**
335 * \ingroup attribute_Vector3D
336 * \relates Vector3D
337 * Vector alias typedef for compatibility with mobility models
338 */
340
342
344
345} // namespace ns3
346
347// Document these by hand so they go in group attribute_Vector3D
348
349/*!
350\ingroup attribute_Vector3D
351\fn ns3::Ptr<const ns3::AttributeAccessor> ns3::MakeVectorAccessor (T1 a1)
352\copydoc ns3::MakeAccessorHelper(T1)
353\see AttributeAccessor
354*/
355
356/*!
357\ingroup attribute_Vector3D
358\fn ns3::Ptr<const ns3::AttributeAccessor> ns3::MakeVectorAccessor (T1 a1, T2 a2)
359\copydoc ns3::MakeAccessorHelper(T1,T2)
360\see AttributeAccessor
361*/
362
363/*!
364\ingroup attribute_Vector3D
365\fn ns3::Ptr<const ns3::AttributeChecker> ns3::MakeVectorChecker ()
366\returns The AttributeChecker.
367\see AttributeChecker
368*/
369
370#endif /* NS3_VECTOR_H */
Attribute helper (ATTRIBUTE_ )macros definition.
ns3::AttributeValue, ns3::AttributeAccessor and ns3::AttributeChecker declarations.
Smart pointer class similar to boost::intrusive_ptr.
Definition: ptr.h:77
a 2d vector
Definition: vector.h:183
friend bool operator!=(const Vector2D &a, const Vector2D &b)
Inequality operator.
Definition: vector.cc:254
friend double CalculateDistanceSquared(const Vector2D &a, const Vector2D &b)
Calculate the squared Cartesian distance between two points.
Definition: vector.cc:130
friend std::istream & operator>>(std::istream &is, Vector2D &vector)
Input streamer.
Definition: vector.cc:212
double y
y coordinate of vector
Definition: vector.h:195
friend bool operator==(const Vector2D &a, const Vector2D &b)
Equality operator.
Definition: vector.cc:248
friend bool operator<=(const Vector2D &a, const Vector2D &b)
Less than or equal to comparison operator.
Definition: vector.cc:230
Vector2D()
Constructor: (0.0, 0.0)
Definition: vector.cc:73
friend bool operator<(const Vector2D &a, const Vector2D &b)
Less than comparison operator.
Definition: vector.cc:224
friend std::ostream & operator<<(std::ostream &os, const Vector2D &vector)
Output streamer.
Definition: vector.cc:205
double x
x coordinate of vector
Definition: vector.h:194
friend Vector2D operator+(const Vector2D &a, const Vector2D &b)
Addition operator.
Definition: vector.cc:260
friend bool operator>(const Vector2D &a, const Vector2D &b)
Greater than comparison operator.
Definition: vector.cc:236
friend bool operator>=(const Vector2D &a, const Vector2D &b)
Greater than or equal to comparison operator.
Definition: vector.cc:242
friend Vector2D operator-(const Vector2D &a, const Vector2D &b)
Subtraction operator.
Definition: vector.cc:266
double GetLength() const
Compute the length (magnitude) of the vector.
Definition: vector.cc:88
friend double CalculateDistance(const Vector2D &a, const Vector2D &b)
Calculate the Cartesian distance between two points.
Definition: vector.cc:116
double GetLengthSquared() const
Compute the squared length of the vector.
Definition: vector.cc:102
AttributeChecker implementation for Vector3DValue.
Definition: vector.h:317
a 3d vector
Definition: vector.h:46
double GetLength() const
Compute the length (magnitude) of the vector.
Definition: vector.cc:81
friend double CalculateDistance(const Vector3D &a, const Vector3D &b)
Calculate the Cartesian distance between two points.
Definition: vector.cc:109
friend std::ostream & operator<<(std::ostream &os, const Vector3D &vector)
Output streamer.
Definition: vector.cc:137
friend bool operator>=(const Vector3D &a, const Vector3D &b)
Greater than or equal to comparison operator.
Definition: vector.cc:175
friend bool operator!=(const Vector3D &a, const Vector3D &b)
Inequality operator.
Definition: vector.cc:187
friend Vector3D operator+(const Vector3D &a, const Vector3D &b)
Addition operator.
Definition: vector.cc:193
double x
x coordinate of vector
Definition: vector.h:59
friend bool operator==(const Vector3D &a, const Vector3D &b)
Equality operator.
Definition: vector.cc:181
friend std::istream & operator>>(std::istream &is, Vector3D &vector)
Input streamer.
Definition: vector.cc:144
friend Vector3D operator-(const Vector3D &a, const Vector3D &b)
Subtraction operator.
Definition: vector.cc:199
friend bool operator>(const Vector3D &a, const Vector3D &b)
Greater than comparison operator.
Definition: vector.cc:169
Vector3D()
Create vector (0.0, 0.0, 0.0)
Definition: vector.cc:58
double z
z coordinate of vector
Definition: vector.h:61
friend bool operator<=(const Vector3D &a, const Vector3D &b)
Less than or equal to comparison operator.
Definition: vector.cc:163
double y
y coordinate of vector
Definition: vector.h:60
double GetLengthSquared() const
Compute the squared length of the vector.
Definition: vector.cc:95
friend bool operator<(const Vector3D &a, const Vector3D &b)
Less than comparison operator.
Definition: vector.cc:157
friend double CalculateDistanceSquared(const Vector3D &a, const Vector3D &b)
Calculate the squared Cartesian distance between two points.
Definition: vector.cc:123
AttributeValue implementation for Vector3D.
Definition: vector.h:317
Vector3DValue VectorValue
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:332
Vector3D Vector
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:325
Vector3DChecker VectorChecker
Vector alias typedef for compatibility with mobility models.
Definition: vector.h:339
Ptr< const AttributeChecker > MakeVectorChecker()
Definition: vector.cc:44
#define ATTRIBUTE_ACCESSOR_DEFINE(type)
Define the attribute accessor functions MakeTypeAccessor for class type.
#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
bool operator<(const EventId &a, const EventId &b)
Definition: event-id.h:170
double CalculateDistance(const Vector3D &a, const Vector3D &b)
Definition: vector.cc:109
double CalculateDistanceSquared(const Vector3D &a, const Vector3D &b)
Definition: vector.cc:123