I had accidentally broken the raceXML construction - fixed it.
Fixed a few issues where boat didn't have nextMark/previousMark times under certain circumstances. LatestMessages wasn't actually notifying properly - fixed. The various XML readers now treat a string constructor as containing file contents, not file name - this was how it was mostly already used. Fixed some issues in RaceXMLReader, including where element.getChildNodes() was used instead of element.getElementsByName(...). Boat: changes speed to a doubleProperty. Changed leg to a Property<Leg>. Race.lastFps is now an IntegerProperty. Added breaks to the case statements in VisualiserInput. Whoops. ResizableRaceCanvas now handles drawing the race boundary. Tidied up code a bit. Removed ResizableRaceMap. Started refactoring Sparkline. Currently doesn't work.
This commit is contained in:
@@ -7,17 +7,39 @@ import shared.model.GPSCoordinate;
|
||||
* A TrackPoint is a point plotted to display the track a
|
||||
* {@link VisualiserBoat Boat} has travelled in a race. <br>
|
||||
* TrackPoints are displayed on a
|
||||
* {@link seng302.Model.ResizableRaceCanvas ResizableRaceCanvas}, via the
|
||||
* {@link seng302.Controllers.RaceController RaceController}. <br>
|
||||
* {@link ResizableRaceCanvas}, via the
|
||||
* {@link visualiser.Controllers.RaceController}. <br>
|
||||
* Track points can be made visible or hidden via the RaceController's
|
||||
* {@link seng302.Model.Annotations Annotations}.
|
||||
* {@link Annotations}.
|
||||
*/
|
||||
public class TrackPoint {
|
||||
|
||||
/**
|
||||
* The {@link GPSCoordinate} this {@link TrackPoint} corresponds to.
|
||||
*/
|
||||
private final GPSCoordinate coordinate;
|
||||
|
||||
/**
|
||||
* The time the track point was created at, in milliseconds since unix epoch.
|
||||
*/
|
||||
private final long timeAdded;
|
||||
|
||||
/**
|
||||
* The period of time, in milliseconds, over which the track point's alpha should diminish to a floor value of {@link #minAlpha}.
|
||||
*/
|
||||
private final long expiry;
|
||||
|
||||
/**
|
||||
* The minimum alpha to draw the track point with.
|
||||
*/
|
||||
private final double minAlpha;
|
||||
|
||||
/**
|
||||
* The diameter to draw the track point with.
|
||||
*/
|
||||
private final double diameter;
|
||||
|
||||
|
||||
/**
|
||||
* Creates a new track point with fixed GPS coordinates and time, to reach minimum opacity on expiry.
|
||||
*
|
||||
@@ -29,9 +51,12 @@ public class TrackPoint {
|
||||
this.coordinate = coordinate;
|
||||
this.timeAdded = timeAdded;
|
||||
this.expiry = expiry;
|
||||
|
||||
this.minAlpha = 0.1;
|
||||
this.diameter = 5d;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Gets the position of the point on physical race map.
|
||||
*
|
||||
@@ -44,10 +69,23 @@ public class TrackPoint {
|
||||
/**
|
||||
* Gets opacity of point scaled by age in proportion to expiry, between 1 and minimum opacity inclusive.
|
||||
*
|
||||
* @return greater of minimum opacity and scaled opacity
|
||||
* @return Greater of minimum opacity and scaled opacity.
|
||||
*/
|
||||
public double getAlpha() {
|
||||
return Double.max(minAlpha, 1.0 - (double) (System.currentTimeMillis() - timeAdded) / expiry);
|
||||
|
||||
//Calculate how much the alpha should be attenuated by elapsed time.
|
||||
|
||||
//Elapsed time.
|
||||
long elapsedTime = System.currentTimeMillis() - this.timeAdded;
|
||||
|
||||
//Proportion of expiry period that has elapsed. (E.g., 2.5 means that 5 times the period has elapsed.)
|
||||
double elapsedProportion = ((double) elapsedTime) / this.expiry;
|
||||
|
||||
//As the alpha diminishes from 1 down to a floor, we take the complement of this value. This may be negative.
|
||||
double calculatedAlpha = 1.0 - elapsedProportion;
|
||||
|
||||
//We then take the max of the minAlpha and calculatedAlpha so that it doesn't go past our floor value.
|
||||
return Double.max(this.minAlpha, calculatedAlpha);
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -58,4 +96,13 @@ public class TrackPoint {
|
||||
public long getTimeAdded() {
|
||||
return timeAdded;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Returns the diameter to draw the track point with.
|
||||
* @return The diameter to draw the track point with.
|
||||
*/
|
||||
public double getDiameter() {
|
||||
return diameter;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user