Fixed bugs caused by horizontally scaling maps

This commit is contained in:
Calum
2017-04-26 17:18:33 +12:00
parent 912c081606
commit 749c6b7fef
3 changed files with 135 additions and 39 deletions
@@ -53,8 +53,8 @@ public class CanvasController {
private Mark minLonPoint; private Mark minLonPoint;
private Mark maxLatPoint; private Mark maxLatPoint;
private Mark maxLonPoint; private Mark maxLonPoint;
private int referencePointX; private double referencePointX;
private int referencePointY; private double referencePointY;
private double metersToPixels; private double metersToPixels;
public AnimationTimer timer; public AnimationTimer timer;
@@ -303,6 +303,13 @@ public class CanvasController {
drawGateMark((GateMark) mark); drawGateMark((GateMark) mark);
} }
} }
System.out.println("MIN/MAX POINTS");
System.out.println(minLatPoint.getName() + " " + minLatPoint.getX() + " " + minLatPoint.getY());
System.out.println(maxLatPoint.getName() + " " + maxLatPoint.getX() + " " + maxLatPoint.getY());
System.out.println(minLonPoint.getName() + " " + minLonPoint.getX() + " " + minLonPoint.getY());
System.out.println(maxLonPoint.getName() + " " + maxLonPoint.getX() + " " + maxLonPoint.getY());
System.out.println(referencePointX);
System.out.println(referencePointY);
} }
/** /**
@@ -312,6 +319,7 @@ public class CanvasController {
*/ */
private void drawSingleMark(SingleMark singleMark, Color color) { private void drawSingleMark(SingleMark singleMark, Color color) {
gc.setFill(color); gc.setFill(color);
System.out.println("DRAWING " + singleMark.getName() + " at " + singleMark.getX() + ", " + singleMark.getY());
gc.fillOval(singleMark.getX(), singleMark.getY(),MARK_SIZE,MARK_SIZE); gc.fillOval(singleMark.getX(), singleMark.getY(),MARK_SIZE,MARK_SIZE);
} }
@@ -388,6 +396,16 @@ public class CanvasController {
Collections.reverse(sortedPoints); Collections.reverse(sortedPoints);
minLonPoint = sortedPoints.get(0); minLonPoint = sortedPoints.get(0);
maxLonPoint = sortedPoints.get(sortedPoints.size()-1); maxLonPoint = sortedPoints.get(sortedPoints.size()-1);
System.out.println("ALL POINTS");
for (Mark m : sortedPoints)
{
System.out.println(m.getName() + " " + m.getLatitude() + " " + m.getLongitude());
}
System.out.println("MIN/MAX POINTS");
System.out.println(minLatPoint.getName() + " " + minLatPoint.getLatitude() + " " + minLatPoint.getLongitude());
System.out.println(maxLatPoint.getName() + " " + maxLatPoint.getLatitude() + " " + maxLatPoint.getLongitude());
System.out.println(minLonPoint.getName() + " " + minLonPoint.getLatitude() + " " + minLonPoint.getLongitude());
System.out.println(maxLonPoint.getName() + " " + maxLonPoint.getLatitude() + " " + maxLonPoint.getLongitude());
} }
/** /**
@@ -399,33 +417,41 @@ public class CanvasController {
private void calculateReferencePointLocation (double minLonToMaxLon) { private void calculateReferencePointLocation (double minLonToMaxLon) {
Mark referencePoint = minLatPoint; Mark referencePoint = minLatPoint;
double referenceAngle; double referenceAngle;
double mapWidth = canvas.getWidth(); //double mapWidth = canvas.getWidth();
double mapHeight = canvas.getHeight(); //double mapHeight = canvas.getHeight();
if (scaleDirection == ScaleDirection.HORIZONTAL) { if (scaleDirection == ScaleDirection.HORIZONTAL) {
referenceAngle = Mark.calculateHeadingRad(referencePoint, minLonPoint) - (Math.PI * (3/4)); System.out.println("HORIZONTAL");
referencePointX = LHS_BUFFER + (int) Math.round(distanceScaleFactor * Math.cos(referenceAngle) * Mark.calculateDistance(referencePoint, minLonPoint)); System.out.println("ref angle " + Mark.calculateHeadingRad(referencePoint, minLonPoint));
//referenceAngle = Mark.calculateHeadingRad(referencePoint, minLonPoint) - (Math.PI * (3/4));
referenceAngle = Math.abs(Mark.calculateHeadingRad(referencePoint, minLonPoint));
referencePointX = LHS_BUFFER + distanceScaleFactor * Math.sin(referenceAngle) * Mark.calculateDistance(referencePoint, minLonPoint);
referenceAngle = Mark.calculateHeadingRad(referencePoint, maxLatPoint); //referenceAngle = Mark.calculateHeadingRad(referencePoint, maxLatPoint);
if (referenceAngle > (Math.PI / 2)) { //if (referenceAngle > Math.PI) {
referenceAngle = (Math.PI * 2) - referenceAngle; // referenceAngle = (Math.PI * 2) - referenceAngle;
} //}
referencePointY = (int) Math.round(mapHeight - (TOP_BUFFER + BOT_BUFFER)); referenceAngle = Math.abs(Mark.calculateHeadingRad(referencePoint, maxLatPoint));
referencePointY -= (int) Math.round(distanceScaleFactor * Math.cos(referenceAngle) * Mark.calculateDistance(referencePoint, maxLatPoint)); referencePointY = CANVAS_HEIGHT - (TOP_BUFFER + BOT_BUFFER);
referencePointY = (int) Math.round(referencePointY / 2d); referencePointY -= distanceScaleFactor * Math.cos(referenceAngle) * Mark.calculateDistance(referencePoint, maxLatPoint);
referencePointY = referencePointY / 2;
referencePointY += TOP_BUFFER; referencePointY += TOP_BUFFER;
referencePointY += (int) Math.round(distanceScaleFactor * Math.cos(referenceAngle) * Mark.calculateDistance(referencePoint, maxLatPoint)); referencePointY += distanceScaleFactor * Math.cos(referenceAngle) * Mark.calculateDistance(referencePoint, maxLatPoint);
} else { } else {
referencePointY = (int) Math.round(mapHeight - BOT_BUFFER); System.out.println("VERTICAL");
referencePointY = CANVAS_HEIGHT - BOT_BUFFER;
referenceAngle = (Math.PI * 2) - Mark.calculateHeadingRad(referencePoint, minLonPoint); //referenceAngle = (Math.PI * 2) - Mark.calculateHeadingRad(referencePoint, minLonPoint);
referenceAngle = Math.abs(Mark.calculateHeadingRad(referencePoint, minLonPoint));
referencePointX = LHS_BUFFER; referencePointX = LHS_BUFFER;
referencePointX += (int) Math.round(distanceScaleFactor * Math.sin(referenceAngle) * Mark.calculateDistance(referencePoint, minLonPoint)); referencePointX += distanceScaleFactor * Math.sin(referenceAngle) * Mark.calculateDistance(referencePoint, minLonPoint);
referencePointX += (int) Math.round(((mapWidth - (LHS_BUFFER + RHS_BUFFER)) - (minLonToMaxLon * distanceScaleFactor)) / 2); referencePointX += ((CANVAS_WIDTH - (LHS_BUFFER + RHS_BUFFER)) - (minLonToMaxLon * distanceScaleFactor)) / 2;
} }
referencePoint.setX(referencePointX); referencePointX = Math.round(referencePointX);
referencePoint.setY(referencePointY); referencePointY = Math.round(referencePointY);
referencePoint.setX((int) referencePointX);
referencePoint.setY((int) referencePointY);
} }
/** /**
@@ -433,9 +459,10 @@ public class CanvasController {
* Returns the max horizontal distance of the map. * Returns the max horizontal distance of the map.
*/ */
private double scaleRaceExtremities () { private double scaleRaceExtremities () {
double vertAngle = Mark.calculateHeadingRad(minLatPoint, maxLatPoint); //double vertAngle = Mark.calculateHeadingRad(minLatPoint, maxLatPoint);
if (vertAngle > Math.PI) double vertAngle = Math.abs(Mark.calculateHeadingRad(minLatPoint, maxLatPoint));
vertAngle = (2 * Math.PI) - vertAngle; // if (vertAngle > Math.PI)
// vertAngle = (2 * Math.PI) - vertAngle;
double vertDistance = Math.cos(vertAngle) * Mark.calculateDistance(minLatPoint, maxLatPoint); double vertDistance = Math.cos(vertAngle) * Mark.calculateDistance(minLatPoint, maxLatPoint);
double horiAngle = Mark.calculateHeadingRad(minLonPoint, maxLonPoint); double horiAngle = Mark.calculateHeadingRad(minLonPoint, maxLonPoint);
@@ -445,10 +472,10 @@ public class CanvasController {
horiAngle = horiAngle - (Math.PI / 2); horiAngle = horiAngle - (Math.PI / 2);
double horiDistance = Math.cos(horiAngle) * Mark.calculateDistance(minLonPoint, maxLonPoint); double horiDistance = Math.cos(horiAngle) * Mark.calculateDistance(minLonPoint, maxLonPoint);
double vertScale = (canvas.getHeight() - (TOP_BUFFER + BOT_BUFFER)) / vertDistance; double vertScale = (CANVAS_HEIGHT - (TOP_BUFFER + BOT_BUFFER)) / vertDistance;
if ((horiDistance * vertScale) > (canvas.getWidth() - (RHS_BUFFER + LHS_BUFFER))) { if ((horiDistance * vertScale) > (CANVAS_WIDTH - (RHS_BUFFER + LHS_BUFFER))) {
distanceScaleFactor = (canvas.getWidth() - (RHS_BUFFER + LHS_BUFFER)) / horiDistance; distanceScaleFactor = (CANVAS_WIDTH - (RHS_BUFFER + LHS_BUFFER)) / horiDistance;
scaleDirection = ScaleDirection.HORIZONTAL; scaleDirection = ScaleDirection.HORIZONTAL;
} else { } else {
distanceScaleFactor = vertScale; distanceScaleFactor = vertScale;
@@ -495,21 +522,18 @@ public class CanvasController {
private Point2D findScaledXY (double latA, double lonA, double latB, double lonB) { private Point2D findScaledXY (double latA, double lonA, double latB, double lonB) {
double distanceFromReference; double distanceFromReference;
double angleFromReference; double angleFromReference;
int yAxisLocation; int xAxisLocation = (int) referencePointX;
int xAxisLocation; int yAxisLocation = (int) referencePointY;
angleFromReference = Mark.calculateHeadingRad(latA, lonA, latB, lonB); angleFromReference = Mark.calculateHeadingRad(latA, lonA, latB, lonB);
distanceFromReference = Mark.calculateDistance(latA, lonA, latB, lonB); distanceFromReference = Mark.calculateDistance(latA, lonA, latB, lonB);
if (angleFromReference > (Math.PI / 2)) { if (angleFromReference > (Math.PI / 2)) {
angleFromReference = (Math.PI * 2) - angleFromReference; angleFromReference = (Math.PI * 2) - angleFromReference;
xAxisLocation = referencePointX;
xAxisLocation -= (int) Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference); xAxisLocation -= (int) Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
} else { } else {
xAxisLocation = referencePointX;
xAxisLocation += (int) Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference); xAxisLocation += (int) Math.round(distanceScaleFactor * Math.sin(angleFromReference) * distanceFromReference);
} }
yAxisLocation = referencePointY;
yAxisLocation -= (int) Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference); yAxisLocation -= (int) Math.round(distanceScaleFactor * Math.cos(angleFromReference) * distanceFromReference);
return new Point2D(xAxisLocation, yAxisLocation); return new Point2D(xAxisLocation, yAxisLocation);
+8 -8
View File
@@ -11,8 +11,8 @@
</mark> </mark>
<mark> <mark>
<name>Start2</name> <name>Start2</name>
<latitude>57.6703330</latitude> <latitude>57.6706330</latitude>
<longitude>11.8278330</longitude> <longitude>11.8281330</longitude>
</mark> </mark>
</gate> </gate>
<mark> <mark>
@@ -29,8 +29,8 @@
</mark> </mark>
<mark> <mark>
<name>Leeward Gate2</name> <name>Leeward Gate2</name>
<latitude>57.6708220</latitude> <latitude>57.6711220</latitude>
<longitude>11.8433900</longitude> <longitude>11.8436900</longitude>
</mark> </mark>
</gate> </gate>
<gate> <gate>
@@ -42,8 +42,8 @@
</mark> </mark>
<mark> <mark>
<name>Windward Gate2</name> <name>Windward Gate2</name>
<latitude>57.6650170</latitude> <latitude>57.6653170</latitude>
<longitude>11.8279170</longitude> <longitude>11.8282170</longitude>
</mark> </mark>
</gate> </gate>
<gate type="finish-line"> <gate type="finish-line">
@@ -55,8 +55,8 @@
</mark> </mark>
<mark> <mark>
<name>Finish2</name> <name>Finish2</name>
<latitude>57.6715240</latitude> <latitude>57.6718240</latitude>
<longitude>11.8444950</longitude> <longitude>11.8447950</longitude>
</mark> </mark>
</gate> </gate>
</marks> </marks>
+72
View File
@@ -0,0 +1,72 @@
<?xml version="1.0" ?>
<course>
<marks>
<gate>
<name type="start-line">Start</name>
<mark>
<name>Start1</name>
<latitude>32.296577</latitude>
<longitude>-64.854304</longitude>
</mark>
<mark>
<name>Start2</name>
<latitude>32.293771</latitude>
<longitude>-64.855242</longitude>
</mark>
</gate>
<mark>
<name>Mid Mark</name>
<latitude>32.293039</latitude>
<longitude>-64.843983</longitude>
</mark>
<gate>
<name>Leeward Gate</name>
<mark>
<name>Leeward Gate1</name>
<latitude>32.284680</latitude>
<longitude>-64.850045</longitude>
</mark>
<mark>
<name>Leeward Gate2</name>
<latitude>32.280164</latitude>
<longitude>-64.847591</longitude>
</mark>
</gate>
<gate>
<name>Windward Gate</name>
<mark>
<name>Windward Gate1</name>
<latitude>32.309693</latitude>
<longitude>-64.835249</longitude>
</mark>
<mark>
<name>Windward Gate2</name>
<latitude>32.308046</latitude>
<longitude>-64.831785</longitude>
</mark>
</gate>
<gate type="finish-line">
<name>Finish</name>
<mark>
<name>Finish1</name>
<latitude>32.317379</latitude>
<longitude>-64.839291</longitude>
</mark>
<mark>
<name>Finish2</name>
<latitude>32.317257</latitude>
<longitude>-64.836260</longitude>
</mark>
</gate>
</marks>
<order>
<one>Start</one>
<two>Mid Mark</two>
<three>Leeward Gate</three>
<four>Windward Gate</four>
<five>Leeward Gate</five>
<six>Finish</six>
</order>
</course>