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