Commit 1a516dc5 authored by Julian Zobel's avatar Julian Zobel
Browse files

3D Grid Position Placement (with height 0 at the start)

New version of PositionVector with alternative (and correctly functioning) set()/replace() functionality.
parent 03907fe2
......@@ -25,7 +25,6 @@ import java.util.LinkedList;
import java.util.List;
import java.util.Map;
import java.util.Set;
import de.tud.kom.p2psim.api.common.SimHost;
import de.tud.kom.p2psim.api.linklayer.mac.PhyType;
import de.tud.kom.p2psim.api.topology.Topology;
......@@ -100,11 +99,9 @@ public abstract class AbstractTopologyComponent implements TopologyComponent {
topology.addComponent(this);
movementModel.placeComponent(this);
if (placementModel != null) {
/*
* Legacy support for placement models.
*/
position.set(placementModel.place(this));
if (placementModel != null) {
// retrieve the initial position of this topology component
position.set(placementModel.place(this));
}
if (registerAsInformationProviderInSiS) {
......
......@@ -69,9 +69,9 @@ public class GridPositionDistribution implements PlacementModel {
@Override
public PositionVector place(TopologyComponent comp) {
if (positions.isEmpty()) {
calcPositions2D();
calcPositions3D();
}
PositionVector pos = positions.get(placedComponents);
PositionVector pos = positions.get(placedComponents);
placedComponents = (placedComponents + 1) % numberOfComponents;
return pos;
}
......@@ -83,8 +83,8 @@ public class GridPositionDistribution implements PlacementModel {
public void setFakeNumberOfComponents(int fakeNumberOfComponents) {
this.fakeNumberOfComponents = fakeNumberOfComponents;
}
private void calcPositions2D() {
private void calcPositions3D() {
if (fakeNumberOfComponents != -1) {
numberOfComponents = fakeNumberOfComponents;
}
......@@ -104,7 +104,7 @@ public class GridPositionDistribution implements PlacementModel {
ycenter += random.nextDouble() * dist_y / 2
- dist_y / 4;
}
PositionVector vec = new PositionVector(xcenter, ycenter);
PositionVector vec = new PositionVector(xcenter, ycenter, 0);
positions.add(vec);
}
}
......
......@@ -49,8 +49,11 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
* - 05.09.2018 Julian Zobel: Added location support for third dimension (altitude)
* 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.
*
* @author Bjoern Richerzhagen, Julian Zobel
* @version 1.1, 06.09.2018
* @version 1.2, 10.09.2018
*/
public class PositionVector implements Location {
......@@ -141,21 +144,30 @@ public class PositionVector implements Location {
/*
*
*
*
*/
@Override
public void setLatitudeOrY(double latitudeOrY)
throws UnsupportedOperationException {
{
this.setEntry(1, latitudeOrY);
}
@Override
public void setLongitudeOrX(double longitudeOrX)
throws UnsupportedOperationException {
{
this.setEntry(0, longitudeOrX);
}
@Override
public void setAltitude(double altitude) {
if(hasAltitude()) {
this.setEntry(2, altitude);
}
else
throw new AssertionError("Setting altitude only possible with three dimensional PositionVector");
}
@Override
public void setAccuracy(double accuracy)
throws UnsupportedOperationException {
......@@ -376,7 +388,7 @@ public class PositionVector implements Location {
@Override
public String toString() {
return "PV " + Arrays.toString(values) + "";
return "PV("+getDimensions()+") " + Arrays.toString(values) + "";
}
@Override
......@@ -435,8 +447,11 @@ public class PositionVector implements Location {
* @param vector
*/
public void replace(PositionVector vector) {
assert dimensions == vector.getDimensions();
this.values = Arrays.copyOf(vector.values, dimensions);
this.dimensions = vector.getDimensions();
this.values = new double[dimensions];
for (int i = 0; i < this.dimensions; i++) {
setEntry(i, vector.getEntry(i));
}
}
/**
......@@ -457,6 +472,7 @@ public class PositionVector implements Location {
* @param speed
* @return
*/
@Deprecated
public PositionVector moveStep(PositionVector destination, double speed) {
if(speed == 0) {
......@@ -492,8 +508,12 @@ public class PositionVector implements Location {
@Override
public void set(Location l) {
assert (l instanceof PositionVector);
this.replace((PositionVector) l);
if (l instanceof PositionVector) {
this.replace((PositionVector) l);
}
else {
throw new AssertionError("Cannot replace PositionVector with Location");
}
}
@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