1 package tim.prune.function.compress;
4 import tim.prune.UpdateMessageBroker;
5 import tim.prune.data.DataPoint;
8 * Function to mark all the points in the selected rectangle
10 public class MarkPointsInRectangleFunction extends MarkAndDeleteFunction
12 /** Minimum and maximum latitude values of rectangle */
13 private double _minLat = 0.0, _maxLat = 0.0;
14 /** Minimum and maximum longitude values of rectangle */
15 private double _minLon = 0.0, _maxLon = 0.0;
20 * @param inApp App object
22 public MarkPointsInRectangleFunction(App inApp)
27 /** @return name key */
28 public String getNameKey() {
29 return "menu.track.markrectangle";
33 * Set the coordinates of the rectangle
34 * @param inLon1 first longitude value
35 * @param inLat1 first latitude value
36 * @param inLon2 second longitude value
37 * @param inLat2 second latitude value
39 public void setRectCoords(double inLon1, double inLat1, double inLon2, double inLat2)
41 if (inLon1 == inLon2 || inLat1 == inLat2)
43 // Coordinates not valid
44 _minLat = _maxLat = _minLon = _maxLon = 0.0;
48 if (inLon2 > inLon1) {
49 _minLon = inLon1; _maxLon = inLon2;
52 _minLon = inLon2; _maxLon = inLon1;
54 if (inLat2 > inLat1) {
55 _minLat = inLat1; _maxLat = inLat2;
58 _minLat = inLat2; _maxLat = inLat1;
64 * Begin the function using the set parameters
68 if (_maxLon == _minLon || _maxLat == _minLat) {
72 // Loop over all points in track
73 final int numPoints = _app.getTrackInfo().getTrack().getNumPoints();
75 for (int i=0; i<numPoints; i++)
77 DataPoint point = _app.getTrackInfo().getTrack().getPoint(i);
78 // For each point, see if it's within the rectangle
79 final double pointLon = point.getLongitude().getDouble();
80 final double pointLat = point.getLatitude().getDouble();
81 final boolean insideRect = (pointLon >= _minLon && pointLon <= _maxLon
82 && pointLat >= _minLat && pointLat <= _maxLat);
83 // Mark it accordingly (also resetting points outside the rect to false)
84 point.setMarkedForDeletion(insideRect);
90 // Inform subscribers to update display
91 UpdateMessageBroker.informSubscribers();
92 // Confirm message showing how many marked
95 optionallyDeleteMarkedPoints(numMarked);