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