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