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