Commit 9fa50bfd authored by Julian Zobel's avatar Julian Zobel
Browse files

Position Vector now always 3D with 0 altitude if not set

parent 9cd866a1
...@@ -50,7 +50,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; ...@@ -50,7 +50,8 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
* and removed a bug in the moveStep() function. * and removed a bug in the moveStep() function.
* *
* - 10.09.2018 Julian Zobel: Adapted the replace function to work properly without * - 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 * @author Bjoern Richerzhagen, Julian Zobel
* @version 1.2, 10.09.2018 * @version 1.2, 10.09.2018
...@@ -76,6 +77,11 @@ public class PositionVector implements Location { ...@@ -76,6 +77,11 @@ public class PositionVector implements Location {
if (dimensions < 2) { if (dimensions < 2) {
throw new AssertionError("Vector cannot have less than 2 dimensions."); 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.dimensions = dimensions;
this.values = new double[dimensions]; this.values = new double[dimensions];
} }
...@@ -94,9 +100,10 @@ public class PositionVector implements Location { ...@@ -94,9 +100,10 @@ public class PositionVector implements Location {
} }
public PositionVector(double longitudeOrX, double latitudeOrY) { public PositionVector(double longitudeOrX, double latitudeOrY) {
this(2); this(3);
this.setLatitudeOrY(latitudeOrY); this.setLatitudeOrY(latitudeOrY);
this.setLongitudeOrX(longitudeOrX); this.setLongitudeOrX(longitudeOrX);
this.setAltitude(0);
} }
public PositionVector(double longitudeOrX, double latitudeOrY, double altitude) { public PositionVector(double longitudeOrX, double latitudeOrY, double altitude) {
...@@ -106,15 +113,15 @@ public class PositionVector implements Location { ...@@ -106,15 +113,15 @@ public class PositionVector implements Location {
this.setAltitude(altitude); this.setAltitude(altitude);
} }
public PositionVector(Location location) { public PositionVector(Location location) {
if(location.hasAltitude()) { this.dimensions = 3;
this.dimensions = 3; this.values = new double[3];
this.values = new double[3];
if(location.hasAltitude()) {
this.setAltitude(location.getAltitude()); this.setAltitude(location.getAltitude());
} }
else { else {
this.dimensions = 2; this.setAltitude(0);
this.values = new double[2];
} }
this.setLatitudeOrY(location.getLatitudeOrY()); this.setLatitudeOrY(location.getLatitudeOrY());
...@@ -161,11 +168,7 @@ public class PositionVector implements Location { ...@@ -161,11 +168,7 @@ public class PositionVector implements Location {
@Override @Override
public void setAltitude(double altitude) { public void setAltitude(double altitude) {
if(hasAltitude()) { this.setEntry(2, altitude);
this.setEntry(2, altitude);
}
else
throw new AssertionError("Setting altitude only possible with three dimensional PositionVector");
} }
@Override @Override
...@@ -380,10 +383,8 @@ public class PositionVector implements Location { ...@@ -380,10 +383,8 @@ public class PositionVector implements Location {
throw new AssertionError( throw new AssertionError(
"Cast to Coordinate only possible with two or three dimensional PositionVector"); "Cast to Coordinate only possible with two or three dimensional PositionVector");
} }
if (this.dimensions == 2)
return new Coordinate(getX(), getY()); return new Coordinate(getX(), getY(), getZ());
else
return new Coordinate(getX(), getY(), getZ());
} }
@Override @Override
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment