Merge branch 'story_25'

main
cbt24 9 years ago
commit 71535be143

@ -259,6 +259,12 @@ public class BoatInRace extends Boat {
this.position.set(position);
}
/**
* 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();
@ -269,14 +275,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;
}

@ -339,12 +339,17 @@ public class ResizableRaceCanvas extends Canvas {
if (raceAnno)
displayText(boat.toString(), 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;
}

Loading…
Cancel
Save