mirror of
https://github.com/eclipse-sailing-analytics/sailing-analytics.git
synced 2026-10-17 01:31:01 +00:00
Merge remote-tracking branch 'origin/simulator_dev' into simulator_dev
This commit is contained in:
commit
e6e0a6e12a
3 files changed
+202
-128
No files matched your search
+78
-66
@@ -1,10 +1,10 @@
|
||||
package com.sap.sailing.gwt.ui.shared.racemap;
|
||||
|
||||
public class TwoDPoint {
|
||||
private double x;
|
||||
private double y;
|
||||
private final double x;
|
||||
private final double y;
|
||||
|
||||
public TwoDPoint(double x, double y) {
|
||||
public TwoDPoint(final double x, final double y) {
|
||||
this.x = x;
|
||||
this.y = y;
|
||||
}
|
||||
@@ -17,19 +17,19 @@ public class TwoDPoint {
|
||||
return this.y;
|
||||
}
|
||||
|
||||
public double distanceBetween(TwoDPoint point) {
|
||||
public double distanceBetween(final TwoDPoint point) {
|
||||
return distanceBetween(this.x, this.y, point.getX(), point.getY());
|
||||
}
|
||||
|
||||
public double distanceBetween(double x, double y) {
|
||||
public double distanceBetween(final double x, final double y) {
|
||||
return distanceBetween(this.x, this.y, x, y);
|
||||
}
|
||||
|
||||
public static double distanceBetween(double x1, double y1, double x2, double y2) {
|
||||
public static double distanceBetween(final double x1, final double y1, final double x2, final double y2) {
|
||||
return Math.sqrt(Math.pow((x2 - x1), 2) + Math.pow((y2 - y1), 2));
|
||||
}
|
||||
|
||||
public static double distanceBetween(TwoDPoint point1, TwoDPoint point2) {
|
||||
public static double distanceBetween(final TwoDPoint point1, final TwoDPoint point2) {
|
||||
return distanceBetween(point1.getX(), point1.getY(), point2.getX(), point2.getY());
|
||||
}
|
||||
|
||||
@@ -39,15 +39,18 @@ public class TwoDPoint {
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object obj) {
|
||||
if (obj == null)
|
||||
public boolean equals(final Object obj) {
|
||||
if (obj == null) {
|
||||
return false;
|
||||
if (obj == this)
|
||||
}
|
||||
if (obj == this) {
|
||||
return true;
|
||||
if (obj.getClass() != getClass())
|
||||
}
|
||||
if (obj.getClass() != getClass()) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TwoDPoint other = (TwoDPoint) obj;
|
||||
final TwoDPoint other = (TwoDPoint) obj;
|
||||
return this.x == other.getX() && this.y == other.getY();
|
||||
}
|
||||
|
||||
@@ -56,111 +59,120 @@ public class TwoDPoint {
|
||||
return 31 * (new Double(this.x).hashCode()) * (new Double(this.y).hashCode());
|
||||
}
|
||||
|
||||
public static TwoDPoint getDistancedPoint(TwoDPoint distancedFromPoint, double length, TwoDPoint startPoint) {
|
||||
TwoDVector vector = new TwoDVector(startPoint, distancedFromPoint).normalize().multiplyScalar(length);
|
||||
public static TwoDPoint getDistancedPoint(final TwoDPoint distancedFromPoint, final double length, final TwoDPoint startPoint) {
|
||||
final TwoDVector vector = new TwoDVector(startPoint, distancedFromPoint).normalize().multiplyScalar(length);
|
||||
|
||||
double x = distancedFromPoint.getX() + vector.getRe();
|
||||
double y = distancedFromPoint.getY() + vector.getIm();
|
||||
final double x = distancedFromPoint.getX() + vector.getRe();
|
||||
final double y = distancedFromPoint.getY() + vector.getIm();
|
||||
|
||||
return new TwoDPoint(x, y);
|
||||
}
|
||||
|
||||
public static TwoDPoint getBisectingPoint(TwoDPoint origin, TwoDPoint head1, TwoDPoint head2, double scale) {
|
||||
TwoDVector v1 = new TwoDVector(origin, head1);
|
||||
TwoDVector v2 = new TwoDVector(origin, head2);
|
||||
public static TwoDPoint getBisectingPoint(final TwoDPoint origin, final TwoDPoint head1, final TwoDPoint head2, final double scale) {
|
||||
final TwoDVector v1 = new TwoDVector(origin, head1);
|
||||
final TwoDVector v2 = new TwoDVector(origin, head2);
|
||||
|
||||
TwoDVector sum = (v1.normalize()).add(v2.normalize()).normalize().multiplyScalar(scale);
|
||||
final TwoDVector sum = (v1.normalize()).add(v2.normalize()).normalize().multiplyScalar(scale);
|
||||
|
||||
return new TwoDPoint(sum.getRe() + origin.getX(), sum.getIm() + origin.getY());
|
||||
}
|
||||
|
||||
public static TwoDPoint get90RotatedPoint(TwoDPoint origin, TwoDPoint head) {
|
||||
public static TwoDPoint get90RotatedPoint(final TwoDPoint origin, final TwoDPoint head) {
|
||||
return getRotatedPoint(origin, head, 90);
|
||||
}
|
||||
|
||||
public static TwoDPoint get270RotatedPoint(TwoDPoint origin, TwoDPoint head) {
|
||||
public static TwoDPoint get270RotatedPoint(final TwoDPoint origin, final TwoDPoint head) {
|
||||
return getRotatedPoint(origin, head, 270);
|
||||
}
|
||||
|
||||
public static TwoDPoint getRotatedPoint(TwoDPoint origin, TwoDPoint head, double degrees) {
|
||||
public static TwoDPoint getRotatedPoint(final TwoDPoint origin, final TwoDPoint head, final double degrees) {
|
||||
TwoDVector v = new TwoDVector(origin, head);
|
||||
v = v.rotate(degrees);
|
||||
|
||||
return new TwoDPoint(v.getRe() + origin.getX(), v.getIm() + origin.getY());
|
||||
}
|
||||
|
||||
public static TwoDPoint getCorrectProjection(TwoDPoint origin, TwoDPoint head1, TwoDPoint head2, TwoDPoint newOrigin) {
|
||||
TwoDSegment oh1 = new TwoDSegment(origin, head1);
|
||||
TwoDPoint p1 = oh1.projectionOfPointOnLine(newOrigin);
|
||||
double d1 = newOrigin.distanceBetween(p1);
|
||||
public static TwoDPoint getCorrectProjection(final TwoDPoint origin, final TwoDPoint head1, final TwoDPoint head2, final TwoDPoint newOrigin) {
|
||||
final TwoDSegment oh1 = new TwoDSegment(origin, head1);
|
||||
final TwoDPoint p1 = oh1.projectionOfPointOnLine(newOrigin);
|
||||
final double d1 = newOrigin.distanceBetween(p1);
|
||||
|
||||
TwoDSegment oh2 = new TwoDSegment(origin, head2);
|
||||
TwoDPoint p2 = oh2.projectionOfPointOnLine(newOrigin);
|
||||
double d2 = newOrigin.distanceBetween(p2);
|
||||
final TwoDSegment oh2 = new TwoDSegment(origin, head2);
|
||||
final TwoDPoint p2 = oh2.projectionOfPointOnLine(newOrigin);
|
||||
final double d2 = newOrigin.distanceBetween(p2);
|
||||
|
||||
return (d1 < d2) ? p1 : p2;
|
||||
}
|
||||
|
||||
public static TwoDPoint projectToLineByVector(TwoDPoint newOrigin, TwoDSegment line, TwoDVector vector) {
|
||||
double a = vector.getRe();
|
||||
double b = vector.getIm();
|
||||
double p = line.getLineSlope();
|
||||
double q = line.getLineIntercept();
|
||||
double x0 = newOrigin.getX();
|
||||
double y0 = newOrigin.getY();
|
||||
public static TwoDPoint projectToLineByVector(final TwoDPoint newOrigin, final TwoDSegment line, final TwoDVector vector) {
|
||||
final double a = vector.getRe();
|
||||
final double b = vector.getIm();
|
||||
final double p = line.getLineSlope();
|
||||
final double q = line.getLineIntercept();
|
||||
final double x0 = newOrigin.getX();
|
||||
final double y0 = newOrigin.getY();
|
||||
|
||||
double x = ((q - y0) / b + x0 / a) / (1 / a - p / b);
|
||||
double y = p * x + q;
|
||||
final double x = ((q - y0) / b + x0 / a) / (1 / a - p / b);
|
||||
final double y = p * x + q;
|
||||
|
||||
return new TwoDPoint(x, y);
|
||||
}
|
||||
|
||||
// A //B //C //B'
|
||||
public static boolean isOnTheInside(TwoDPoint beforePoint, TwoDPoint origin, TwoDPoint afterPoint,
|
||||
TwoDPoint newOrigin) {
|
||||
TwoDSegment ab = new TwoDSegment(beforePoint, origin);
|
||||
public static boolean isOnTheInside(final TwoDPoint beforePoint, final TwoDPoint origin, final TwoDPoint afterPoint,
|
||||
final TwoDPoint newOrigin) {
|
||||
final TwoDSegment ab = new TwoDSegment(beforePoint, origin);
|
||||
|
||||
double valueOf_C_AB = ab.getLineSlope() * afterPoint.x - afterPoint.y + ab.getLineIntercept();
|
||||
double valueOf_Bfirst_AB = ab.getLineSlope() * newOrigin.x - newOrigin.y + ab.getLineIntercept();
|
||||
final double valueOf_C_AB = ab.getLineSlope() * afterPoint.x - afterPoint.y + ab.getLineIntercept();
|
||||
final double valueOf_Bfirst_AB = ab.getLineSlope() * newOrigin.x - newOrigin.y + ab.getLineIntercept();
|
||||
|
||||
boolean sameSide_BFirst_C_AB = ((valueOf_C_AB * valueOf_Bfirst_AB) > 0);
|
||||
final boolean sameSide_BFirst_C_AB = ((valueOf_C_AB * valueOf_Bfirst_AB) > 0);
|
||||
|
||||
if (sameSide_BFirst_C_AB == false)
|
||||
if (sameSide_BFirst_C_AB == false) {
|
||||
return false;
|
||||
}
|
||||
|
||||
TwoDSegment bc = new TwoDSegment(origin, afterPoint);
|
||||
final TwoDSegment bc = new TwoDSegment(origin, afterPoint);
|
||||
|
||||
double valueOf_A_BC = bc.getLineSlope() * beforePoint.x - beforePoint.y + bc.getLineIntercept();
|
||||
double valueOf_Bfirst_BC = bc.getLineSlope() * newOrigin.x - newOrigin.y + bc.getLineIntercept();
|
||||
final double valueOf_A_BC = bc.getLineSlope() * beforePoint.x - beforePoint.y + bc.getLineIntercept();
|
||||
final double valueOf_Bfirst_BC = bc.getLineSlope() * newOrigin.x - newOrigin.y + bc.getLineIntercept();
|
||||
|
||||
boolean sameSide_BFirst_A_BC = ((valueOf_A_BC * valueOf_Bfirst_BC) > 0);
|
||||
final boolean sameSide_BFirst_A_BC = ((valueOf_A_BC * valueOf_Bfirst_BC) > 0);
|
||||
|
||||
return sameSide_BFirst_A_BC;
|
||||
}
|
||||
|
||||
// A //B //C //Bfirst
|
||||
public static TwoDSegment getBeforeNew(TwoDPoint beforePoint, TwoDPoint origin, TwoDPoint afterPoint,
|
||||
TwoDPoint newOrigin) {
|
||||
TwoDSegment AB = new TwoDSegment(beforePoint, origin);
|
||||
double slopeAB = AB.getLineSlope();
|
||||
double interceptAB = AB.getLineIntercept();
|
||||
public static TwoDSegment getBeforeNew(final TwoDPoint beforePoint, final TwoDPoint origin, final TwoDPoint afterPoint,
|
||||
final TwoDPoint newOrigin) {
|
||||
final TwoDSegment AB = new TwoDSegment(beforePoint, origin);
|
||||
final double slopeAB = AB.getLineSlope();
|
||||
final double interceptAB = AB.getLineIntercept();
|
||||
|
||||
TwoDSegment BC = new TwoDSegment(origin, afterPoint);
|
||||
double slopeBC = BC.getLineSlope();
|
||||
double interceptBC = BC.getLineIntercept();
|
||||
final TwoDSegment BC = new TwoDSegment(origin, afterPoint);
|
||||
final double slopeBC = BC.getLineSlope();
|
||||
final double interceptBC = BC.getLineIntercept();
|
||||
|
||||
double temp1 = origin.x + newOrigin.x;
|
||||
double temp2 = origin.y + newOrigin.y - interceptAB - interceptBC;
|
||||
final double temp1 = origin.x + newOrigin.x;
|
||||
final double temp2 = origin.y + newOrigin.y - interceptAB - interceptBC;
|
||||
|
||||
double beforeFx = (temp1 - temp2 / slopeBC) / (1 - slopeAB / slopeBC);
|
||||
double beforeFy = slopeAB * beforeFx + interceptAB;
|
||||
final double beforeFx = (temp1 - temp2 / slopeBC) / (1 - slopeAB / slopeBC);
|
||||
final double beforeFy = slopeAB * beforeFx + interceptAB;
|
||||
|
||||
double afterFx = (temp1 - temp2 / slopeAB) / (1 - slopeBC / slopeAB);
|
||||
double afterFy = slopeBC * afterFx + interceptBC;
|
||||
final double afterFx = (temp1 - temp2 / slopeAB) / (1 - slopeBC / slopeAB);
|
||||
final double afterFy = slopeBC * afterFx + interceptBC;
|
||||
|
||||
TwoDPoint beforeF = new TwoDPoint(beforeFx, beforeFy);
|
||||
TwoDPoint afterF = new TwoDPoint(afterFx, afterFy);
|
||||
final TwoDPoint beforeF = new TwoDPoint(beforeFx, beforeFy);
|
||||
final TwoDPoint afterF = new TwoDPoint(afterFx, afterFy);
|
||||
|
||||
return new TwoDSegment(beforeF, afterF);
|
||||
}
|
||||
|
||||
public static boolean areInClockwiseOrder(final TwoDPoint A, final TwoDPoint B, final TwoDPoint C) {
|
||||
return (C.y - A.y) * (B.x - A.x) > (B.y - A.y) * (C.x - A.x);
|
||||
}
|
||||
|
||||
public static boolean areIntersecting(final TwoDPoint A, final TwoDPoint B, final TwoDPoint C, final TwoDPoint D) {
|
||||
return (areInClockwiseOrder(A, C, D) != areInClockwiseOrder(B, C, D)) && (areInClockwiseOrder(A, B, C) != areInClockwiseOrder(A, B, D));
|
||||
}
|
||||
}
|
||||
+37
-6
@@ -1,5 +1,6 @@
|
||||
package com.sap.sailing.gwt.ui.shared.racemap;
|
||||
|
||||
|
||||
public class TwoDSegment {
|
||||
private double lineSlope = 0.0;
|
||||
private double lineIntercept = 0.0;
|
||||
@@ -7,11 +8,11 @@ public class TwoDSegment {
|
||||
private TwoDPoint firstPoint = null;
|
||||
private TwoDPoint secondPoint = null;
|
||||
|
||||
public TwoDSegment(TwoDPoint p1, TwoDPoint p2) {
|
||||
public TwoDSegment(final TwoDPoint p1, final TwoDPoint p2) {
|
||||
this(p1.getX(), p1.getY(), p2.getX(), p2.getY());
|
||||
}
|
||||
|
||||
public TwoDSegment(double x1, double y1, double x2, double y2) {
|
||||
public TwoDSegment(final double x1, final double y1, final double x2, final double y2) {
|
||||
if (x1 == x2) {
|
||||
// FIXME:
|
||||
// this.slope = Double.MAX_VALUE;
|
||||
@@ -33,15 +34,15 @@ public class TwoDSegment {
|
||||
return this.lineIntercept;
|
||||
}
|
||||
|
||||
public TwoDPoint projectionOfPointOnLine(TwoDPoint p) {
|
||||
double x = (this.lineSlope * p.getY() + p.getX() - this.lineSlope * this.lineIntercept)
|
||||
public TwoDPoint projectionOfPointOnLine(final TwoDPoint p) {
|
||||
final double x = (this.lineSlope * p.getY() + p.getX() - this.lineSlope * this.lineIntercept)
|
||||
/ (this.lineSlope * this.lineSlope + 1);
|
||||
double y = this.lineSlope * x + this.lineIntercept;
|
||||
final double y = this.lineSlope * x + this.lineIntercept;
|
||||
|
||||
return new TwoDPoint(x, y);
|
||||
}
|
||||
|
||||
public double distanceToLine(TwoDPoint p) {
|
||||
public double distanceToLine(final TwoDPoint p) {
|
||||
return TwoDPoint.distanceBetween(p, this.projectionOfPointOnLine(p));
|
||||
}
|
||||
|
||||
@@ -61,4 +62,34 @@ public class TwoDSegment {
|
||||
public TwoDVector asVector() {
|
||||
return new TwoDVector(this.firstPoint, this.secondPoint);
|
||||
}
|
||||
|
||||
public static boolean areIntersecting(final TwoDSegment s1, final TwoDSegment s2) {
|
||||
return TwoDPoint.areIntersecting(s1.firstPoint, s1.secondPoint, s2.firstPoint, s2.secondPoint);
|
||||
}
|
||||
|
||||
public TwoDPoint intersectionPointWith(final TwoDSegment segment2) {
|
||||
return getIntersectionPoint(this, segment2);
|
||||
}
|
||||
|
||||
public static TwoDPoint getIntersectionPoint(final TwoDSegment segment1, final TwoDSegment segment2) {
|
||||
|
||||
final double x1 = segment1.firstPoint.getX();
|
||||
final double x2 = segment1.secondPoint.getX();
|
||||
final double x3 = segment2.firstPoint.getX();
|
||||
final double x4 = segment2.secondPoint.getX();
|
||||
|
||||
final double y1 = segment1.firstPoint.getY();
|
||||
final double y2 = segment1.secondPoint.getY();
|
||||
final double y3 = segment2.firstPoint.getY();
|
||||
final double y4 = segment2.secondPoint.getY();
|
||||
|
||||
final double temp1 = (y2 - y1) / (x2 - x1);
|
||||
final double temp2 = (y4 - y3) / (x4 - x3);
|
||||
|
||||
final double x = (y3 - y1 + x1 * temp1 - x3 * temp2) / (temp1 - temp2);
|
||||
final double y = x * temp1 + y1 - x1 * temp1;
|
||||
|
||||
return new TwoDPoint(x, y);
|
||||
}
|
||||
|
||||
}
|
||||
+87
-56
@@ -28,7 +28,6 @@ public class PathPolyline {
|
||||
private static final boolean DRAW_DISTANCED_DASHLINES = false;
|
||||
private static final boolean DRAW_BISECTOR_DASHLINES = false;
|
||||
private static final boolean DRAW_VERTICAL_DASHLINES = false;
|
||||
private static final boolean DRAW_SHADOW_DASHLINES = false;
|
||||
|
||||
public static final String DEFAULT_COLOR = "#8B0000";
|
||||
private static final int DEFAULT_WEIGHT = 3;
|
||||
@@ -43,8 +42,6 @@ public class PathPolyline {
|
||||
private Polyline polyline = null;
|
||||
private LatLng[] turnPoints = null;
|
||||
|
||||
private Polyline shadowPolyline = null;
|
||||
private List<LatLng> shadowPoints = null;
|
||||
private List<Polyline> dashedLines = null;
|
||||
|
||||
private String color = "";
|
||||
@@ -94,7 +91,6 @@ public class PathPolyline {
|
||||
|
||||
this.dashedLines = new ArrayList<Polyline>();
|
||||
this.originAndHeads = new HashMap<TwoDPoint, List<TwoDPoint>>();
|
||||
this.shadowPoints = new ArrayList<LatLng>();
|
||||
|
||||
this.allPoints = pathPoints;
|
||||
this.simulatorService = simulatorService;
|
||||
@@ -131,25 +127,20 @@ public class PathPolyline {
|
||||
if (indexOfMovedPoint == 0 || indexOfMovedPoint == noOfPoints - 1) {
|
||||
// start and end points cannot be moved!
|
||||
} else {
|
||||
// boolean isOnTheInside = TwoDPoint.isOnTheInside(
|
||||
// convertToTwoDPoint(points[indexOfMovedPoint - 1]),
|
||||
// convertToTwoDPoint(points[indexOfMovedPoint]),
|
||||
// convertToTwoDPoint(points[indexOfMovedPoint - 1]),
|
||||
// convertToTwoDPoint(polyline.getVertex(indexOfMovedPoint)));
|
||||
// System.out.println("\r\nXXX: Moved point: " + indexOfMovedPoint);
|
||||
// System.out.println("\r\nXXX: Is on the inside: " + isOnTheInside);
|
||||
// System.err.println("INDEX OF MOVED POINT = " + indexOfMovedPoint);
|
||||
|
||||
final double distance = (map.getZoomLevel() - 11) * DEFAULT_DISTANCE_PX;
|
||||
|
||||
final TwoDPoint origin = convertToTwoDPoint(turnPoints[indexOfMovedPoint]);
|
||||
final TwoDPoint head1 = TwoDPoint.getDistancedPoint(origin, distance, convertToTwoDPoint(turnPoints[indexOfMovedPoint - 1]));
|
||||
final TwoDPoint head2 = TwoDPoint.getDistancedPoint(origin, distance, convertToTwoDPoint(turnPoints[indexOfMovedPoint + 1]));
|
||||
final TwoDPoint newOrigin = TwoDPoint.getCorrectProjection(origin, head1, head2, convertToTwoDPoint(polyline.getVertex(indexOfMovedPoint)));
|
||||
TwoDPoint beforeBeforeOrigin = null;
|
||||
final TwoDPoint beforeOrigin = toTwoDPoint(turnPoints[indexOfMovedPoint - 1]);
|
||||
final TwoDPoint origin = toTwoDPoint(turnPoints[indexOfMovedPoint]);
|
||||
final TwoDPoint afterOrigin = toTwoDPoint(turnPoints[indexOfMovedPoint + 1]);
|
||||
TwoDPoint afterAfterOrigin = null;
|
||||
|
||||
shadowPoints.clear();
|
||||
for (final LatLng point : turnPoints) {
|
||||
shadowPoints.add(point);
|
||||
}
|
||||
final TwoDPoint head1 = TwoDPoint.getDistancedPoint(origin, distance, beforeOrigin);
|
||||
final TwoDPoint head2 = TwoDPoint.getDistancedPoint(origin, distance, afterOrigin);
|
||||
|
||||
final TwoDPoint newOrigin = TwoDPoint.getCorrectProjection(origin, head1, head2, toTwoDPoint(polyline.getVertex(indexOfMovedPoint)));
|
||||
|
||||
TwoDSegment afterLine = null;
|
||||
TwoDVector afterVector = null;
|
||||
@@ -159,33 +150,82 @@ public class PathPolyline {
|
||||
TwoDPoint beforeNewOrigin = null;
|
||||
|
||||
if (indexOfMovedPoint == 1) {
|
||||
afterLine = new TwoDSegment(convertToTwoDPoint(turnPoints[indexOfMovedPoint + 1]), convertToTwoDPoint(turnPoints[indexOfMovedPoint + 2]));
|
||||
afterVector = new TwoDVector(origin, convertToTwoDPoint(turnPoints[indexOfMovedPoint + 1]));
|
||||
|
||||
afterAfterOrigin = toTwoDPoint(turnPoints[indexOfMovedPoint + 2]);
|
||||
|
||||
afterLine = new TwoDSegment(afterOrigin, afterAfterOrigin);
|
||||
afterVector = new TwoDVector(origin, afterOrigin);
|
||||
afterNewOrigin = TwoDPoint.projectToLineByVector(newOrigin, afterLine, afterVector);
|
||||
|
||||
turnPoints[indexOfMovedPoint] = convertToLatLng(newOrigin);
|
||||
turnPoints[indexOfMovedPoint + 1] = convertToLatLng(afterNewOrigin);
|
||||
turnPoints[indexOfMovedPoint] = toLatLng(newOrigin);
|
||||
turnPoints[indexOfMovedPoint + 1] = toLatLng(afterNewOrigin);
|
||||
|
||||
} else if (indexOfMovedPoint == noOfPoints - 2) {
|
||||
beforeLine = new TwoDSegment(convertToTwoDPoint(turnPoints[indexOfMovedPoint - 2]), convertToTwoDPoint(turnPoints[indexOfMovedPoint - 1]));
|
||||
beforeVector = new TwoDVector(convertToTwoDPoint(turnPoints[indexOfMovedPoint - 1]), origin);
|
||||
|
||||
beforeBeforeOrigin = toTwoDPoint(turnPoints[indexOfMovedPoint - 2]);
|
||||
|
||||
beforeLine = new TwoDSegment(beforeBeforeOrigin, beforeOrigin);
|
||||
beforeVector = new TwoDVector(beforeOrigin, origin);
|
||||
beforeNewOrigin = TwoDPoint.projectToLineByVector(newOrigin, beforeLine, beforeVector);
|
||||
|
||||
turnPoints[indexOfMovedPoint - 1] = convertToLatLng(beforeNewOrigin);
|
||||
turnPoints[indexOfMovedPoint] = convertToLatLng(newOrigin);
|
||||
turnPoints[indexOfMovedPoint - 1] = toLatLng(beforeNewOrigin);
|
||||
turnPoints[indexOfMovedPoint] = toLatLng(newOrigin);
|
||||
} else {
|
||||
beforeLine = new TwoDSegment(convertToTwoDPoint(turnPoints[indexOfMovedPoint - 2]), convertToTwoDPoint(turnPoints[indexOfMovedPoint - 1]));
|
||||
beforeVector = new TwoDVector(convertToTwoDPoint(turnPoints[indexOfMovedPoint - 1]), origin);
|
||||
|
||||
beforeBeforeOrigin = toTwoDPoint(turnPoints[indexOfMovedPoint - 2]);
|
||||
afterAfterOrigin = toTwoDPoint(turnPoints[indexOfMovedPoint + 2]);
|
||||
|
||||
beforeLine = new TwoDSegment(beforeBeforeOrigin, beforeOrigin);
|
||||
beforeVector = new TwoDVector(beforeOrigin, origin);
|
||||
beforeNewOrigin = TwoDPoint.projectToLineByVector(newOrigin, beforeLine, beforeVector);
|
||||
|
||||
afterLine = new TwoDSegment(convertToTwoDPoint(turnPoints[indexOfMovedPoint + 1]), convertToTwoDPoint(turnPoints[indexOfMovedPoint + 2]));
|
||||
afterVector = new TwoDVector(origin, convertToTwoDPoint(turnPoints[indexOfMovedPoint + 1]));
|
||||
afterLine = new TwoDSegment(afterOrigin, afterAfterOrigin);
|
||||
afterVector = new TwoDVector(origin, afterOrigin);
|
||||
afterNewOrigin = TwoDPoint.projectToLineByVector(newOrigin, afterLine, afterVector);
|
||||
|
||||
turnPoints[indexOfMovedPoint - 1] = convertToLatLng(beforeNewOrigin);
|
||||
turnPoints[indexOfMovedPoint] = convertToLatLng(newOrigin);
|
||||
turnPoints[indexOfMovedPoint + 1] = convertToLatLng(afterNewOrigin);
|
||||
turnPoints[indexOfMovedPoint - 1] = toLatLng(beforeNewOrigin);
|
||||
turnPoints[indexOfMovedPoint] = toLatLng(newOrigin);
|
||||
turnPoints[indexOfMovedPoint + 1] = toLatLng(afterNewOrigin);
|
||||
}
|
||||
|
||||
if (noOfPoints > 3) {
|
||||
LatLng first = null;
|
||||
LatLng second = null;
|
||||
LatLng third = null;
|
||||
LatLng fourth = null;
|
||||
|
||||
for (int index = 0; (index + 3) < noOfPoints; index++) {
|
||||
first = turnPoints[index];
|
||||
second = turnPoints[index + 1];
|
||||
third = turnPoints[index + 2];
|
||||
fourth = turnPoints[index + 3];
|
||||
|
||||
if (TwoDPoint.areIntersecting(toTwoDPoint(first), toTwoDPoint(second), toTwoDPoint(third), toTwoDPoint(fourth))) {
|
||||
|
||||
final TwoDSegment firstSegment = new TwoDSegment(toTwoDPoint(first),
|
||||
toTwoDPoint(second));
|
||||
final TwoDSegment secondSegment = new TwoDSegment(toTwoDPoint(third),
|
||||
toTwoDPoint(fourth));
|
||||
|
||||
final 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)));
|
||||
} else {
|
||||
newTurnPoints.add(LatLng.newInstance(turnPoints[index2].getLatitude(), turnPoints[index2].getLongitude()));
|
||||
}
|
||||
}
|
||||
|
||||
turnPoints = null;
|
||||
turnPoints = newTurnPoints.toArray(new LatLng[0]);
|
||||
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
drawPolylineOnMap();
|
||||
@@ -287,15 +327,6 @@ public class PathPolyline {
|
||||
for (final Polyline line : this.dashedLines) {
|
||||
this.map.addOverlay(line);
|
||||
}
|
||||
|
||||
if (DRAW_SHADOW_DASHLINES) {
|
||||
if (this.shadowPolyline != null) {
|
||||
this.map.removeOverlay(this.shadowPolyline);
|
||||
}
|
||||
|
||||
this.shadowPolyline = new Polyline(this.shadowPoints.toArray(new LatLng[0]), DEFAULT_COLOR, DEFAULT_DASHLINE_WEIGHT, DEFAULT_OPACITY);
|
||||
this.map.addOverlay(this.shadowPolyline);
|
||||
}
|
||||
}
|
||||
|
||||
private int getIndexOfMovedPoint() {
|
||||
@@ -315,16 +346,16 @@ public class PathPolyline {
|
||||
return index;
|
||||
}
|
||||
|
||||
private TwoDPoint convertToTwoDPoint(final LatLng latLng) {
|
||||
private TwoDPoint toTwoDPoint(final LatLng latLng) {
|
||||
final Point point = this.map.convertLatLngToContainerPixel(latLng);
|
||||
return new TwoDPoint(point.getX(), point.getY());
|
||||
}
|
||||
|
||||
private LatLng convertToLatLng(final TwoDPoint point) {
|
||||
private LatLng toLatLng(final TwoDPoint point) {
|
||||
return this.map.convertContainerPixelToLatLng(Point.newInstance((int) point.getX(), (int) point.getY()));
|
||||
}
|
||||
|
||||
private static PositionDTO convertToPositionDTO(final LatLng position) {
|
||||
private static PositionDTO toPositionDTO(final LatLng position) {
|
||||
return new PositionDTO(position.getLatitude(), position.getLongitude());
|
||||
}
|
||||
|
||||
@@ -345,7 +376,7 @@ public class PathPolyline {
|
||||
final List<PositionDTO> turnPointsAsPositionDTO = new ArrayList<PositionDTO>();
|
||||
|
||||
for (final LatLng point : this.turnPoints) {
|
||||
turnPointsAsPositionDTO.add(convertToPositionDTO(point));
|
||||
turnPointsAsPositionDTO.add(toPositionDTO(point));
|
||||
}
|
||||
|
||||
final RequestTotalTimeDTO requestData = new RequestTotalTimeDTO(this.boatClassID, this.allPoints, turnPointsAsPositionDTO, USE_REAL_AVERAGE_WIND,
|
||||
@@ -368,12 +399,12 @@ public class PathPolyline {
|
||||
|
||||
final long totalTime = receiveData.totalTimeSeconds;
|
||||
|
||||
System.err.println("==================================================");
|
||||
System.err.println("total time (old way) = " + totalTime + " seconds!");
|
||||
System.err.println("==================================================");
|
||||
// System.err.println("==================================================");
|
||||
// System.err.println("total time (old way) = " + totalTime + " seconds!");
|
||||
// System.err.println("==================================================");
|
||||
|
||||
// simulatorMap.addLegendOverlayForPathPolyline(totalTime * 1000);
|
||||
// simulatorMap.redrawLegendCanvasOverlay();
|
||||
simulatorMap.addLegendOverlayForPathPolyline(totalTime * 1000);
|
||||
simulatorMap.redrawLegendCanvasOverlay();
|
||||
}
|
||||
});
|
||||
}
|
||||
@@ -382,7 +413,7 @@ public class PathPolyline {
|
||||
final List<PositionDTO> turnPointsAsPositionDTO = new ArrayList<PositionDTO>();
|
||||
|
||||
for (final LatLng point : this.turnPoints) {
|
||||
turnPointsAsPositionDTO.add(convertToPositionDTO(point));
|
||||
turnPointsAsPositionDTO.add(toPositionDTO(point));
|
||||
}
|
||||
|
||||
final RequestTotalTimeDTO requestData = new RequestTotalTimeDTO(this.boatClassID, this.allPoints, turnPointsAsPositionDTO, USE_REAL_AVERAGE_WIND,
|
||||
@@ -405,9 +436,9 @@ public class PathPolyline {
|
||||
|
||||
final long totalTime = receiveData.totalTimeSeconds;
|
||||
|
||||
System.err.println("==================================================");
|
||||
System.err.println("total time (new way) = " + totalTime + " seconds!");
|
||||
System.err.println("==================================================");
|
||||
// System.err.println("==================================================");
|
||||
// System.err.println("total time (new way) = " + totalTime + " seconds!");
|
||||
// System.err.println("==================================================");
|
||||
|
||||
simulatorMap.addLegendOverlayForPathPolyline(totalTime * 1000);
|
||||
simulatorMap.redrawLegendCanvasOverlay();
|
||||
|
||||
Reference in new issue
Block a user