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
26
NS_LOG_COMPONENT_DEFINE
(
"Vector"
);
27
28
namespace
ns3 {
29
30
ATTRIBUTE_HELPER_CPP
(Vector3D);
31
ATTRIBUTE_HELPER_CPP
(Vector2D);
32
// compatibility for mobility code
33
Ptr<const AttributeChecker>
MakeVectorChecker
(
void
)
34
{
35
NS_LOG_FUNCTION_NOARGS
();
36
return
MakeVector3DChecker ();
37
}
38
39
40
Vector3D::Vector3D
(
double
_x,
double
_y,
double
_z)
41
:
x
(_x),
42
y (_y),
43
z (_z)
44
{
45
NS_LOG_FUNCTION
(
this
<< _x << _y << _z);
46
}
47
48
Vector3D::Vector3D
()
49
:
x
(0.0),
50
y (0.0),
51
z (0.0)
52
{
53
NS_LOG_FUNCTION
(
this
);
54
}
55
56
Vector2D::Vector2D
(
double
_x,
double
_y)
57
:
x
(_x),
58
y (_y)
59
{
60
NS_LOG_FUNCTION
(
this
<< _x << _y);
61
}
62
63
Vector2D::Vector2D
()
64
:
x
(0.0),
65
y (0.0)
66
{
67
NS_LOG_FUNCTION
(
this
);
68
}
69
70
double
71
CalculateDistance
(
const
Vector3D
&a,
const
Vector3D
&b)
72
{
73
NS_LOG_FUNCTION
(a << b);
74
double
dx = b.
x
- a.
x
;
75
double
dy = b.
y
- a.
y
;
76
double
dz = b.
z
- a.
z
;
77
double
distance = std::sqrt (dx * dx + dy * dy + dz * dz);
78
return
distance;
79
}
80
double
81
CalculateDistance
(
const
Vector2D
&a,
const
Vector2D
&b)
82
{
83
NS_LOG_FUNCTION
(a << b);
84
double
dx = b.
x
- a.
x
;
85
double
dy = b.
y
- a.
y
;
86
double
distance = std::sqrt (dx * dx + dy * dy);
87
return
distance;
88
}
89
90
std::ostream &
operator <<
(std::ostream &os,
const
Vector3D
&vector)
91
{
92
os << vector.
x
<<
":"
<< vector.
y
<<
":"
<< vector.
z
;
93
return
os;
94
}
95
std::istream &
operator >>
(std::istream &is,
Vector3D
&vector)
96
{
97
char
c1, c2;
98
is >> vector.
x
>> c1 >> vector.
y
>> c2 >> vector.
z
;
99
if
(c1 !=
':'
||
100
c2 !=
':'
)
101
{
102
is.setstate (std::ios_base::failbit);
103
}
104
return
is;
105
}
106
std::ostream &
operator <<
(std::ostream &os,
const
Vector2D
&vector)
107
{
108
os << vector.
x
<<
":"
<< vector.
y
;
109
return
os;
110
}
111
std::istream &
operator >>
(std::istream &is,
Vector2D
&vector)
112
{
113
char
c1;
114
is >> vector.
x
>> c1 >> vector.
y
;
115
if
(c1 !=
':'
)
116
{
117
is.setstate (std::ios_base::failbit);
118
}
119
return
is;
120
}
121
122
}
// namespace ns3
src
core
model
vector.cc
Generated on Tue May 14 2013 11:08:18 for ns-3 by
1.8.1.2