Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Menu
Open sidebar
Simonstrator
PeerfactSim.KOM
Commits
9fa50bfd
Commit
9fa50bfd
authored
Sep 14, 2018
by
Julian Zobel
Browse files
Position Vector now always 3D with 0 altitude if not set
parent
9cd866a1
Changes
1
Hide whitespace changes
Inline
Side-by-side
src/de/tud/kom/p2psim/impl/topology/util/PositionVector.java
View file @
9fa50bfd
...
...
@@ -50,7 +50,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
* and removed a bug in the moveStep() function.
*
* - 10.09.2018 Julian Zobel: Adapted the replace function to work properly without
* assertions. Replace does now fully replace the position vector entries.
* assertions. Replace does now fully replace the position vector entries. PVs are now
* always at least 3D (with 0 altitude)
*
* @author Bjoern Richerzhagen, Julian Zobel
* @version 1.2, 10.09.2018
...
...
@@ -76,6 +77,11 @@ public class PositionVector implements Location {
if
(
dimensions
<
2
)
{
throw
new
AssertionError
(
"Vector cannot have less than 2 dimensions."
);
}
// Position Vector is always at least 3D
if
(
dimensions
==
2
)
dimensions
=
3
;
this
.
dimensions
=
dimensions
;
this
.
values
=
new
double
[
dimensions
];
}
...
...
@@ -94,9 +100,10 @@ public class PositionVector implements Location {
}
public
PositionVector
(
double
longitudeOrX
,
double
latitudeOrY
)
{
this
(
2
);
this
(
3
);
this
.
setLatitudeOrY
(
latitudeOrY
);
this
.
setLongitudeOrX
(
longitudeOrX
);
this
.
setAltitude
(
0
);
}
public
PositionVector
(
double
longitudeOrX
,
double
latitudeOrY
,
double
altitude
)
{
...
...
@@ -106,15 +113,15 @@ public class PositionVector implements Location {
this
.
setAltitude
(
altitude
);
}
public
PositionVector
(
Location
location
)
{
if
(
location
.
hasAltitude
())
{
this
.
dimensions
=
3
;
this
.
values
=
new
double
[
3
];
public
PositionVector
(
Location
location
)
{
this
.
dimensions
=
3
;
this
.
values
=
new
double
[
3
];
if
(
location
.
hasAltitude
())
{
this
.
setAltitude
(
location
.
getAltitude
());
}
else
{
this
.
dimensions
=
2
;
this
.
values
=
new
double
[
2
];
this
.
setAltitude
(
0
);
}
this
.
setLatitudeOrY
(
location
.
getLatitudeOrY
());
...
...
@@ -161,11 +168,7 @@ public class PositionVector implements Location {
@Override
public
void
setAltitude
(
double
altitude
)
{
if
(
hasAltitude
())
{
this
.
setEntry
(
2
,
altitude
);
}
else
throw
new
AssertionError
(
"Setting altitude only possible with three dimensional PositionVector"
);
this
.
setEntry
(
2
,
altitude
);
}
@Override
...
...
@@ -380,10 +383,8 @@ public class PositionVector implements Location {
throw
new
AssertionError
(
"Cast to Coordinate only possible with two or three dimensional PositionVector"
);
}
if
(
this
.
dimensions
==
2
)
return
new
Coordinate
(
getX
(),
getY
());
else
return
new
Coordinate
(
getX
(),
getY
(),
getZ
());
return
new
Coordinate
(
getX
(),
getY
(),
getZ
());
}
@Override
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment