Documented methods added for track handling.
#story[758]
This commit is contained in:
@@ -258,6 +258,12 @@ public class BoatInRace extends Boat {
|
||||
this.position.set(Integer.toString(position + 1));
|
||||
}
|
||||
|
||||
/**
|
||||
* Adds a new point to boat's track.
|
||||
* @param coordinate of point on track
|
||||
* @return whether add is successful
|
||||
* @see seng302.Model.TrackPoint
|
||||
*/
|
||||
public boolean addTrackPoint(GPSCoordinate coordinate) {
|
||||
Boolean added = System.currentTimeMillis() >= nextValidTime;
|
||||
long currentTime = System.currentTimeMillis();
|
||||
@@ -268,14 +274,27 @@ public class BoatInRace extends Boat {
|
||||
return added;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the boat's sampled track between start of race and current time.
|
||||
* @return queue of track points
|
||||
* @see seng302.Model.TrackPoint
|
||||
*/
|
||||
public Queue<TrackPoint> getTrack() {
|
||||
return track;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether track is visible
|
||||
* @return true if visible
|
||||
*/
|
||||
public boolean isTrackVisible() {
|
||||
return trackVisible;
|
||||
}
|
||||
|
||||
/**
|
||||
* Sets track visibility.
|
||||
* @param trackVisible visible if true.
|
||||
*/
|
||||
public void setTrackVisible(boolean trackVisible) {
|
||||
this.trackVisible = trackVisible;
|
||||
}
|
||||
|
||||
@@ -285,12 +285,17 @@ public class ResizableRaceCanvas extends Canvas {
|
||||
if (raceAnno)
|
||||
displayText(boat.getAbbrev(), boat.getVelocity(), this.map.convertGPS(boat.getCurrentPosition()));
|
||||
|
||||
if(boat.isTrackVisible()) drawTrackPoint(boat);
|
||||
if(boat.isTrackVisible()) drawTrack(boat);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
private void drawTrackPoint(BoatInRace boat) {
|
||||
/**
|
||||
* Draws all track points for a given boat. Colour is set by boat, opacity by track point.
|
||||
* @param boat whose track is displayed
|
||||
* @see seng302.Model.TrackPoint
|
||||
*/
|
||||
private void drawTrack(BoatInRace boat) {
|
||||
for (TrackPoint point : boat.getTrack()) {
|
||||
GraphCoordinate scaledCoordinate = this.map.convertGPS(point.getCoordinate());
|
||||
Color boatColour = boat.getColour();
|
||||
|
||||
@@ -11,6 +11,12 @@ public class TrackPoint {
|
||||
private long expiry;
|
||||
private double minAlpha;
|
||||
|
||||
/**
|
||||
* Creates a new track point with fixed GPS coordinates and time, to reach minimum opacity on expiry.
|
||||
* @param coordinate position of point on physical race map
|
||||
* @param timeAdded system clock at time of addition
|
||||
* @param expiry time to minimum opacity after added
|
||||
*/
|
||||
public TrackPoint(GPSCoordinate coordinate, long timeAdded, long expiry) {
|
||||
this.coordinate = coordinate;
|
||||
this.timeAdded = timeAdded;
|
||||
@@ -18,14 +24,26 @@ public class TrackPoint {
|
||||
this.minAlpha = 0.1;
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the position of the point on physical race map.
|
||||
* @return GPS coordinate of point
|
||||
*/
|
||||
public GPSCoordinate getCoordinate() {
|
||||
return coordinate;
|
||||
}
|
||||
|
||||
/**
|
||||
* 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
|
||||
*/
|
||||
public double getAlpha() {
|
||||
return Double.max(minAlpha,1.0 - (double)(System.currentTimeMillis() - timeAdded) / expiry);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets time point was added to track.
|
||||
* @return system clock at time of addition
|
||||
*/
|
||||
public long getTimeAdded() {
|
||||
return timeAdded;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user