double height = abs(southWest.getLatitude() - northEast.getLatitude()) * threshold;
northEast.setLongitude(northEast.getLongitude() + width);
northEast.setLatitude(northEast.getLatitude() + height);
southWest.setLongitude(southWest.getLongitude() - width);
southWest.setLatitude(southWest.getLatitude() - height);
BoundingBox boundingBox = new BoundingBox(northEast, southWest);
List<NavigationPosition> result = new ArrayList<NavigationPosition>();
if (includeFirstAndLastPosition)
result.add(positions.get(0));
int firstIndex = includeFirstAndLastPosition ? 1 : 0;
int lastIndex = includeFirstAndLastPosition ? positions.size() - 1 : positions.size();
NavigationPosition previousPosition = positions.get(firstIndex);
boolean previousPositionVisible = boundingBox.contains(previousPosition);
for (int i = firstIndex; i < lastIndex; i += 1) {
NavigationPosition position = positions.get(i);
boolean visible = boundingBox.contains(position);
if (visible) {
// if the previous position was not visible but the current position is visible:
// add the previous position to render transition from non-visible to visible area
if (!previousPositionVisible && previousPosition != null)
result.add(previousPosition);