X-Git-Url: https://gitweb.fperrin.net/?p=GpsPrune.git;a=blobdiff_plain;f=src%2Ftim%2Fprune%2Ffunction%2Fcompress%2FMarkPointsInRectangleFunction.java;fp=src%2Ftim%2Fprune%2Ffunction%2Fcompress%2FMarkPointsInRectangleFunction.java;h=2ea0f8ca64c495486cec33d3a94d82598f5f2b5d;hp=0000000000000000000000000000000000000000;hb=ce6f2161b8596f7018d6a76bff79bc9e571f35fd;hpb=2d8cb72e84d5cc1089ce77baf1e34ea3ea2f8465 diff --git a/src/tim/prune/function/compress/MarkPointsInRectangleFunction.java b/src/tim/prune/function/compress/MarkPointsInRectangleFunction.java new file mode 100644 index 0000000..2ea0f8c --- /dev/null +++ b/src/tim/prune/function/compress/MarkPointsInRectangleFunction.java @@ -0,0 +1,98 @@ +package tim.prune.function.compress; + +import tim.prune.App; +import tim.prune.UpdateMessageBroker; +import tim.prune.data.DataPoint; + +/** + * Function to mark all the points in the selected rectangle + */ +public class MarkPointsInRectangleFunction extends MarkAndDeleteFunction +{ + /** Minimum and maximum latitude values of rectangle */ + private double _minLat = 0.0, _maxLat = 0.0; + /** Minimum and maximum longitude values of rectangle */ + private double _minLon = 0.0, _maxLon = 0.0; + + + /** + * Constructor + * @param inApp App object + */ + public MarkPointsInRectangleFunction(App inApp) + { + super(inApp); + } + + /** @return name key */ + public String getNameKey() { + return "menu.track.markrectangle"; + } + + /** + * Set the coordinates of the rectangle + * @param inLon1 first longitude value + * @param inLat1 first latitude value + * @param inLon2 second longitude value + * @param inLat2 second latitude value + */ + public void setRectCoords(double inLon1, double inLat1, double inLon2, double inLat2) + { + if (inLon1 == inLon2 || inLat1 == inLat2) + { + // Coordinates not valid + _minLat = _maxLat = _minLon = _maxLon = 0.0; + } + else + { + if (inLon2 > inLon1) { + _minLon = inLon1; _maxLon = inLon2; + } + else { + _minLon = inLon2; _maxLon = inLon1; + } + if (inLat2 > inLat1) { + _minLat = inLat1; _maxLat = inLat2; + } + else { + _minLat = inLat2; _maxLat = inLat1; + } + } + } + + /** + * Begin the function using the set parameters + */ + public void begin() + { + if (_maxLon == _minLon || _maxLat == _minLat) { + return; + } + + // Loop over all points in track + final int numPoints = _app.getTrackInfo().getTrack().getNumPoints(); + int numMarked = 0; + for (int i=0; i= _minLon && pointLon <= _maxLon + && pointLat >= _minLat && pointLat <= _maxLat); + // Mark it accordingly (also resetting points outside the rect to false) + point.setMarkedForDeletion(insideRect); + if (insideRect) { + numMarked++; + } + } + + // Inform subscribers to update display + UpdateMessageBroker.informSubscribers(); + // Confirm message showing how many marked + if (numMarked > 0) + { + optionallyDeleteMarkedPoints(numMarked); + } + } +}