A Discrete-Event Network Simulator
Home
Tutorials ▼
English
Portuguese
Docs ▼
Wiki
Manual
Models
Develop ▼
API
Bugs
API
Main Page
Related Pages
Modules
Namespaces
Classes
Files
File List
File Members
All
Classes
Namespaces
Files
Functions
Variables
Typedefs
Enumerations
Enumerator
Properties
Friends
Macros
Groups
Pages
vector.cc
Go to the documentation of this file.
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
#include "
vector.h
"
21
#include "
fatal-error.h
"
22
#include "
log.h
"
23
#include <cmath>
24
#include <sstream>
25
32
namespace
ns3 {
33
34
NS_LOG_COMPONENT_DEFINE
(
"Vector"
);
35
36
ATTRIBUTE_HELPER_CPP
(
Vector3D
);
37
ATTRIBUTE_HELPER_CPP
(
Vector2D
);
38
39
// compatibility for mobility code
40
Ptr<const AttributeChecker>
MakeVectorChecker
(
void
)
41
{
42
NS_LOG_FUNCTION_NOARGS
();
43
return
MakeVector3DChecker
();
44
}
45
46
47
Vector3D::Vector3D
(
double
_x,
double
_y,
double
_z)
48
:
x
(_x),
49
y (_y),
50
z (_z)
51
{
52
NS_LOG_FUNCTION
(
this
<< _x << _y << _z);
53
}
54
55
Vector3D::Vector3D
()
56
:
x
(0.0),
57
y (0.0),
58
z (0.0)
59
{
60
NS_LOG_FUNCTION
(
this
);
61
}
62
63
Vector2D::Vector2D
(
double
_x,
double
_y)
64
:
x
(_x),
65
y (_y)
66
{
67
NS_LOG_FUNCTION
(
this
<< _x << _y);
68
}
69
70
Vector2D::Vector2D
()
71
:
x
(0.0),
72
y (0.0)
73
{
74
NS_LOG_FUNCTION
(
this
);
75
}
76
77
double
78
CalculateDistance
(
const
Vector3D
&a,
const
Vector3D
&b)
79
{
80
NS_LOG_FUNCTION
(a << b);
81
double
dx = b.
x
- a.
x
;
82
double
dy = b.
y
- a.
y
;
83
double
dz = b.
z
- a.
z
;
84
double
distance = std::sqrt (dx * dx + dy * dy + dz * dz);
85
return
distance;
86
}
87
double
88
CalculateDistance
(
const
Vector2D
&a,
const
Vector2D
&b)
89
{
90
NS_LOG_FUNCTION
(a << b);
91
double
dx = b.
x
- a.
x
;
92
double
dy = b.
y
- a.
y
;
93
double
distance = std::sqrt (dx * dx + dy * dy);
94
return
distance;
95
}
96
97
std::ostream &
operator <<
(std::ostream &os,
const
Vector3D
&vector)
98
{
99
os << vector.
x
<<
":"
<< vector.
y
<<
":"
<< vector.
z
;
100
return
os;
101
}
102
std::istream &
operator >>
(std::istream &is,
Vector3D
&vector)
103
{
104
char
c1, c2;
105
is >> vector.
x
>> c1 >> vector.
y
>> c2 >> vector.
z
;
106
if
(c1 !=
':'
||
107
c2 !=
':'
)
108
{
109
is.setstate (std::ios_base::failbit);
110
}
111
return
is;
112
}
113
std::ostream &
operator <<
(std::ostream &os,
const
Vector2D
&vector)
114
{
115
os << vector.
x
<<
":"
<< vector.
y
;
116
return
os;
117
}
118
std::istream &
operator >>
(std::istream &is,
Vector2D
&vector)
119
{
120
char
c1;
121
is >> vector.
x
>> c1 >> vector.
y
;
122
if
(c1 !=
':'
)
123
{
124
is.setstate (std::ios_base::failbit);
125
}
126
return
is;
127
}
128
129
}
// namespace ns3
fatal-error.h
NS_FATAL_x macro definitions.
ns3::operator>>
std::istream & operator>>(std::istream &is, Angles &a)
initialize a struct Angles from input
Definition:
angles.cc:48
ns3::Vector3D::x
double x
x coordinate of vector
Definition:
vector.h:56
ns3::Ptr
Smart pointer class similar to boost::intrusive_ptr.
Definition:
ptr.h:73
NS_LOG_FUNCTION
#define NS_LOG_FUNCTION(parameters)
If log level LOG_FUNCTION is enabled, this macro will output all input parameters separated by "...
Definition:
log-macros-enabled.h:213
NS_LOG_COMPONENT_DEFINE
#define NS_LOG_COMPONENT_DEFINE(name)
Define a Log component with a specific name.
Definition:
log.h:201
ns3::MakeVector3DChecker
Ptr< const AttributeChecker > MakeVector3DChecker(void)
Definition:
vector.cc:36
NS_LOG_FUNCTION_NOARGS
#define NS_LOG_FUNCTION_NOARGS()
Output the name of the function.
Definition:
log-macros-enabled.h:176
ns3::Vector3D
a 3d vector
Definition:
vector.h:38
ns3::Vector2D::x
double x
x coordinate of vector
Definition:
vector.h:92
ns3::Vector2D::Vector2D
Vector2D()
Create vector vector (0.0, 0.0)
Definition:
vector.cc:70
ns3::Vector2D::y
double y
y coordinate of vector
Definition:
vector.h:96
ns3::CalculateDistance
double CalculateDistance(const Vector3D &a, const Vector3D &b)
Definition:
vector.cc:78
ns3::Vector3D::Vector3D
Vector3D()
Create vector (0.0, 0.0, 0.0)
Definition:
vector.cc:55
ns3::operator<<
std::ostream & operator<<(std::ostream &os, const Angles &a)
print a struct Angles to output
Definition:
angles.cc:42
ns3::Vector2D
a 2d vector
Definition:
vector.h:75
ns3::MakeVectorChecker
Ptr< const AttributeChecker > MakeVectorChecker(void)
Definition:
vector.cc:40
ns3::Vector3D::y
double y
y coordinate of vector
Definition:
vector.h:60
vector.h
ns3::Vector, ns3::Vector2D and ns3::Vector3D attribute value declarations.
log.h
Debug message logging.
ns3::ATTRIBUTE_HELPER_CPP
ATTRIBUTE_HELPER_CPP(BleAccessAddress)
ns3::Vector3D::z
double z
z coordinate of vector
Definition:
vector.h:64
sample-rng-plot.x
list x
Definition:
sample-rng-plot.py:26
src
core
model
vector.cc
Generated on Wed Jul 6 2016 17:11:26 for ns-3 by
1.8.6