Commit c5a8f78e authored by Julian Zobel's avatar Julian Zobel 🦄
Browse files

New naming for X/Y position functions.

3D position functions added to PositionVector class
parent 0ce6cda0
...@@ -319,12 +319,12 @@ public class GnpPosition implements Location, Comparable<GnpPosition> { ...@@ -319,12 +319,12 @@ public class GnpPosition implements Location, Comparable<GnpPosition> {
} }
@Override @Override
public double getLatitude() { public double getLatitudeOrY() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
@Override @Override
public double getLongitude() { public double getLongitudeOrX() {
throw new UnsupportedOperationException(); throw new UnsupportedOperationException();
} }
......
...@@ -46,6 +46,9 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location; ...@@ -46,6 +46,9 @@ import de.tudarmstadt.maki.simonstrator.api.component.sensor.location.Location;
* the dubious equals-tolerance, which violates the hashCode contract. Seriously * the dubious equals-tolerance, which violates the hashCode contract. Seriously
* guys... * guys...
* *
* - 05/09/18 Julian Zobel: Added location support for third dimension (altitude)
* and removed a bug in the moveStep() function.
*
* @author Bjoern Richerzhagen * @author Bjoern Richerzhagen
* @version 1.0, 04/25/2011 * @version 1.0, 04/25/2011
*/ */
...@@ -68,7 +71,7 @@ public class PositionVector implements Location { ...@@ -68,7 +71,7 @@ public class PositionVector implements Location {
*/ */
public PositionVector(int dimensions) { public PositionVector(int dimensions) {
if (dimensions < 2) { if (dimensions < 2) {
throw new AssertionError("Less than 2 Dimensions make no sense."); throw new AssertionError("Vector cannot have less than 2 dimensions.");
} }
this.dimensions = dimensions; this.dimensions = dimensions;
this.values = new double[dimensions]; this.values = new double[dimensions];
...@@ -85,6 +88,34 @@ public class PositionVector implements Location { ...@@ -85,6 +88,34 @@ public class PositionVector implements Location {
setEntry(i, vec.getEntry(i)); setEntry(i, vec.getEntry(i));
} }
} }
public PositionVector(double longitudeOrX, double latitudeOrY) {
this(2);
this.setLatitudeOrY(latitudeOrY);
this.setLongitudeOrX(longitudeOrX);
}
public PositionVector(double longitudeOrX, double latitudeOrY, double altitude) {
this(3);
this.setLatitudeOrY(latitudeOrY);
this.setLongitudeOrX(longitudeOrX);
this.setAltitude(altitude);
}
public PositionVector(Location location) {
if(location.hasAltitude()) {
this.dimensions = 3;
this.values = new double[3];
this.setAltitude(location.getAltitude());
}
else {
this.dimensions = 2;
this.values = new double[2];
}
this.setLatitudeOrY(location.getLatitudeOrY());
this.setLongitudeOrX(location.getLongitudeOrX());
}
/** /**
* Convenience Constructor, initializes a Vector with values.length * Convenience Constructor, initializes a Vector with values.length
...@@ -100,15 +131,15 @@ public class PositionVector implements Location { ...@@ -100,15 +131,15 @@ public class PositionVector implements Location {
} }
@Override @Override
public void setLatitude(double latitude) public void setLatitudeOrY(double latitudeOrY)
throws UnsupportedOperationException { throws UnsupportedOperationException {
this.setEntry(1, latitude); this.setEntry(1, latitudeOrY);
} }
@Override @Override
public void setLongitude(double longitude) public void setLongitudeOrX(double longitudeOrX)
throws UnsupportedOperationException { throws UnsupportedOperationException {
this.setEntry(0, longitude); this.setEntry(0, longitudeOrX);
} }
@Override @Override
...@@ -331,8 +362,12 @@ public class PositionVector implements Location { ...@@ -331,8 +362,12 @@ public class PositionVector implements Location {
@Override @Override
public String toString() { public String toString() {
return "PositionVector " + Arrays.toString(values);
return "PV [" + Arrays.toString(values) + "]";
} }
@Override @Override
public PositionVector clone() { public PositionVector clone() {
...@@ -422,6 +457,10 @@ public class PositionVector implements Location { ...@@ -422,6 +457,10 @@ public class PositionVector implements Location {
*/ */
public PositionVector moveStep(PositionVector destination, double speed) { public PositionVector moveStep(PositionVector destination, double speed) {
if(speed == 0) {
return new PositionVector(this);
}
double distance = destination.distanceTo(this); double distance = destination.distanceTo(this);
if (distance < speed) { if (distance < speed) {
/* /*
...@@ -456,23 +495,25 @@ public class PositionVector implements Location { ...@@ -456,23 +495,25 @@ public class PositionVector implements Location {
} }
@Override @Override
public double getLatitude() { public double getLatitudeOrY() {
/*
* TODO this is only a stub, as we do not work on long/lat in the
* simulator (yet?)
*/
return getY(); return getY();
} }
@Override @Override
public double getLongitude() { public double getLongitudeOrX() {
/*
* TODO this is only a stub, as we do not work on long/lat in the
* simulator (yet?)
*/
return getX(); return getX();
} }
@Override
public double getAltitude() {
return getZ();
}
@Override
public boolean hasAltitude() {
return dimensions > 2;
}
@Override @Override
public long getAgeOfLocation() { public long getAgeOfLocation() {
return 0; // always a fresh location return 0; // always a fresh location
...@@ -490,7 +531,8 @@ public class PositionVector implements Location { ...@@ -490,7 +531,8 @@ public class PositionVector implements Location {
* (pv.getEntry(i) - getEntry(i)); * (pv.getEntry(i) - getEntry(i));
} }
return Math.sqrt(dist); return Math.sqrt(dist);
} else { }
else {
throw new AssertionError( throw new AssertionError(
"Can not compute distance between Vectors of different length!"); "Can not compute distance between Vectors of different length!");
} }
...@@ -515,4 +557,6 @@ public class PositionVector implements Location { ...@@ -515,4 +557,6 @@ public class PositionVector implements Location {
"Can only calculate an Angle on elements of type position vector"); "Can only calculate an Angle on elements of type position vector");
} }
} }
} }
...@@ -113,7 +113,7 @@ public class RSUMovementModel implements MovementModel { ...@@ -113,7 +113,7 @@ public class RSUMovementModel implements MovementModel {
if (_currentIndex < _intersections.size()) { if (_currentIndex < _intersections.size()) {
// Initial placement // Initial placement
Location intersection = _intersections.get(_currentIndex); Location intersection = _intersections.get(_currentIndex);
actuator.updateCurrentLocation(new PositionVector(intersection.getLongitude(), intersection.getLatitude())); actuator.updateCurrentLocation(new PositionVector(intersection.getLongitudeOrX(), intersection.getLatitudeOrY()));
hostIntersectionMatching.put(actuator.getHost().getId(), _currentIndex); hostIntersectionMatching.put(actuator.getHost().getId(), _currentIndex);
......
...@@ -151,13 +151,13 @@ public class StreetMovement implements MovementModel, EventHandler { ...@@ -151,13 +151,13 @@ public class StreetMovement implements MovementModel, EventHandler {
double longMin, longMax, latMin, latMax, longNew, latNew; double longMin, longMax, latMin, latMax, longNew, latNew;
// Points have different longitude, so only search for random value for longitude // Points have different longitude, so only search for random value for longitude
if(a.getLongitude() != b.getLongitude()) { if(a.getLongitudeOrX() != b.getLongitudeOrX()) {
if(a.getLongitude() < b.getLongitude()) { if(a.getLongitudeOrX() < b.getLongitudeOrX()) {
longMin = a.getLongitude(); longMin = a.getLongitudeOrX();
longMax = b.getLongitude(); longMax = b.getLongitudeOrX();
} else { } else {
longMin = b.getLongitude(); longMin = b.getLongitudeOrX();
longMax = a.getLongitude(); longMax = a.getLongitudeOrX();
} }
do { do {
...@@ -165,17 +165,17 @@ public class StreetMovement implements MovementModel, EventHandler { ...@@ -165,17 +165,17 @@ public class StreetMovement implements MovementModel, EventHandler {
} while(longNew < longMin); } while(longNew < longMin);
assert longNew > longMin && longNew <= longMax; assert longNew > longMin && longNew <= longMax;
return new PositionVector(longNew, a.getLatitude()); return new PositionVector(longNew, a.getLatitudeOrY());
} }
// Points have different latitude, so only search for random value for latitude // Points have different latitude, so only search for random value for latitude
if(a.getLatitude() != b.getLatitude()) { if(a.getLatitudeOrY() != b.getLatitudeOrY()) {
if(a.getLatitude() < b.getLatitude()) { if(a.getLatitudeOrY() < b.getLatitudeOrY()) {
latMin = a.getLatitude(); latMin = a.getLatitudeOrY();
latMax = b.getLatitude(); latMax = b.getLatitudeOrY();
} else { } else {
latMin = b.getLatitude(); latMin = b.getLatitudeOrY();
latMax = a.getLatitude(); latMax = a.getLatitudeOrY();
} }
do{ do{
...@@ -183,7 +183,7 @@ public class StreetMovement implements MovementModel, EventHandler { ...@@ -183,7 +183,7 @@ public class StreetMovement implements MovementModel, EventHandler {
} while(latNew < latMin); } while(latNew < latMin);
assert latNew > latMin && latNew <= latMax; assert latNew > latMin && latNew <= latMax;
return new PositionVector(a.getLongitude(), latNew); return new PositionVector(a.getLongitudeOrX(), latNew);
} }
return null; return null;
......
...@@ -293,7 +293,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler { ...@@ -293,7 +293,7 @@ public class VehicleMovementModel implements MovementModel, EventHandler {
e.printStackTrace(); e.printStackTrace();
} }
component.updateCurrentLocation(new PositionVector(position.getLongitude(), position.getLatitude())); component.updateCurrentLocation(new PositionVector(position.getLongitudeOrX(), position.getLatitudeOrY()));
component.setMovementSpeed(_controller.getVehicleSpeed(vehicle)); component.setMovementSpeed(_controller.getVehicleSpeed(vehicle));
......
...@@ -230,21 +230,21 @@ public class ModularMovementModelViz extends JComponent ...@@ -230,21 +230,21 @@ public class ModularMovementModelViz extends JComponent
lastLoc = loc; lastLoc = loc;
g2.drawString(segment.getSegmentId(), g2.drawString(segment.getSegmentId(),
VisualizationInjector VisualizationInjector
.scaleValue(lastLoc.getLongitude()), .scaleValue(lastLoc.getLongitudeOrX()),
VisualizationInjector VisualizationInjector
.scaleValue(lastLoc.getLatitude())); .scaleValue(lastLoc.getLatitudeOrY()));
continue; continue;
} }
g2.setStroke(new BasicStroke(3.0f)); g2.setStroke(new BasicStroke(3.0f));
g2.drawLine( g2.drawLine(
VisualizationInjector VisualizationInjector
.scaleValue(lastLoc.getLongitude()), .scaleValue(lastLoc.getLongitudeOrX()),
VisualizationInjector VisualizationInjector
.scaleValue(lastLoc.getLatitude()), .scaleValue(lastLoc.getLatitudeOrY()),
VisualizationInjector VisualizationInjector
.scaleValue(loc.getLongitude()), .scaleValue(loc.getLongitudeOrX()),
VisualizationInjector VisualizationInjector
.scaleValue(loc.getLatitude())); .scaleValue(loc.getLatitudeOrY()));
lastLoc = loc; lastLoc = loc;
} }
} }
......
...@@ -127,8 +127,8 @@ public class RandomInAreaTransitionStrategy implements ITransitionStrategy ...@@ -127,8 +127,8 @@ public class RandomInAreaTransitionStrategy implements ITransitionStrategy
{ {
assert radius > 0 : "An area radius must be specified for the RandomInAreaTransitionStrategy! Did you set the 'DefaultRadius' property for this transition?"; assert radius > 0 : "An area radius must be specified for the RandomInAreaTransitionStrategy! Did you set the 'DefaultRadius' property for this transition?";
double x = center.getLongitude(); double x = center.getLongitudeOrX();
double y = center.getLatitude(); double y = center.getLatitudeOrY();
double newX = -1; double newX = -1;
double newY = -1; double newY = -1;
......
...@@ -27,8 +27,8 @@ public class RoadSideUnitInformationHandler { ...@@ -27,8 +27,8 @@ public class RoadSideUnitInformationHandler {
List<Location> result = new ArrayList<>(); List<Location> result = new ArrayList<>();
for (Location position : _positions) { for (Location position : _positions) {
if (_startX <= position.getLongitude() && position.getLongitude() <= _endX && _startY <= position.getLatitude() && position.getLatitude() <= _endY) { if (_startX <= position.getLongitudeOrX() && position.getLongitudeOrX() <= _endX && _startY <= position.getLatitudeOrY() && position.getLatitudeOrY() <= _endY) {
result.add(new PositionVector(position.getLongitude() - _startX, position.getLatitude() - _startY, 0)); result.add(new PositionVector(position.getLongitudeOrX() - _startX, position.getLatitudeOrY() - _startY, 0));
} }
} }
......
...@@ -786,8 +786,8 @@ public class TraciSimulationController implements VehicleController, SimulationS ...@@ -786,8 +786,8 @@ public class TraciSimulationController implements VehicleController, SimulationS
int count = 0; int count = 0;
for (Location position : positions) { for (Location position : positions) {
x += position.getLongitude(); x += position.getLongitudeOrX();
y += position.getLatitude(); y += position.getLatitudeOrY();
count++; count++;
} }
......
...@@ -108,7 +108,7 @@ public class RSUPlacement implements PlacementModel { ...@@ -108,7 +108,7 @@ public class RSUPlacement implements PlacementModel {
if (_currentIndex < _intersections.size()) { if (_currentIndex < _intersections.size()) {
Location intersection = _intersections.get(_currentIndex); Location intersection = _intersections.get(_currentIndex);
_currentIndex++; _currentIndex++;
return new PositionVector(intersection.getLongitude(), intersection.getLatitude()); return new PositionVector(intersection.getLongitudeOrX(), intersection.getLatitudeOrY());
} else { } else {
return new PositionVector(Double.NaN, Double.NaN); return new PositionVector(Double.NaN, Double.NaN);
} }
......
...@@ -374,8 +374,8 @@ public class VisualizationTopologyView extends JFrame ...@@ -374,8 +374,8 @@ public class VisualizationTopologyView extends JFrame
@Override @Override
public void onLocationChanged(Host host, Location location) { public void onLocationChanged(Host host, Location location) {
this.position.setLocation( this.position.setLocation(
VisualizationInjector.scaleValue(location.getLongitude()), VisualizationInjector.scaleValue(location.getLongitudeOrX()),
VisualizationInjector.scaleValue(location.getLatitude())); VisualizationInjector.scaleValue(location.getLatitudeOrY()));
} }
} }
......
...@@ -90,13 +90,13 @@ public class GeoSpherePosition implements Transmitable, Location { ...@@ -90,13 +90,13 @@ public class GeoSpherePosition implements Transmitable, Location {
/** Get the latitude in degrees */ /** Get the latitude in degrees */
@Override @Override
public double getLatitude() { public double getLatitudeOrY() {
return Math.toDegrees(latitude); return Math.toDegrees(latitude);
} }
/** Get the longitude in degrees */ /** Get the longitude in degrees */
@Override @Override
public double getLongitude() { public double getLongitudeOrX() {
return Math.toDegrees(longitude); return Math.toDegrees(longitude);
} }
...@@ -260,7 +260,7 @@ public class GeoSpherePosition implements Transmitable, Location { ...@@ -260,7 +260,7 @@ public class GeoSpherePosition implements Transmitable, Location {
@Override @Override
public String toString() { public String toString() {
return "GeoSpherePos["+getLatitude()+";"+getLongitude()+"]"; return "GeoSpherePos["+getLatitudeOrY()+";"+getLongitudeOrX()+"]";
} }
@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