I am doing a "safe check-in" - too many modified files for too long, I'm afraid of possible merging conflicts.

This commit is contained in:
I077899 committed 2013-03-21 13:44:04 +02:00
1 parent bbd4daaf15
commit 344a31ec28
8 files changed
+767 -542

No files matched your search

@@ -451,45 +451,94 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
PolarDiagram polarDiagram = polarDiagramAndNotificationMessage.getA();
String notificationMessage = polarDiagramAndNotificationMessage.getB();
Position startPosition = toPosition(requestData.firstPoint);
Position endPosition = toPosition(requestData.secondPoint);
Position edgeStart = toPosition(requestData.edgeStart);
Position edgeEnd = toPosition(requestData.edgeEnd);
RectangularBoundary rectangularBoundry = new RectangularBoundary(startPosition, endPosition, 0.1);
Position oldMovedPosition = toPosition(requestData.oldMovedPoint);
Position newMovedPosition = toPosition(requestData.newMovedPoint);
Bearing oldMovedToNewMovedBearing = oldMovedPosition.getBearingGreatCircle(newMovedPosition);
boolean areTowardsSameDirection = areTowardsSameDirection(oldMovedToNewMovedBearing, new DegreeBearingImpl(requestData.startToEndBearingDegrees));
System.out.println("oldMovedToNewMovedBearing = " + oldMovedToNewMovedBearing.getDegrees() + " degrees");
System.out.println("requestData.startToEndBearingDegrees = " + requestData.startToEndBearingDegrees + " degrees");
System.out.println("areTowardsSameDirection = " + areTowardsSameDirection);
SimulationParameters simulationParameters = new SimulationParametersImpl(null, polarDiagram, null, SailingSimulatorUtil.measured);
SailingSimulator sailingSimulator = new SailingSimulatorImpl(simulationParameters);
Path gpsWind = sailingSimulator.getLegGPSTrack(requestData.selectedRaceIndex, requestData.selectedCompetitorIndex, requestData.selectedLegIndex);
RectangularBoundary rectangularBoundry = new RectangularBoundary(oldMovedPosition, newMovedPosition, 0.1);
this.controlParameters.baseWindBearing += rectangularBoundry.getSouth().getDegrees();
WindFieldGeneratorMeasured windFieldGenerator = new WindFieldGeneratorMeasured(rectangularBoundry, this.controlParameters);
windFieldGenerator.setGPSWind(gpsWind);
TimePoint startTime = new MillisecondsTimePoint(requestData.firstPointTimepoint);
TimePoint startTime = new MillisecondsTimePoint(requestData.oldMovedPointTimePoint);
PathGenerator1Turner pathGenerator = new PathGenerator1Turner(null);
TimedPositionWithSpeed oneTurner = null;
try {
oneTurner = pathGenerator.get1Turner(windFieldGenerator, polarDiagram, startPosition, endPosition, startTime,
requestData.leftSide,
DEFAULT_STEP_MAX, DEFAULT_TIMESTEP);
TimedPositionWithSpeed leftSide1Turner = null;
TimedPositionWithSpeed rightSide1Turner = null;
// System.out.println("start and end are in correct order");
Position realStart = areTowardsSameDirection ? oldMovedPosition : newMovedPosition;
Position realEnd = areTowardsSameDirection ? newMovedPosition : oldMovedPosition;
} catch (Exception e) {
oneTurner = pathGenerator.get1Turner(windFieldGenerator, polarDiagram, endPosition, startPosition, startTime, requestData.leftSide,
DEFAULT_STEP_MAX, DEFAULT_TIMESTEP);
leftSide1Turner = pathGenerator.get1Turner(windFieldGenerator, polarDiagram, realStart, realEnd, startTime, true, DEFAULT_STEP_MAX, DEFAULT_TIMESTEP);
rightSide1Turner = pathGenerator.get1Turner(windFieldGenerator, polarDiagram, realStart, realEnd, startTime, false, DEFAULT_STEP_MAX, DEFAULT_TIMESTEP);
// System.out.println("start and end are in reversed order");
boolean isLeftSide1TurnerOnTheInside = isPointInsideTriangle(toPositionDTO(leftSide1Turner.getPosition()), requestData.beforeMovedPoint,
requestData.newMovedPoint, requestData.edgeStart);
System.out.println("isLeftSide1TurnerOnTheInside = " + isLeftSide1TurnerOnTheInside);
boolean isRightSide1TurnerOnTheInside = isPointInsideTriangle(toPositionDTO(rightSide1Turner.getPosition()), requestData.beforeMovedPoint,
requestData.newMovedPoint, requestData.edgeStart);
System.out.println("isRightSide1TurnerOnTheInside = " + isRightSide1TurnerOnTheInside);
TimedPositionWithSpeed correct1Turner = null;
if (isLeftSide1TurnerOnTheInside && isRightSide1TurnerOnTheInside == false) {
correct1Turner = rightSide1Turner;
System.out.println("voi folosi right side 1 turner");
} else if (isRightSide1TurnerOnTheInside && isLeftSide1TurnerOnTheInside == false) {
correct1Turner = leftSide1Turner;
System.out.println("voi folosi left side 1 turner");
} else {
System.out.println("voi folosi endPosition");
if (equals(leftSide1Turner.getPosition(), newMovedPosition, 0.0001)) {
System.out.println("voi folosi endPosition = leftSide1Turner!");
correct1Turner = leftSide1Turner;
} else if (equals(rightSide1Turner.getPosition(), newMovedPosition, 0.0001)) {
System.out.println("voi folosi endPosition = rightSide1Turner!");
correct1Turner = rightSide1Turner;
}
else {
System.out.println("nu ar trebui sa ajunga aici NICIODATA!");
}
}
TimedPositionWithSpeed intersection = pathGenerator.getIntersectionOptimalTowardWind(windFieldGenerator, polarDiagram, edgeStart, edgeEnd, oneTurner,
requestData.leftSide);
long timeStepMilliseconds = 2000;
double minimumDistanceMeters = 4.0;
return new Response1TurnerDTO(toSimulatorWindDTO(intersection), toSimulatorWindDTO(oneTurner), notificationMessage);
List<TimedPositionWithSpeed> path = pathGenerator.getIntersectionOptimalTowardWind(windFieldGenerator, polarDiagram, edgeStart, edgeEnd,
correct1Turner,
true,
timeStepMilliseconds, minimumDistanceMeters);
return new Response1TurnerDTO(toSimulatorWindDTOList(path), toSimulatorWindDTO(leftSide1Turner), toSimulatorWindDTO(rightSide1Turner),
toPositionDTO(oldMovedPosition), toPositionDTO(newMovedPosition),
notificationMessage);
}
private static List<SimulatorWindDTO> toSimulatorWindDTOList(List<TimedPositionWithSpeed> points) {
List<SimulatorWindDTO> result = new ArrayList<SimulatorWindDTO>();
for (TimedPositionWithSpeed point : points) {
result.add(toSimulatorWindDTO(point));
}
return result;
}
private static SimulatorWindDTO toSimulatorWindDTO(TimedPositionWithSpeed point) {
@@ -997,4 +1046,33 @@ public class SimulatorServiceImpl extends RemoteServiceServlet implements Simula
return simulator.getComeptitorsNames(selectedRaceIndex);
}
public static double getSign(PositionDTO p1, PositionDTO p2, PositionDTO p3) {
return (p1.latDeg - p3.latDeg) * (p2.lngDeg - p3.lngDeg) - (p2.latDeg - p3.latDeg) * (p1.lngDeg - p3.lngDeg);
}
public static boolean isPointInsideTriangle(PositionDTO point, PositionDTO corner1, PositionDTO corner2, PositionDTO corner3) {
boolean b1, b2, b3;
b1 = getSign(point, corner1, corner2) < 0.0d;
b2 = getSign(point, corner2, corner3) < 0.0d;
b3 = getSign(point, corner3, corner1) < 0.0d;
return (b1 == b2) && (b2 == b3);
}
public static boolean areTowardsSameDirection(Bearing b1, Bearing b2) {
boolean isB1TowardsNorth = (b1.getDegrees() < 90.0 || b1.getDegrees() > 270.0);
boolean isB2TowardsNorth = (b2.getDegrees() < 90.0 || b2.getDegrees() > 270.0);
return !(isB1TowardsNorth ^ isB2TowardsNorth);
}
private static boolean equals(Position first, Position second, double delta) {
double latDiff = Math.abs(first.getLatDeg() - second.getLatDeg());
double lngDiff = Math.abs(first.getLngDeg() - second.getLngDeg());
return latDiff <= delta && lngDiff <= delta;
}
}
@@ -5,49 +5,52 @@ import com.google.gwt.user.client.rpc.IsSerializable;
public class Request1TurnerDTO implements IsSerializable {
public Integer selectedBoatClassIndex = 0;
public PositionDTO firstPoint = null;
public Long firstPointTimepoint = 0L;
public PositionDTO secondPoint = null;
public Boolean leftSide = false;
public int selectedRaceIndex = 0;
public int selectedLegIndex = 0;
public int selectedCompetitorIndex = 0;
public Integer selectedRaceIndex = 0;
public Integer selectedCompetitorIndex = 0;
public Integer selectedLegIndex = 0;
public PositionDTO oldMovedPoint = null;
public PositionDTO newMovedPoint = null;
public PositionDTO beforeMovedPoint = null;
public PositionDTO edgeStart = null;
public PositionDTO edgeEnd = null;
public Long oldMovedPointTimePoint = 0L;
public Double startToEndBearingDegrees = 0.0;
public Request1TurnerDTO() {
this.selectedBoatClassIndex = 0;
this.firstPoint = null;
this.firstPointTimepoint = 0L;
this.secondPoint = null;
this.leftSide = false;
this.selectedRaceIndex = 0;
this.selectedLegIndex = 0;
this.selectedCompetitorIndex = 0;
this.selectedLegIndex = 0;
this.oldMovedPoint = null;
this.newMovedPoint = null;
this.beforeMovedPoint = null;
this.edgeStart = null;
this.edgeEnd = null;
this.oldMovedPointTimePoint = 0L;
this.startToEndBearingDegrees = 0.0;
}
public Request1TurnerDTO(int selectedBoatClassIndex, int selectedRaceIndex, int selectedCompetitorIndex, int selectedLegIndex, PositionDTO firstPoint,
Long firstPointTimepoint, PositionDTO secondPoint, boolean leftSide, PositionDTO edgeStart, PositionDTO edgeEnd) {
public Request1TurnerDTO(Integer selectedBoatClassIndex, Integer selectedRaceIndex, Integer selectedCompetitorIndex, Integer selectedLegIndex,
PositionDTO oldMovedPoint, PositionDTO newMovedPoint, PositionDTO beforeMovedPoint, PositionDTO edgeStart, PositionDTO edgeEnd,
Long oldMovedPointTimePoint, Double startToEndBearingDegrees) {
this.selectedBoatClassIndex = selectedBoatClassIndex;
this.firstPoint = firstPoint;
this.firstPointTimepoint = firstPointTimepoint;
this.secondPoint = secondPoint;
this.leftSide = leftSide;
this.selectedRaceIndex = selectedRaceIndex;
this.selectedCompetitorIndex = selectedCompetitorIndex;
this.selectedLegIndex = selectedLegIndex;
this.selectedRaceIndex = selectedRaceIndex;
this.selectedCompetitorIndex = selectedCompetitorIndex;
this.selectedLegIndex = selectedLegIndex;
this.oldMovedPoint = oldMovedPoint;
this.newMovedPoint = newMovedPoint;
this.beforeMovedPoint = beforeMovedPoint;
this.edgeStart = edgeStart;
this.edgeEnd = edgeEnd;
this.oldMovedPointTimePoint = oldMovedPointTimePoint;
this.startToEndBearingDegrees = startToEndBearingDegrees;
}
}
@@ -1,22 +1,34 @@
package com.sap.sailing.gwt.ui.shared;
import java.util.List;
import com.google.gwt.user.client.rpc.IsSerializable;
public class Response1TurnerDTO implements IsSerializable {
public SimulatorWindDTO intersection = null;
public SimulatorWindDTO oneTurner = null;
public List<SimulatorWindDTO> path = null;
public SimulatorWindDTO leftSide1Turner = null;
public SimulatorWindDTO rightSide1Turner = null;
public PositionDTO startPosition = null;
public PositionDTO endPosition = null;
public String notificationMessage = "";
public Response1TurnerDTO() {
this.intersection = null;
this.oneTurner = null;
this.path = null;
this.leftSide1Turner = null;
this.rightSide1Turner = null;
this.startPosition = null;
this.endPosition = null;
this.notificationMessage = "";
}
public Response1TurnerDTO(SimulatorWindDTO intersection, SimulatorWindDTO oneTurner, String notificationMessage) {
this.intersection = intersection;
this.oneTurner = oneTurner;
public Response1TurnerDTO(List<SimulatorWindDTO> path, SimulatorWindDTO leftSide1Turner, SimulatorWindDTO rightSide1Turner, PositionDTO startPosition,
PositionDTO endPosition, String notificationMessage) {
this.path = path;
this.leftSide1Turner = leftSide1Turner;
this.rightSide1Turner = rightSide1Turner;
this.startPosition = startPosition;
this.endPosition = endPosition;
this.notificationMessage = notificationMessage;
}
}
@@ -16,6 +16,9 @@ import com.google.gwt.maps.client.overlay.MarkerOptions;
import com.google.gwt.maps.client.overlay.PolyEditingOptions;
import com.google.gwt.maps.client.overlay.Polyline;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.sap.sailing.domain.common.Bearing;
import com.sap.sailing.domain.common.Position;
import com.sap.sailing.domain.common.impl.DegreePosition;
import com.sap.sailing.gwt.ui.client.ErrorReporter;
import com.sap.sailing.gwt.ui.client.SimulatorServiceAsync;
import com.sap.sailing.gwt.ui.shared.PositionDTO;
@@ -62,17 +65,16 @@ public class PathPolyline {
private ErrorReporter errorReporter = null;
private boolean warningAlreadyShown = false;
private SimulatorMap simulatorMap = null;
private Bearing startToEndBearing = null;
private static int STEP_DURATION_MILLISECONDS = 2000;
private static boolean USE_REAL_AVERAGE_WIND = true;
private static boolean FIX_CUT_SPIKES = true;
private static boolean FIX_CUT_TRIANGLES = true;
private static boolean ADD_1_TURNER = true;
private static boolean ADD_1_TURNER = false;
private static double SMOOTHNESS_MAX_DEG = 20.0;
// private int movedPointIndex = 0;
// private int alsoMovedPointIndex = 0;
public static PathPolyline createPathPolyline(List<SimulatorWindDTO> pathPoints, ErrorReporter errorReporter, SimulatorServiceAsync simulatorService,
MapWidget map, SimulatorMap simulatorMap, int selectedBoatClassIndex, int selectedRaceIndex, int selectedCompetitorIndex, int selectedLegIndex) {
@@ -103,6 +105,9 @@ public class PathPolyline {
int selectedCompetitorIndex, int selectedLegIndex, ErrorReporter errorReporter,
List<SimulatorWindDTO> pathPoints, SimulatorServiceAsync simulatorService, MapWidget map, SimulatorMap simulatorMap) {
this.turnPoints = points;
this.color = color;
this.weight = weight;
this.opacity = opacity;
@@ -120,6 +125,7 @@ public class PathPolyline {
this.errorReporter = errorReporter;
this.simulatorMap = simulatorMap;
this.startToEndBearing = getStartToEndBearing(pathPoints);
this.drawPolylineOnMap();
this.drawDashLinesOnMap(this.map.getZoomLevel());
@@ -132,15 +138,12 @@ public class PathPolyline {
});
}
@SuppressWarnings("unused")
private void printTurnPoints() {
System.out.println("-----------------------------");
private static Bearing getStartToEndBearing(List<SimulatorWindDTO> points) {
for (int index = 0; index < this.turnPoints.length; index++) {
System.out.println("Point no. " + index + " at " + this.turnPoints[index].toString());
}
System.out.println("-----------------------------");
Position start = toPosition(points.get(0).position);
Position end = toPosition(points.get(points.size() - 1).position);
Bearing bearing = start.getBearingGreatCircle(end);
return bearing;
}
private void addMarker(LatLng point, String title) {
@@ -165,60 +168,53 @@ public class PathPolyline {
public void onUpdate(PolylineLineUpdatedEvent event) {
final int indexOfMovedPoint = getIndexOfMovedPoint();
// System.out.println("indexOfMovedPoint = " + indexOfMovedPoint);
final int noOfPoints = turnPoints.length;
final LatLng originalOriginLatLng = turnPoints[indexOfMovedPoint];
// addMarker(originalOriginLatLng, "original position of moved point");
// addMarker(polyline.getVertex(indexOfMovedPoint), "proposed position of moved point");
LatLng oldPositionMovedPoint = turnPoints[indexOfMovedPoint];
if (indexOfMovedPoint == 0 || indexOfMovedPoint == noOfPoints - 1) {
// start and end points cannot be moved!
} else {
TwoDPoint newOrigin = computeNewOrigin(indexOfMovedPoint);
final boolean projectionOnBeforeLine = projectedToBeforeLine(indexOfMovedPoint);
System.out.println("projectionOnBeforeLine = " + projectionOnBeforeLine);
TwoDPoint newOrigin = computeNewOrigin(indexOfMovedPoint);
LatLng edgeStart = null;
LatLng edgeEnd = null;
LatLng beforeMovedPoint = null;
if (indexOfMovedPoint == 1) {
turnPoints[indexOfMovedPoint + 1] = toLatLng(computeAfterNewOrigin(indexOfMovedPoint, newOrigin));
turnPoints[indexOfMovedPoint + 1] = toLatLng(computeAfterNewOrigin(indexOfMovedPoint, newOrigin), map);
} else if (indexOfMovedPoint == noOfPoints - 2) {
turnPoints[indexOfMovedPoint - 1] = toLatLng(computeBeforeNewOrigin(indexOfMovedPoint, newOrigin));
turnPoints[indexOfMovedPoint - 1] = toLatLng(computeBeforeNewOrigin(indexOfMovedPoint, newOrigin), map);
} else {
LatLng temp = null;
temp = toLatLng(computeBeforeNewOrigin(indexOfMovedPoint, newOrigin));
temp = toLatLng(computeBeforeNewOrigin(indexOfMovedPoint, newOrigin), map);
if (PathPolyline.equals(temp, turnPoints[indexOfMovedPoint - 1], 0.0001) == false) {
// System.out.println("aici1");
turnPoints[indexOfMovedPoint - 1] = temp;
beforeMovedPoint = turnPoints[indexOfMovedPoint + 1];
edgeStart = turnPoints[indexOfMovedPoint - 1];
edgeEnd = turnPoints[indexOfMovedPoint - 2];
}
temp = toLatLng(computeAfterNewOrigin(indexOfMovedPoint, newOrigin));
temp = toLatLng(computeAfterNewOrigin(indexOfMovedPoint, newOrigin), map);
if (PathPolyline.equals(temp, turnPoints[indexOfMovedPoint + 1], 0.0001) == false) {
// System.out.println("aici2");
turnPoints[indexOfMovedPoint + 1] = temp;
beforeMovedPoint = turnPoints[indexOfMovedPoint - 1];
edgeStart = turnPoints[indexOfMovedPoint + 1];
edgeEnd = turnPoints[indexOfMovedPoint + 2];
}
}
// addMarker(edgeStart, "edge start");
// addMarker(edgeEnd, "edge end");
turnPoints[indexOfMovedPoint] = toLatLng(newOrigin, map);
turnPoints[indexOfMovedPoint] = toLatLng(newOrigin);
LatLng newPositionMovedPoint = turnPoints[indexOfMovedPoint];
// addMarker(toLatLng(newOrigin), "new position of moved point");
LatLng newOriginLatLng = turnPoints[indexOfMovedPoint];
long oldMovedPointTimePoint = getTimePointOf(oldPositionMovedPoint);
oldPositionMovedPoint = fixOldPositionMovedPoint(beforeMovedPoint, oldPositionMovedPoint, newPositionMovedPoint);
if (FIX_CUT_SPIKES) {
turnPoints = fixCutSpikes(turnPoints);
@@ -229,13 +225,22 @@ public class PathPolyline {
}
if(ADD_1_TURNER) {
add1Turner(originalOriginLatLng, newOriginLatLng, edgeStart, edgeEnd, !projectionOnBeforeLine, turnPoints);
// addMarker(newPositionMovedPoint, "newPositionMovedPoint");
// addMarker(oldPositionMovedPoint, "oldPositionMovedPoint");
// addMarker(edgeStart, "edgeStart");
// addMarker(edgeEnd, "edgeEnd");
// addMarker(beforeMovedPoint, "beforeMovedPoint");
add1Turner(oldPositionMovedPoint, newPositionMovedPoint, beforeMovedPoint, edgeStart, edgeEnd, turnPoints, oldMovedPointTimePoint);
}
}
drawPolylineOnMap();
drawDashLinesOnMap(map.getZoomLevel());
}
});
this.map.addOverlay(this.polyline);
@@ -245,10 +250,23 @@ public class PathPolyline {
this.getTotalTime();
}
private LatLng fixOldPositionMovedPoint(LatLng beforeMovedPoint, LatLng oldPositionMovedPoint, LatLng newPositionMovedPoint) {
TwoDPoint beforePoint = toTwoDPoint(beforeMovedPoint, this.map);
TwoDPoint point = toTwoDPoint(oldPositionMovedPoint, this.map);
TwoDPoint afterPoint = toTwoDPoint(newPositionMovedPoint, this.map);
TwoDSegment line = new TwoDSegment(beforePoint, afterPoint);
TwoDPoint projection = line.projectionOfPointOnLine(point);
return toLatLng(projection, this.map);
}
private double getAngleDegreesBetween(LatLng previous, LatLng current, LatLng next) {
TwoDVector first = new TwoDVector(this.toTwoDPoint(current), this.toTwoDPoint(previous));
TwoDVector second = new TwoDVector(this.toTwoDPoint(current), this.toTwoDPoint(next));
TwoDVector first = new TwoDVector(PathPolyline.toTwoDPoint(current, this.map), PathPolyline.toTwoDPoint(previous, this.map));
TwoDVector second = new TwoDVector(PathPolyline.toTwoDPoint(current, this.map), PathPolyline.toTwoDPoint(next, this.map));
double dotProduct = first.dotProduct(second);
@@ -278,6 +296,7 @@ public class PathPolyline {
return timepoint;
}
@SuppressWarnings("unused")
private static int getIndexOf(LatLng item, LatLng[] array) {
int index = 0;
for (LatLng element : array) {
@@ -290,36 +309,25 @@ public class PathPolyline {
return index;
}
private void add1Turner(final LatLng originalOriginLng, final LatLng newOriginLng, LatLng edgeStart, LatLng edgeEnd, boolean leftSide, final LatLng[] turnPoints) {
private void add1Turner(LatLng oldPositionMovedPoint, LatLng newPositionMovedPoint, LatLng beforeMovedPoint, LatLng edgeStart, LatLng edgeEnd,
LatLng[] turnPoints, long oldMovedPointTimePoint) {
final int indexOfEdgeStart = getIndexOf(edgeStart, turnPoints);
// System.out.println("indexOfEdgeStart = " + indexOfEdgeStart);
// int indexOfEdgeEnd = getIndexOf(edgeEnd, turnPoints);
// System.out.println("indexOfEdgeEnd = " + indexOfEdgeEnd);
final int indexOfMovedPoint = getIndexOf(newOriginLng, turnPoints);
// System.out.println("indexOfMovedPoint = " + indexOfMovedPoint);
final int noOfTurnPoints = turnPoints.length;
PositionDTO firstPoint = toPositionDTO(originalOriginLng);
PositionDTO secondPoint = toPositionDTO(newOriginLng);
PositionDTO edgeStartPoint = toPositionDTO(edgeStart);
PositionDTO edgeEndPoint = toPositionDTO(edgeEnd);
long timepoint = this.getTimePointOf(originalOriginLng);
PositionDTO oldMovedPositionDTO = toPositionDTO(oldPositionMovedPoint);
PositionDTO newMovedPositionDTO = toPositionDTO(newPositionMovedPoint);
PositionDTO beforeMovedPositionDTO = toPositionDTO(beforeMovedPoint);
PositionDTO edgeStartPositionDTO = toPositionDTO(edgeStart);
PositionDTO edgeEndPositionDTO = toPositionDTO(edgeEnd);
Request1TurnerDTO requestData = new Request1TurnerDTO(this.selectedBoatClassIndex, this.selectedRaceIndex, this.selectedCompetitorIndex, this.selectedLegIndex,
firstPoint, timepoint, secondPoint, !leftSide, edgeStartPoint, edgeEndPoint);
oldMovedPositionDTO, newMovedPositionDTO, beforeMovedPositionDTO, edgeStartPositionDTO, edgeEndPositionDTO,
oldMovedPointTimePoint, this.startToEndBearing.getDegrees());
this.simulatorService.get1Turner(requestData, new AsyncCallback<Response1TurnerDTO>() {
@Override
public void onFailure(Throwable error) {
System.err.println("Failed to compute the 1-turner!\r\n" + error.getMessage());
//errorReporter.reportError("Failed to compute the 1-turner!\r\n" + error.getMessage());
errorReporter.reportError("Failed to compute the 1-turner!\r\n" + error.getMessage());
}
@Override
@@ -327,49 +335,81 @@ public class PathPolyline {
// System.out.println("succes");
SimulatorWindDTO oneTurner = receiveData.oneTurner;
// System.out.println("One turner at (" + oneTurner.position.latDeg + ", " + oneTurner.position.lngDeg +
// ")");
addMarker(LatLng.newInstance(oneTurner.position.latDeg, oneTurner.position.lngDeg), "One turner");
LatLng leftSide1Turner = LatLng.newInstance(receiveData.leftSide1Turner.position.latDeg, receiveData.leftSide1Turner.position.lngDeg);
addMarker(leftSide1Turner, "leftSide1Turner");
System.out.println("leftSide1Turner = " + leftSide1Turner);
SimulatorWindDTO intersection = receiveData.intersection;
// System.out.println("Intersection at (" + intersection.position.latDeg + ", " +
// intersection.position.lngDeg + ")");
addMarker(LatLng.newInstance(intersection.position.latDeg, intersection.position.lngDeg), "Intersection");
LatLng rightSide1Turner = LatLng.newInstance(receiveData.rightSide1Turner.position.latDeg, receiveData.rightSide1Turner.position.lngDeg);
addMarker(rightSide1Turner, "rightSide1Turner");
System.out.println("rightSide1Turner = " + rightSide1Turner);
List<LatLng> newTurnPoints = new ArrayList<LatLng>();
LatLng startPosition = LatLng.newInstance(receiveData.startPosition.latDeg, receiveData.startPosition.lngDeg);
// addMarker(startPosition, "startPosition");
System.out.println("startPosition = " + startPosition);
if (indexOfEdgeStart < indexOfMovedPoint) {
LatLng endPosition = LatLng.newInstance(receiveData.endPosition.latDeg, receiveData.endPosition.lngDeg);
// addMarker(endPosition, "endPosition");
System.out.println("endPosition = " + endPosition);
for (int index = 0; index < noOfTurnPoints; index++) {
if (index == indexOfEdgeStart) {
newTurnPoints.add(LatLng.newInstance(intersection.position.latDeg, intersection.position.lngDeg));
} else if (index == indexOfMovedPoint) {
newTurnPoints.add(newOriginLng);
newTurnPoints.add(LatLng.newInstance(oneTurner.position.latDeg, oneTurner.position.lngDeg));
newTurnPoints.add(originalOriginLng);
} else {
newTurnPoints.add(turnPoints[index]);
}
}
} else {
for (int index = 0; index < noOfTurnPoints; index++) {
if (index == indexOfEdgeStart) {
newTurnPoints.add(LatLng.newInstance(intersection.position.latDeg, intersection.position.lngDeg));
} else if (index == indexOfMovedPoint) {
newTurnPoints.add(originalOriginLng);
newTurnPoints.add(LatLng.newInstance(oneTurner.position.latDeg, oneTurner.position.lngDeg));
newTurnPoints.add(newOriginLng);
} else {
newTurnPoints.add(turnPoints[index]);
}
}
if (PathPolyline.equals(leftSide1Turner, startPosition)) {
System.out.println("leftSide1Turner is the same as startPosition");
} else if (PathPolyline.equals(leftSide1Turner, endPosition)) {
System.out.println("leftSide1Turner is the same as endPosition");
} else if (PathPolyline.equals(rightSide1Turner, startPosition)) {
System.out.println("rightSide1Turner is the same as startPosition");
} else if (PathPolyline.equals(rightSide1Turner, endPosition)) {
System.out.println("rightSide1Turner is the same as endPosition");
}
PathPolyline.this.turnPoints = newTurnPoints.toArray(new LatLng[0]);
drawPolylineOnMap();
List<SimulatorWindDTO> path = receiveData.path;
List<LatLng> polylinePoints = new ArrayList<LatLng>();
for (SimulatorWindDTO point : path) {
polylinePoints.add(LatLng.newInstance(point.position.latDeg, point.position.lngDeg));
}
Polyline secondPolyline = new Polyline(polylinePoints.toArray(new LatLng[0]), "cyan", 3);
map.addOverlay(secondPolyline);
// SimulatorWindDTO intersection = receiveData.intersection;
// // System.out.println("Intersection at (" + intersection.position.latDeg + ", " +
// // intersection.position.lngDeg + ")");
// addMarker(LatLng.newInstance(intersection.position.latDeg, intersection.position.lngDeg), "Intersection");
// List<LatLng> newTurnPoints = new ArrayList<LatLng>();
//
// if (indexOfEdgeStart < indexOfMovedPoint) {
//
// for (int index = 0; index < noOfTurnPoints; index++) {
// if (index == indexOfEdgeStart) {
// newTurnPoints.add(LatLng.newInstance(intersection.position.latDeg, intersection.position.lngDeg));
// } else if (index == indexOfMovedPoint) {
// newTurnPoints.add(newOriginLng);
// newTurnPoints.add(LatLng.newInstance(oneTurner.position.latDeg, oneTurner.position.lngDeg));
// newTurnPoints.add(originalOriginLng);
// } else {
// newTurnPoints.add(turnPoints[index]);
// }
// }
//
// } else {
//
// for (int index = 0; index < noOfTurnPoints; index++) {
// if (index == indexOfEdgeStart) {
// newTurnPoints.add(LatLng.newInstance(intersection.position.latDeg, intersection.position.lngDeg));
// } else if (index == indexOfMovedPoint) {
// newTurnPoints.add(originalOriginLng);
// newTurnPoints.add(LatLng.newInstance(oneTurner.position.latDeg, oneTurner.position.lngDeg));
// newTurnPoints.add(newOriginLng);
// } else {
// newTurnPoints.add(turnPoints[index]);
// }
// }
// }
//
// PathPolyline.this.turnPoints = newTurnPoints.toArray(new LatLng[0]);
// drawPolylineOnMap();
}
});
}
@@ -393,8 +433,8 @@ public class PathPolyline {
for (int index = 2; index < noOfPointsMinus1; index++) {
if (getAngleDegreesBetween(turnPoints[index - 1], turnPoints[index], turnPoints[index + 1]) < SMOOTHNESS_MAX_DEG) {
before = new TwoDSegment(toTwoDPoint(turnPoints[index - 2]), toTwoDPoint(turnPoints[index - 1]));
after = new TwoDSegment(toTwoDPoint(turnPoints[index]), toTwoDPoint(turnPoints[index + 1]));
before = new TwoDSegment(toTwoDPoint(turnPoints[index - 2], this.map), toTwoDPoint(turnPoints[index - 1], this.map));
after = new TwoDSegment(toTwoDPoint(turnPoints[index], this.map), toTwoDPoint(turnPoints[index + 1], this.map));
newAtIndex = after.intersectionPointWith(before);
newIndex = index;
}
@@ -404,7 +444,7 @@ public class PathPolyline {
if (index == newIndex - 1) {
continue;
} else if (index == newIndex) {
points.add(toLatLng(newAtIndex));
points.add(toLatLng(newAtIndex, this.map));
} else {
points.add(turnPoints[index]);
}
@@ -427,17 +467,18 @@ public class PathPolyline {
third = this.turnPoints[index + 2];
fourth = this.turnPoints[index + 3];
if (TwoDPoint.areIntersecting(toTwoDPoint(first), toTwoDPoint(second), toTwoDPoint(third), toTwoDPoint(fourth))) {
if (TwoDPoint.areIntersecting(toTwoDPoint(first, this.map), toTwoDPoint(second, this.map), toTwoDPoint(third, this.map),
toTwoDPoint(fourth, this.map))) {
TwoDSegment firstSegment = new TwoDSegment(toTwoDPoint(first), toTwoDPoint(second));
TwoDSegment secondSegment = new TwoDSegment(toTwoDPoint(third), toTwoDPoint(fourth));
TwoDSegment firstSegment = new TwoDSegment(toTwoDPoint(first, this.map), toTwoDPoint(second, this.map));
TwoDSegment secondSegment = new TwoDSegment(toTwoDPoint(third, this.map), toTwoDPoint(fourth, this.map));
List<LatLng> newTurnPoints = new ArrayList<LatLng>();
for (int index2 = 0; index2 < noOfPoints; index2++) {
if (index2 == index + 1) {
continue;
} else if (index2 == index + 2) {
newTurnPoints.add(toLatLng(firstSegment.intersectionPointWith(secondSegment)));
newTurnPoints.add(toLatLng(firstSegment.intersectionPointWith(secondSegment), this.map));
} else {
newTurnPoints.add(LatLng.newInstance(this.turnPoints[index2].getLatitude(), this.turnPoints[index2].getLongitude()));
}
@@ -454,44 +495,23 @@ public class PathPolyline {
private TwoDPoint computeNewOrigin(int indexOfMovedPoint) {
double distance = (map.getZoomLevel() - 11) * DEFAULT_DISTANCE_PX;
double distance = (this.map.getZoomLevel() - 11) * DEFAULT_DISTANCE_PX;
TwoDPoint beforeOrigin = toTwoDPoint(this.turnPoints[indexOfMovedPoint - 1]);
TwoDPoint origin = toTwoDPoint(this.turnPoints[indexOfMovedPoint]);
TwoDPoint afterOrigin = toTwoDPoint(this.turnPoints[indexOfMovedPoint + 1]);
TwoDPoint beforeOrigin = toTwoDPoint(this.turnPoints[indexOfMovedPoint - 1], this.map);
TwoDPoint origin = toTwoDPoint(this.turnPoints[indexOfMovedPoint], this.map);
TwoDPoint afterOrigin = toTwoDPoint(this.turnPoints[indexOfMovedPoint + 1], this.map);
TwoDPoint head1 = TwoDPoint.getDistancedPoint(origin, distance, beforeOrigin);
TwoDPoint head2 = TwoDPoint.getDistancedPoint(origin, distance, afterOrigin);
return TwoDPoint.getCorrectProjection(origin, head1, head2, toTwoDPoint(this.polyline.getVertex(indexOfMovedPoint)));
}
private boolean projectedToBeforeLine(int indexOfMovedPoint) {
double distance = (map.getZoomLevel() - 11) * DEFAULT_DISTANCE_PX;
TwoDPoint origin = toTwoDPoint(this.turnPoints[indexOfMovedPoint]);
TwoDPoint newOrigin = toTwoDPoint(this.polyline.getVertex(indexOfMovedPoint));
TwoDPoint beforeOrigin = toTwoDPoint(this.turnPoints[indexOfMovedPoint - 1]);
TwoDPoint head1 = TwoDPoint.getDistancedPoint(origin, distance, beforeOrigin);
TwoDSegment oh1 = new TwoDSegment(origin, head1);
TwoDPoint p1 = oh1.projectionOfPointOnLine(newOrigin);
double d1 = newOrigin.distanceBetween(p1);
TwoDPoint afterOrigin = toTwoDPoint(this.turnPoints[indexOfMovedPoint + 1]);
TwoDPoint head2 = TwoDPoint.getDistancedPoint(origin, distance, afterOrigin);
TwoDSegment oh2 = new TwoDSegment(origin, head2);
TwoDPoint p2 = oh2.projectionOfPointOnLine(newOrigin);
double d2 = newOrigin.distanceBetween(p2);
return (d1 > d2);
return TwoDPoint.getCorrectProjection(origin, head1, head2, toTwoDPoint(this.polyline.getVertex(indexOfMovedPoint), this.map));
}
private TwoDPoint computeAfterNewOrigin(int indexOfMovedPoint, TwoDPoint newOrigin) {
TwoDPoint origin = toTwoDPoint(this.turnPoints[indexOfMovedPoint]);
TwoDPoint afterOrigin = toTwoDPoint(this.turnPoints[indexOfMovedPoint + 1]);
TwoDPoint afterAfterOrigin = toTwoDPoint(this.turnPoints[indexOfMovedPoint + 2]);
TwoDPoint origin = toTwoDPoint(this.turnPoints[indexOfMovedPoint], this.map);
TwoDPoint afterOrigin = toTwoDPoint(this.turnPoints[indexOfMovedPoint + 1], this.map);
TwoDPoint afterAfterOrigin = toTwoDPoint(this.turnPoints[indexOfMovedPoint + 2], this.map);
TwoDSegment afterLine = new TwoDSegment(afterOrigin, afterAfterOrigin);
TwoDVector afterVector = new TwoDVector(origin, afterOrigin);
@@ -500,9 +520,9 @@ public class PathPolyline {
private TwoDPoint computeBeforeNewOrigin(int indexOfMovedPoint, TwoDPoint newOrigin) {
TwoDPoint beforeOrigin = toTwoDPoint(this.turnPoints[indexOfMovedPoint - 1]);
TwoDPoint beforeBeforeOrigin = toTwoDPoint(this.turnPoints[indexOfMovedPoint - 2]);
TwoDPoint origin = toTwoDPoint(this.turnPoints[indexOfMovedPoint]);
TwoDPoint beforeOrigin = toTwoDPoint(this.turnPoints[indexOfMovedPoint - 1], this.map);
TwoDPoint beforeBeforeOrigin = toTwoDPoint(this.turnPoints[indexOfMovedPoint - 2], this.map);
TwoDPoint origin = toTwoDPoint(this.turnPoints[indexOfMovedPoint], this.map);
TwoDSegment beforeLine = new TwoDSegment(beforeBeforeOrigin, beforeOrigin);
TwoDVector beforeVector = new TwoDVector(beforeOrigin, origin);
@@ -616,19 +636,23 @@ public class PathPolyline {
return index;
}
private TwoDPoint toTwoDPoint(LatLng latLng) {
Point point = this.map.convertLatLngToContainerPixel(latLng);
private static TwoDPoint toTwoDPoint(LatLng latLng, MapWidget map) {
Point point = map.convertLatLngToContainerPixel(latLng);
return new TwoDPoint(point.getX(), point.getY());
}
private LatLng toLatLng(TwoDPoint point) {
return this.map.convertContainerPixelToLatLng(Point.newInstance((int) point.getX(), (int) point.getY()));
private static LatLng toLatLng(TwoDPoint point, MapWidget map) {
return map.convertContainerPixelToLatLng(Point.newInstance((int) point.getX(), (int) point.getY()));
}
private static PositionDTO toPositionDTO(LatLng position) {
return new PositionDTO(position.getLatitude(), position.getLongitude());
}
private static Position toPosition(PositionDTO position) {
return new DegreePosition(position.latDeg, position.lngDeg);
}
private Polyline createPolyline(TwoDPoint first, TwoDPoint second, String color, int weight) {
LatLng[] points = new LatLng[2];
@@ -722,4 +746,21 @@ public class PathPolyline {
public void setBoatClassID(int boatClassIndex) {
this.selectedBoatClassIndex = boatClassIndex;
}
// public static double getSign(LatLng p1, LatLng p2, LatLng p3) {
// return (p1.getLatitude() - p3.getLatitude()) * (p2.getLongitude() - p3.getLongitude()) - (p2.getLatitude() -
// p3.getLatitude())
// * (p1.getLongitude() - p3.getLongitude());
// }
//
// public static boolean isPointInsideTriangle(LatLng point, LatLng corner1, LatLng corner2, LatLng corner3) {
//
// boolean b1, b2, b3;
//
// b1 = getSign(point, corner1, corner2) < 0.0d;
// b2 = getSign(point, corner2, corner3) < 0.0d;
// b3 = getSign(point, corner3, corner1) < 0.0d;
//
// return (b1 == b2) && (b2 == b3);
// }
}
@@ -1,6 +1,8 @@
package com.sap.sailing.simulator.impl;
import java.util.ArrayList;
import java.util.LinkedList;
import java.util.List;
import com.sap.sailing.domain.base.SpeedWithBearing;
import com.sap.sailing.domain.base.impl.MillisecondsTimePoint;
@@ -74,6 +76,7 @@ public class PathGenerator1Turner extends PathGeneratorBase {
Bearing bearStart2End = start.getBearingGreatCircle(end);
Position currentPosition = start;
TimePoint currentTime = startTime;
// problema e ca starttime e 1970
TimePoint nextTime;
double[] reachTime = new double[stepMax];
@@ -152,6 +155,7 @@ public class PathGenerator1Turner extends PathGeneratorBase {
// System.out.println("stepRight = " + stepLeft + " targetFound = " + targetFound);
currentWind = windField.getWind(new TimedPositionImpl(currentTime, currentPosition));
polarDiagram.setWind(currentWind);
direction = polarDiagram.optimalDirectionsUpwind()[leftSide ? 1 : 0];
@@ -233,32 +237,103 @@ public class PathGenerator1Turner extends PathGeneratorBase {
return this.result.paths[0];
}
public TimedPositionWithSpeed getIntersectionOptimalTowardWind(WindFieldGenerator windField, PolarDiagram polarDiagram, Position edgeStart,
Position edgeEnd, TimedPositionWithSpeed from, boolean leftSide) {
public List<TimedPositionWithSpeed> getIntersectionOptimalTowardWind(WindFieldGenerator windField, PolarDiagram polarDiagram, Position edgeStart,
Position edgeEnd, TimedPositionWithSpeed start, boolean leftSide, long timeStepMilliseconds, double minimumDistanceMeters) {
TimePoint currentTime = from.getTimePoint();
Position currentPosition = from.getPosition();
List<TimedPositionWithSpeed> path = new ArrayList<TimedPositionWithSpeed>();
TimedPositionWithSpeed nextPoint = start;
double distanceToLine = 0;
int maxSteps = 60;
Wind currentWind = windField.getWind(new TimedPositionImpl(currentTime, currentPosition));
polarDiagram.setWind(currentWind);
Bearing direction = polarDiagram.optimalDirectionsUpwind()[leftSide ? 0 : 1];
//while (true) {
while (maxSteps > 0) {
nextPoint = travelTo(nextPoint, windField, polarDiagram, leftSide, timeStepMilliseconds, edgeStart, edgeEnd);
SpeedWithBearing currSpeed = polarDiagram.getSpeedAtBearing(direction);
TimePoint nextTime = new MillisecondsTimePoint(currentTime.asMillis() + 1000);
Position nextPosition = currSpeed.travelTo(currentPosition, currentTime, nextTime);
distanceToLine = getDistanceToLine(nextPoint.getPosition(), edgeStart, edgeEnd);
Position intersectionPosition = this.getIntersection(currentPosition, nextPosition, edgeStart, edgeEnd);
// System.out.println("distanceToLine = " + distanceToLine + " meters");
double distanceMeters = currentPosition.getDistance(nextPosition).getMeters();
long timeMilliseconds = (long) ((distanceMeters / currSpeed.getMetersPerSecond()) * 1000);
if (distanceToLine <= minimumDistanceMeters) {
break;
} else {
path.add(nextPoint);
}
TimePoint intersectionTimePoint = new MillisecondsTimePoint(currentTime.asMillis() + timeMilliseconds);
Wind intersectionWind = windField.getWind(new TimedPositionImpl(intersectionTimePoint, intersectionPosition));
maxSteps--;
}
return new TimedPositionWithSpeedImpl(intersectionTimePoint, intersectionPosition, intersectionWind);
return path;
}
private Position getIntersection(Position segment1Start, Position segment1End, Position segment2Start, Position segment2End) {
private static TimedPositionWithSpeed travelTo(TimedPositionWithSpeed start, WindFieldGenerator windField, PolarDiagram polarDiagram, boolean leftSide,
long timeStepMilliseconds, Position edgeStart, Position edgeEnd) {
TimePoint startTimePoint = start.getTimePoint();
Position startPosition = start.getPosition();
SpeedWithBearing windSpeedWithBearing = windField.getWind(new TimedPositionImpl(startTimePoint, startPosition));
polarDiagram.setWind(windSpeedWithBearing);
// TimePoint endTimePoint = new MillisecondsTimePoint(startTimePoint.asMillis() + timeStepMilliseconds);
// Bearing[] bearings = polarDiagram.optimalDirectionsUpwind();
//
// Bearing bearing1 = bearings[0];
// SpeedWithBearing boatSpeedWithBearing1 = polarDiagram.getSpeedAtBearing(bearing1);
// Position endPosition1 = boatSpeedWithBearing1.travelTo(startPosition, startTimePoint, endTimePoint);
// SpeedWithBearing endWind1 = windField.getWind(new TimedPositionImpl(endTimePoint, endPosition1));
// TimedPositionWithSpeed end1 = new TimedPositionWithSpeedImpl(endTimePoint, endPosition1, endWind1);
// double distance1 = getDistanceToLine(endPosition1, edgeStart, edgeEnd);
//
// Bearing bearing2 = bearings[1];
// SpeedWithBearing boatSpeedWithBearing2 = polarDiagram.getSpeedAtBearing(bearing2);
// Position endPosition2 = boatSpeedWithBearing2.travelTo(startPosition, startTimePoint, endTimePoint);
// SpeedWithBearing endWind2 = windField.getWind(new TimedPositionImpl(endTimePoint, endPosition2));
// TimedPositionWithSpeed end2 = new TimedPositionWithSpeedImpl(endTimePoint, endPosition2, endWind2);
// double distance2 = getDistanceToLine(endPosition2, edgeStart, edgeEnd);
//
// return (distance1 < distance2) ? end1 : end2;
Bearing bearing = polarDiagram.optimalDirectionsUpwind()[leftSide ? 0 : 1];
// double degrees = bearing.getDegrees();
// System.out.println("degrees = " + degrees);
// bearing = new DegreeBearingImpl(degrees + 180);
SpeedWithBearing boatSpeedWithBearing = polarDiagram.getSpeedAtBearing(bearing);
TimePoint endTimePoint = new MillisecondsTimePoint(startTimePoint.asMillis() + timeStepMilliseconds);
Position endPosition = boatSpeedWithBearing.travelTo(startPosition, startTimePoint, endTimePoint);
Wind endWind = windField.getWind(new TimedPositionImpl(endTimePoint, endPosition));
TimedPositionWithSpeed end = new TimedPositionWithSpeedImpl(endTimePoint, endPosition, endWind);
return end;
}
// private static Position getIntersection(Position segment1Start, Position segment1End, Position segment2Start,
// Position segment2End) {
//
// double xA = segment1Start.getLatDeg();
// double yA = segment1Start.getLngDeg();
//
// double xB = segment1End.getLatDeg();
// double yB = segment1End.getLngDeg();
//
// double xC = segment2Start.getLatDeg();
// double yC = segment2Start.getLngDeg();
//
// double xD = segment2End.getLatDeg();
// double yD = segment2End.getLngDeg();
//
// double m1 = (yB - yA) / (xB - xA);
// double m2 = (yD - yC) / (xD - xC);
//
// double x = (yC - yA + m1 * xA - m2 * xC) / (m1 - m2);
// double y = (yC - yA + m2 * (xA - xC)) * m1 / (m1 - m2) + yA;
//
// return new DegreePosition(x, y);
// }
public static Position getProjectionOnLine(Position point, Position segment1Start, Position segment1End) {
double xA = segment1Start.getLatDeg();
double yA = segment1Start.getLngDeg();
@@ -266,18 +341,19 @@ public class PathGenerator1Turner extends PathGeneratorBase {
double xB = segment1End.getLatDeg();
double yB = segment1End.getLngDeg();
double xC = segment2Start.getLatDeg();
double yC = segment2Start.getLngDeg();
double xC = point.getLatDeg();
double yC = point.getLngDeg();
double xD = segment2End.getLatDeg();
double yD = segment2End.getLngDeg();
double m = (yB - yA) / (xB - xA);
double b = (xB * yA - xA * yB) / (xB - xA);
double m1 = (yB - yA) / (xB - xA);
double m2 = (yD - yC) / (xD - xC);
double x = (yC - yA + m1 * xA - m2 * xC) / (m1 - m2);
double y = (yC - yA + m2 * (xA - xC)) * m1 / (m1 - m2) + yA;
double x = (m * yC + xC - m * b) / (m * m + 1);
double y = m * x + b;
return new DegreePosition(x, y);
}
public static double getDistanceToLine(Position point, Position segment1Start, Position segment1End) {
return point.getDistance(getProjectionOnLine(point, segment1Start, segment1End)).getMeters();
}
}
@@ -1,5 +1,15 @@
package com.sap.sailing.simulator.impl;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
@@ -8,6 +18,8 @@ import java.util.Map.Entry;
import java.util.TreeMap;
import java.util.logging.Logger;
import org.osgi.framework.FrameworkUtil;
import com.sap.sailing.domain.base.impl.KnotSpeedWithBearingImpl;
import com.sap.sailing.domain.base.impl.MeterDistance;
import com.sap.sailing.domain.common.Position;
@@ -20,7 +32,6 @@ import com.sap.sailing.simulator.SailingSimulator;
import com.sap.sailing.simulator.SimulationParameters;
import com.sap.sailing.simulator.TimedPositionWithSpeed;
import com.sap.sailing.simulator.util.SailingSimulatorUtil;
import com.sap.sailing.simulator.util.SerializationUtils;
import com.sap.sailing.simulator.windfield.WindFieldGenerator;
import com.sap.sailing.simulator.windfield.impl.WindFieldGeneratorMeasured;
@@ -73,9 +84,9 @@ public class SailingSimulatorImpl implements SailingSimulator {
private Path getFromResourcesOrDownload(String pathName, int selectedRaceIndex, int selectedCompetitorIndex, int selectedLegIndex) throws Exception {
String fileName = SerializationUtils.getFileName(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex, pathName);
String fileName = getFileName(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex, pathName);
Path path = (Path) SerializationUtils.readObjectFromResources(fileName);
Path path = (Path) readObjectFromResources(fileName);
if (path == null) {
if (pathName.equals("6#GPS Poly")) {
path = this.pathGenerator.getPathPolyline(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex, new MeterDistance(4.88));
@@ -86,7 +97,7 @@ public class SailingSimulatorImpl implements SailingSimulator {
} else {
throw new Exception("Unknown path name!");
}
SerializationUtils.saveToFile(path, SerializationUtils.getPathPrefix() + "\\src\\resources\\" + fileName);
saveToFile(path, getPathPrefix() + "\\src\\resources\\" + fileName);
}
return path;
@@ -103,7 +114,7 @@ public class SailingSimulatorImpl implements SailingSimulator {
if (this.simulationParameters.getMode() == SailingSimulatorUtil.measured) {
Pair<Map<String, Path>, Path> result = SerializationUtils.readLegPathsFromResources(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex);
Pair<Map<String, Path>, Path> result = readLegPathsFromResources(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex);
allPaths = result.getA();
this.raceCourse = result.getB();
@@ -256,7 +267,7 @@ public class SailingSimulatorImpl implements SailingSimulator {
allPaths.put("1#Omniscient", optPath);
if (this.simulationParameters.getMode() == SailingSimulatorUtil.measured) {
SerializationUtils.saveLegPathsToFiles(allPaths, this.raceCourse, selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex);
saveLegPathsToFiles(allPaths, this.raceCourse, selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex);
}
return allPaths;
@@ -291,9 +302,9 @@ public class SailingSimulatorImpl implements SailingSimulator {
@Override
public Path getLegGPSTrack(int selectedRaceIndex, int selectedCompetitorIndex, int selectedLegIndex) {
String fileName = SerializationUtils.getFileName(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex, "7#GPS Track");
String fileName = getFileName(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex, "7#GPS Track");
Path path = (Path) SerializationUtils.readObjectFromResources("resources/" + fileName);
Path path = (Path) readObjectFromResources("resources/" + fileName);
if (path == null) {
System.err.println("[ERROR][SailingSimulatorImpl][readPathsFromResources] Cannot de-serialize path from resources/7#GPS Track.dat");
LOGGER.warning("[ERROR][SailingSimulatorImpl][readPathsFromResources] Cannot de-serialize path from resources/7#GPS Track.dat");
@@ -311,16 +322,16 @@ public class SailingSimulatorImpl implements SailingSimulator {
this.setSimulationParameters(this.simulationParameters, selectedRaceIndex);
List<String> legsNames = null;
String fileName = SerializationUtils.getRaceID(ConfigurationManager.INSTANCE.getRaceURL(selectedRaceIndex)) + "_" + SerializationUtils.LEGSNAMES_DAT;
String fileName = getRaceID(ConfigurationManager.INSTANCE.getRaceURL(selectedRaceIndex)) + "_" + LEGSNAMES_DAT;
legsNames = (List<String>) SerializationUtils.readObjectFromResources("resources/" + fileName);
legsNames = (List<String>) readObjectFromResources("resources/" + fileName);
if (legsNames != null && legsNames.isEmpty() == false) {
return legsNames;
}
legsNames = this.pathGenerator.getLegsNames();
SerializationUtils.saveStringListToFiles(legsNames, fileName);
saveStringListToFiles(legsNames, fileName);
return legsNames;
}
@@ -350,18 +361,305 @@ public class SailingSimulatorImpl implements SailingSimulator {
this.setSimulationParameters(this.simulationParameters, selectedRaceIndex);
List<String> competitorsNames = null;
String fileName = SerializationUtils.getRaceID(ConfigurationManager.INSTANCE.getRaceURL(selectedRaceIndex)) + "_"
+ SerializationUtils.COMPETITORSNAMES_DAT;
String fileName = getRaceID(ConfigurationManager.INSTANCE.getRaceURL(selectedRaceIndex)) + "_" + COMPETITORSNAMES_DAT;
competitorsNames = (List<String>) SerializationUtils.readObjectFromResources("resources/" + fileName);
competitorsNames = (List<String>) readObjectFromResources("resources/" + fileName);
if (competitorsNames != null && competitorsNames.isEmpty() == false) {
return competitorsNames;
}
competitorsNames = this.pathGenerator.getComeptitorsNames();
SerializationUtils.saveStringListToFiles(competitorsNames, fileName);
saveStringListToFiles(competitorsNames, fileName);
return competitorsNames;
}
// private static final Logger LOGGER = Logger.getLogger("com.sap.sailing.simulator");
public static final String LEGSNAMES_DAT = "legsNames.dat";
public static final String RACECOURSE_DAT = "racecourse.dat";
public static final String COMPETITORSNAMES_DAT = "competitorsNames.dat";
private static final String[] PATH_NAMES = new String[] { "1#Omniscient", "2#Opportunistic", "3#1-Turner Left", "4#1-Turner Right", "6#GPS Poly",
"7#GPS Track" };
private static String pathPrefix = null;
private static String getPathPrefix() {
String bundleName = null;
try {
bundleName = FrameworkUtil.getBundle(Class.forName("com.sap.sailing.simulator.impl.SailingSimulatorImpl")).getSymbolicName();
} catch (ClassNotFoundException e) {
System.err.println("[ERROR][SailingSimulatorImpl][getPathPrefix][ClassNotFoundException] " + e.getMessage());
LOGGER.severe("[ERROR][SailingSimulatorImpl][getPathPrefix][ClassNotFoundException] " + e.getMessage());
return null;
}
String bundlesProperty = System.getProperty("osgi.bundles");
int bundleNameStart = bundlesProperty.indexOf(bundleName);
int bundleNameEnd = bundleNameStart + bundleName.length();
String prependedBundlePath = bundlesProperty.substring(0, bundleNameEnd);
int prefixPos = prependedBundlePath.lastIndexOf("reference:file:");
if (prefixPos >= 0) {
prependedBundlePath = prependedBundlePath.substring(prefixPos + 15, prependedBundlePath.length());
}
return prependedBundlePath;
}
// private static boolean savePathsToFiles(Map<String, Path> paths, Path raceCourse) {
// if (paths == null) {
// return false;
// }
//
// if (paths.isEmpty()) {
// return true;
// }
//
// if (pathPrefix == null) {
// pathPrefix = getPathPrefix();
// }
//
// String filePath = "";
// boolean result = true;
//
// for (String name : PATH_NAMES) {
// filePath = pathPrefix + "\\src\\resources\\" + name + ".dat";
// result &= saveToFile(paths.get(name), filePath);
// }
//
// filePath = pathPrefix + "\\src\\resources\\" + RACECOURSE_DAT;
// result &= saveToFile(raceCourse, filePath);
//
// return result;
// }
private static boolean saveLegPathsToFiles(Map<String, Path> paths, Path raceCourse, int selectedRaceIndex, int selectedCompetitorIndex,
int selectedLegIndex) {
if (paths == null) {
return false;
}
if (paths.isEmpty()) {
return true;
}
if (pathPrefix == null) {
pathPrefix = getPathPrefix();
}
String filePath = "";
String fileName = "";
boolean result = true;
for (String name : PATH_NAMES) {
fileName = getFileName(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex, name);
filePath = pathPrefix + "\\src\\resources\\" + fileName;
result &= saveToFile(paths.get(name), filePath);
}
fileName = getFileName(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex, "racecourse");
filePath = pathPrefix + "\\src\\resources\\" + fileName;
result &= saveToFile(raceCourse, filePath);
return result;
}
private static boolean saveToFile(Path path, String fileName) {
boolean result = true;
try {
OutputStream file = new FileOutputStream(fileName);
OutputStream buffer = new BufferedOutputStream(file);
ObjectOutput output = new ObjectOutputStream(buffer);
try {
output.writeObject(path);
} finally {
output.close();
buffer.close();
file.close();
}
} catch (IOException ex) {
System.err.println("[ERROR][SailingSimulatorImpl][saveToFile][IOException] " + ex.getMessage());
LOGGER.severe("[ERROR][SailingSimulatorImpl][saveToFile][IOException] " + ex.getMessage());
result = false;
}
return result;
}
private static Pair<Map<String, Path>, Path> readLegPathsFromResources(int selectedRaceIndex, int selectedCompetitorIndex, int selectedLegIndex) {
HashMap<String, Path> paths = new HashMap<String, Path>();
Path path = null;
String filePath = "";
String fileName = "";
for (String pathName : PATH_NAMES) {
fileName = getFileName(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex, pathName);
filePath = "resources/" + fileName;
path = (Path) readObjectFromResources(filePath);
if (path == null) {
System.err.println("[ERROR][SailingSimulatorImpl][readPathsFromResources] Cannot de-serialize path from" + pathName);
LOGGER.severe("[ERROR][SailingSimulatorImpl][readPathsFromResources] Cannot de-serialize path from" + pathName);
} else {
paths.put(pathName, path);
}
}
Path raceCourse = (Path) readObjectFromResources("resources/" + getFileName(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex, "racecourse"));
return new Pair<Map<String, Path>, Path>(paths, raceCourse);
}
// private static Pair<Map<String, Path>, Path> readPathsFromResources() {
// HashMap<String, Path> paths = new HashMap<String, Path>();
// Path path = null;
// String filePath = "";
//
// for (String pathName : PATH_NAMES) {
// filePath = "resources/" + pathName + ".dat";
// path = (Path) readObjectFromResources(filePath);
// if (path == null) {
// System.err.println("[ERROR][SailingSimulatorImpl][readPathsFromResources] Cannot de-serialize path from" +
// pathName);
// LOGGER.severe("[ERROR][SailingSimulatorImpl][readPathsFromResources] Cannot de-serialize path from" + pathName);
// } else {
// paths.put(pathName, path);
// }
// }
//
// Path raceCourse = (Path) readObjectFromResources("resources/" + RACECOURSE_DAT);
//
// return new Pair<Map<String, Path>, Path>(paths, raceCourse);
// }
// private static Object readObjectExternalFile(String fileName) {
// Object result = null;
// try {
// InputStream file = new FileInputStream(fileName);
// InputStream buffer = new BufferedInputStream(file);
// ObjectInput input = new ObjectInputStream(buffer);
//
// try {
// result = input.readObject();
// } finally {
// input.close();
// buffer.close();
// file.close();
// }
// } catch (ClassNotFoundException ex) {
// System.err.println("[ERROR][SailingSimulatorImpl][readFromExternalFile][ClassNotFoundException] " +
// ex.getMessage());
// LOGGER.severe("[ERROR][SailingSimulatorImpl][readFromExternalFile][ClassNotFoundException] " + ex.getMessage());
// result = null;
// } catch (IOException ex) {
// System.err.println("[ERROR][SailingSimulatorImpl][readFromExternalFile][IOException] " + ex.getMessage());
// LOGGER.severe("[ERROR][SailingSimulatorImpl][readFromExternalFile][IOException] " + ex.getMessage());
// result = null;
// }
//
// return result;
// }
private static Object readObjectFromResources(String fileName) {
Object result = null;
try {
ClassLoader classLoader = Class.forName("com.sap.sailing.simulator.impl.SailingSimulatorImpl").getClassLoader();
InputStream file = classLoader.getResourceAsStream(fileName);
InputStream buffer = new BufferedInputStream(file);
ObjectInput input = new ObjectInputStream(buffer);
try {
result = input.readObject();
} finally {
input.close();
buffer.close();
file.close();
}
} catch (ClassNotFoundException ex) {
System.err.println("[ERROR][SailingSimulatorImpl][readFromResourcesFile][ClassNotFoundException] " + ex.getMessage());
LOGGER.severe("[ERROR][SailingSimulatorImpl][readFromResourcesFile][ClassNotFoundException] " + ex.getMessage());
result = null;
} catch (IOException ex) {
System.err.println("[ERROR][SailingSimulatorImpl][readFromResourcesFile][IOException] " + ex.getMessage());
LOGGER.severe("[ERROR][SailingSimulatorImpl][readFromResourcesFile][IOException] " + ex.getMessage());
result = null;
}
return result;
}
private static boolean saveStringListToFiles(List<String> legsNames, String fileName) {
if (legsNames == null) {
return false;
}
if (legsNames.isEmpty()) {
return true;
}
if (pathPrefix == null) {
pathPrefix = getPathPrefix();
}
String filePath = pathPrefix + "\\src\\resources\\" + fileName;
boolean result = true;
try {
OutputStream file = new FileOutputStream(filePath);
OutputStream buffer = new BufferedOutputStream(file);
ObjectOutput output = new ObjectOutputStream(buffer);
try {
output.writeObject(legsNames);
} finally {
output.close();
buffer.close();
file.close();
}
} catch (IOException ex) {
System.err.println("[ERROR][SailingSimulatorImpl][saveLegsNamesToFiles][IOException] " + ex.getMessage());
LOGGER.severe("[ERROR][SailingSimulatorImpl][saveLegsNamesToFiles][IOException] " + ex.getMessage());
result = false;
}
return result;
}
private static String getRaceID(String raceURL) {
String result = null;
if (raceURL.contains("&race=")) {
String[] parts = raceURL.split("&");
for (String part : parts) {
if (part.startsWith("race=")) {
result = part.replace("race=", "");
}
}
} else if (raceURL.contains("?race=")) {
String[] parts = raceURL.split("?");
for (String part : parts) {
if (part.startsWith("race=")) {
result = part.replace("race=", "");
}
}
}
return result;
}
private static String getFileName(int selectedRaceIndex, int selectedCompetitorIndex, int selectedLegIndex, String pathName) {
return getRaceID(ConfigurationManager.INSTANCE.getRaceURL(selectedRaceIndex)) + "_" + selectedCompetitorIndex + "_" + selectedLegIndex + "_" + pathName
+ ".dat";
}
}
@@ -1,312 +0,0 @@
package com.sap.sailing.simulator.util;
import java.io.BufferedInputStream;
import java.io.BufferedOutputStream;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInput;
import java.io.ObjectInputStream;
import java.io.ObjectOutput;
import java.io.ObjectOutputStream;
import java.io.OutputStream;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.logging.Logger;
import org.osgi.framework.FrameworkUtil;
import com.sap.sailing.domain.common.impl.Util.Pair;
import com.sap.sailing.simulator.Path;
import com.sap.sailing.simulator.impl.ConfigurationManager;
public class SerializationUtils {
private static final Logger LOGGER = Logger.getLogger("com.sap.sailing.simulator");
public static final String LEGSNAMES_DAT = "legsNames.dat";
public static final String RACECOURSE_DAT = "racecourse.dat";
public static final String COMPETITORSNAMES_DAT = "competitorsNames.dat";
public static final String[] PATH_NAMES = new String[] { "1#Omniscient", "2#Opportunistic", "3#1-Turner Left", "4#1-Turner Right", "6#GPS Poly",
"7#GPS Track" };
public static String pathPrefix = null;
public static String getPathPrefix() {
String bundleName = null;
try {
bundleName = FrameworkUtil.getBundle(Class.forName("com.sap.sailing.simulator.impl.SailingSimulatorImpl")).getSymbolicName();
} catch (ClassNotFoundException e) {
System.err.println("[ERROR][SerializationUtils][getPathPrefix][ClassNotFoundException] " + e.getMessage());
LOGGER.severe("[ERROR][SerializationUtils][getPathPrefix][ClassNotFoundException] " + e.getMessage());
return null;
}
String bundlesProperty = System.getProperty("osgi.bundles");
int bundleNameStart = bundlesProperty.indexOf(bundleName);
int bundleNameEnd = bundleNameStart + bundleName.length();
String prependedBundlePath = bundlesProperty.substring(0, bundleNameEnd);
int prefixPos = prependedBundlePath.lastIndexOf("reference:file:");
if (prefixPos >= 0) {
prependedBundlePath = prependedBundlePath.substring(prefixPos + 15, prependedBundlePath.length());
}
return prependedBundlePath;
}
public static boolean savePathsToFiles(Map<String, Path> paths, Path raceCourse) {
if (paths == null) {
return false;
}
if (paths.isEmpty()) {
return true;
}
if (pathPrefix == null) {
pathPrefix = getPathPrefix();
}
String filePath = "";
boolean result = true;
for (String name : PATH_NAMES) {
filePath = pathPrefix + "\\src\\resources\\" + name + ".dat";
result &= saveToFile(paths.get(name), filePath);
}
filePath = pathPrefix + "\\src\\resources\\" + RACECOURSE_DAT;
result &= saveToFile(raceCourse, filePath);
return result;
}
public static boolean saveLegPathsToFiles(Map<String, Path> paths, Path raceCourse, int selectedRaceIndex, int selectedCompetitorIndex, int selectedLegIndex) {
if (paths == null) {
return false;
}
if (paths.isEmpty()) {
return true;
}
if (pathPrefix == null) {
pathPrefix = getPathPrefix();
}
String filePath = "";
String fileName = "";
boolean result = true;
for (String name : PATH_NAMES) {
fileName = SerializationUtils.getFileName(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex, name);
filePath = pathPrefix + "\\src\\resources\\" + fileName;
result &= saveToFile(paths.get(name), filePath);
}
fileName = SerializationUtils.getFileName(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex, "racecourse");
filePath = pathPrefix + "\\src\\resources\\" + fileName;
result &= saveToFile(raceCourse, filePath);
return result;
}
public static boolean saveToFile(Path path, String fileName) {
boolean result = true;
try {
OutputStream file = new FileOutputStream(fileName);
OutputStream buffer = new BufferedOutputStream(file);
ObjectOutput output = new ObjectOutputStream(buffer);
try {
output.writeObject(path);
} finally {
output.close();
buffer.close();
file.close();
}
} catch (IOException ex) {
System.err.println("[ERROR][SerializationUtils][saveToFile][IOException] " + ex.getMessage());
LOGGER.severe("[ERROR][SerializationUtils][saveToFile][IOException] " + ex.getMessage());
result = false;
}
return result;
}
public static Pair<Map<String, Path>, Path> readLegPathsFromResources(int selectedRaceIndex, int selectedCompetitorIndex, int selectedLegIndex) {
HashMap<String, Path> paths = new HashMap<String, Path>();
Path path = null;
String filePath = "";
String fileName = "";
for (String pathName : PATH_NAMES) {
fileName = SerializationUtils.getFileName(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex, pathName);
filePath = "resources/" + fileName;
path = (Path) readObjectFromResources(filePath);
if (path == null) {
System.err.println("[ERROR][SerializationUtils][readPathsFromResources] Cannot de-serialize path from" + pathName);
LOGGER.severe("[ERROR][SerializationUtils][readPathsFromResources] Cannot de-serialize path from" + pathName);
} else {
paths.put(pathName, path);
}
}
Path raceCourse = (Path) readObjectFromResources("resources/"
+ SerializationUtils.getFileName(selectedRaceIndex, selectedCompetitorIndex, selectedLegIndex, "racecourse"));
return new Pair<Map<String, Path>, Path>(paths, raceCourse);
}
public static Pair<Map<String, Path>, Path> readPathsFromResources() {
HashMap<String, Path> paths = new HashMap<String, Path>();
Path path = null;
String filePath = "";
for (String pathName : PATH_NAMES) {
filePath = "resources/" + pathName + ".dat";
path = (Path) readObjectFromResources(filePath);
if (path == null) {
System.err.println("[ERROR][SerializationUtils][readPathsFromResources] Cannot de-serialize path from" + pathName);
LOGGER.severe("[ERROR][SerializationUtils][readPathsFromResources] Cannot de-serialize path from" + pathName);
} else {
paths.put(pathName, path);
}
}
Path raceCourse = (Path) readObjectFromResources("resources/" + RACECOURSE_DAT);
return new Pair<Map<String, Path>, Path>(paths, raceCourse);
}
public static Object readObjectExternalFile(String fileName) {
Object result = null;
try {
InputStream file = new FileInputStream(fileName);
InputStream buffer = new BufferedInputStream(file);
ObjectInput input = new ObjectInputStream(buffer);
try {
result = input.readObject();
} finally {
input.close();
buffer.close();
file.close();
}
} catch (ClassNotFoundException ex) {
System.err.println("[ERROR][SerializationUtils][readFromExternalFile][ClassNotFoundException] " + ex.getMessage());
LOGGER.severe("[ERROR][SerializationUtils][readFromExternalFile][ClassNotFoundException] " + ex.getMessage());
result = null;
} catch (IOException ex) {
System.err.println("[ERROR][SerializationUtils][readFromExternalFile][IOException] " + ex.getMessage());
LOGGER.severe("[ERROR][SerializationUtils][readFromExternalFile][IOException] " + ex.getMessage());
result = null;
}
return result;
}
public static Object readObjectFromResources(String fileName) {
Object result = null;
try {
ClassLoader classLoader = Class.forName("com.sap.sailing.simulator.impl.SailingSimulatorImpl").getClassLoader();
InputStream file = classLoader.getResourceAsStream(fileName);
InputStream buffer = new BufferedInputStream(file);
ObjectInput input = new ObjectInputStream(buffer);
try {
result = input.readObject();
} finally {
input.close();
buffer.close();
file.close();
}
} catch (ClassNotFoundException ex) {
System.err.println("[ERROR][SerializationUtils][readFromResourcesFile][ClassNotFoundException] " + ex.getMessage());
LOGGER.severe("[ERROR][SerializationUtils][readFromResourcesFile][ClassNotFoundException] " + ex.getMessage());
result = null;
} catch (IOException ex) {
System.err.println("[ERROR][SerializationUtils][readFromResourcesFile][IOException] " + ex.getMessage());
LOGGER.severe("[ERROR][SerializationUtils][readFromResourcesFile][IOException] " + ex.getMessage());
result = null;
}
return result;
}
public static boolean saveStringListToFiles(List<String> legsNames, String fileName) {
if (legsNames == null) {
return false;
}
if (legsNames.isEmpty()) {
return true;
}
if (pathPrefix == null) {
pathPrefix = getPathPrefix();
}
String filePath = pathPrefix + "\\src\\resources\\" + fileName;
boolean result = true;
try {
OutputStream file = new FileOutputStream(filePath);
OutputStream buffer = new BufferedOutputStream(file);
ObjectOutput output = new ObjectOutputStream(buffer);
try {
output.writeObject(legsNames);
} finally {
output.close();
buffer.close();
file.close();
}
} catch (IOException ex) {
System.err.println("[ERROR][SerializationUtils][saveLegsNamesToFiles][IOException] " + ex.getMessage());
LOGGER.severe("[ERROR][SerializationUtils][saveLegsNamesToFiles][IOException] " + ex.getMessage());
result = false;
}
return result;
}
public static String getRaceID(String raceURL) {
String result = null;
if (raceURL.contains("&race=")) {
String[] parts = raceURL.split("&");
for (String part : parts) {
if (part.startsWith("race=")) {
result = part.replace("race=", "");
}
}
} else if (raceURL.contains("?race=")) {
String[] parts = raceURL.split("?");
for (String part : parts) {
if (part.startsWith("race=")) {
result = part.replace("race=", "");
}
}
}
return result;
}
public static String getFileName(int selectedRaceIndex, int selectedCompetitorIndex, int selectedLegIndex, String pathName) {
return SerializationUtils.getRaceID(ConfigurationManager.INSTANCE.getRaceURL(selectedRaceIndex)) + "_" + selectedCompetitorIndex + "_"
+ selectedLegIndex + "_" + pathName + ".dat";
}
}
@@ -61,20 +61,49 @@ public class WindFieldGeneratorMeasured extends WindFieldGeneratorImpl implement
String errorMessage = null;
if (p1 == null) {
errorMessage = "ERROR: couldn't find the before time point, interpolation will now fail!";
System.err.println(errorMessage);
System.out.println(errorMessage);
LOGGER.severe(errorMessage);
}
if (p2 == null) {
errorMessage = "ERROR: couldn't find the after time point, interpolation will now fail!";
System.err.println(errorMessage);
System.out.println(errorMessage);
LOGGER.severe(errorMessage);
}
// TODO: interpolate between p1 and p2
// TODO: check for race with true wind measurement; current test race has everyone 1kn wind speed
//System.out.println("bear p1: "+p1.getSpeed().getBearing().getDegrees()+" p2: "+p2.getSpeed().getBearing().getDegrees());
Bearing midBear = new DegreeBearingImpl((p1.getSpeed().getBearing().getDegrees() + p2.getSpeed().getBearing().getDegrees()) / 2.);
SpeedWithBearing s1 = p1.getSpeed();
if (s1 == null) {
errorMessage = "ERROR: p1.getSpeed() is null!";
System.out.println(errorMessage);
LOGGER.severe(errorMessage);
}
Bearing b1 = s1.getBearing();
if (b1 == null) {
errorMessage = "ERROR: p1.getSpeed().getBearing(); is null!";
System.out.println(errorMessage);
LOGGER.severe(errorMessage);
}
SpeedWithBearing s2 = p2.getSpeed();
if (s2 == null) {
errorMessage = "ERROR: p2.getSpeed() is null!";
System.out.println(errorMessage);
LOGGER.severe(errorMessage);
}
Bearing b2 = s2.getBearing();
if (b2 == null) {
errorMessage = "ERROR: p2.getSpeed().getBearing(); is null!";
System.out.println(errorMessage);
LOGGER.severe(errorMessage);
}
Bearing midBear = new DegreeBearingImpl((b1.getDegrees() + b2.getDegrees()) / 2.);
SpeedWithBearing speedWithBearing = new KnotSpeedWithBearingImpl((p1.getSpeed().getKnots()+p2.getSpeed().getKnots())/2., midBear);
return new WindImpl(timedPosition.getPosition(), timedPosition.getTimePoint(), speedWithBearing);