Esempio n. 1
0
  public void ensureIncreasingTime() {
    if (getPositionCount() < 2) return;

    long completeTime = getTime(); // ms
    double completeDistance = getDistance(); // m
    double averageSpeed = completeTime > 0 ? completeDistance / completeTime * 1000 : 1.0; // m/s

    List<P> positions = getPositions();
    P first = positions.get(0);
    if (!first.hasTime()) first.setTime(fromCalendar(Calendar.getInstance(UTC)));

    P previous = first;
    for (int i = 1; i < positions.size(); i++) {
      P next = positions.get(i);
      CompactCalendar time = next.getTime();
      if (time == null || time.equals(previous.getTime())) {
        Double distance = next.calculateDistance(previous);
        Long millis = distance != null ? (long) (distance / averageSpeed * 1000) : null;
        if (millis == null || millis < 1000) millis = 1000L;
        next.setTime(
            fromMillisAndTimeZone(
                previous.getTime().getTimeInMillis() + millis, previous.getTime().getTimeZoneId()));
      }
      previous = next;
    }
  }
Esempio n. 2
0
 private void move(int index, int upOrDown) {
   List<P> positions = getPositions();
   P move = positions.get(index);
   P replace = positions.get(index + upOrDown);
   positions.set(index + upOrDown, move);
   positions.set(index, replace);
 }
Esempio n. 3
0
 public void sort(Comparator<P> comparator) {
   List<P> positions = getPositions();
   @SuppressWarnings({"SuspiciousToArrayCall", "unchecked"})
   P[] sorted = (P[]) positions.toArray(new BaseNavigationPosition[positions.size()]);
   Arrays.sort(sorted, comparator);
   //noinspection unchecked
   order(asList(sorted));
 }
Esempio n. 4
0
 public int[] getContainedPositions(BoundingBox boundingBox) {
   List<Integer> result = new ArrayList<>();
   List<P> positions = getPositions();
   for (int i = 0; i < positions.size(); i++) {
     P position = positions.get(i);
     if (position.hasCoordinates() && boundingBox.contains(position)) result.add(i);
   }
   return toArray(result);
 }
Esempio n. 5
0
  @SuppressWarnings("UnusedDeclaration")
  public ViaMichelinRoute asViaMichelinFormat() {
    if (getFormat() instanceof ViaMichelinFormat) return (ViaMichelinRoute) this;

    List<Wgs84Position> wgs84Positions = new ArrayList<>();
    for (P position : getPositions()) {
      wgs84Positions.add(position.asWgs84Position());
    }
    return new ViaMichelinRoute(getName(), wgs84Positions);
  }
Esempio n. 6
0
  @SuppressWarnings("UnusedDeclaration")
  public GarminFlightPlanRoute asGarminFlightPlanFormat() {
    if (getFormat() instanceof GarminFlightPlanFormat) return (GarminFlightPlanRoute) this;

    List<GarminFlightPlanPosition> flightPlanPositions = new ArrayList<>();
    for (P position : getPositions()) {
      flightPlanPositions.add(position.asGarminFlightPlanPosition());
    }
    return new GarminFlightPlanRoute(getName(), getDescription(), flightPlanPositions);
  }
Esempio n. 7
0
  @SuppressWarnings("UnusedDeclaration")
  public MagicMapsIktRoute asMagicMapsIktFormat() {
    if (getFormat() instanceof MagicMapsIktFormat) return (MagicMapsIktRoute) this;

    List<Wgs84Position> wgs84Positions = new ArrayList<>();
    for (P position : getPositions()) {
      wgs84Positions.add(position.asWgs84Position());
    }
    return new MagicMapsIktRoute(getName(), getDescription(), wgs84Positions);
  }
Esempio n. 8
0
 public double getElevationDelta(int index) {
   List<P> positions = getPositions();
   NavigationPosition previous = index > 0 ? positions.get(index - 1) : null;
   NavigationPosition current = index < positions.size() ? positions.get(index) : null;
   if (previous != null && current != null) {
     Double elevation = previous.calculateElevation(current);
     if (elevation != null) return elevation;
   }
   return 0;
 }
Esempio n. 9
0
  @SuppressWarnings("UnusedDeclaration")
  public OvlRoute asOvlFormat() {
    if (getFormat() instanceof OvlFormat) return (OvlRoute) this;

    List<Wgs84Position> ovlPositions = new ArrayList<>();
    for (P position : getPositions()) {
      ovlPositions.add(position.asOvlPosition());
    }
    return new OvlRoute(getCharacteristics(), getName(), ovlPositions);
  }
Esempio n. 10
0
  @SuppressWarnings("UnusedDeclaration")
  public TourRoute asTourFormat() {
    if (getFormat() instanceof TourFormat) return (TourRoute) this;

    List<TourPosition> tourPositions = new ArrayList<>();
    for (P position : getPositions()) {
      tourPositions.add(position.asTourPosition());
    }
    return new TourRoute(getName(), tourPositions);
  }
Esempio n. 11
0
  @SuppressWarnings("UnusedDeclaration")
  public MagicMapsPthRoute asMagicMapsPthFormat() {
    if (getFormat() instanceof MagicMapsPthFormat) return (MagicMapsPthRoute) this;

    List<GkPosition> gkPositions = new ArrayList<>();
    for (P position : getPositions()) {
      gkPositions.add(position.asGkPosition());
    }
    return new MagicMapsPthRoute(getCharacteristics(), gkPositions);
  }
Esempio n. 12
0
  @SuppressWarnings("UnusedDeclaration")
  public NokiaLandmarkExchangeRoute asNokiaLandmarkExchangeFormat() {
    if (getFormat() instanceof NokiaLandmarkExchangeFormat)
      return (NokiaLandmarkExchangeRoute) this;

    List<Wgs84Position> wgs84Positions = new ArrayList<>();
    for (P position : getPositions()) {
      wgs84Positions.add(position.asWgs84Position());
    }
    return new NokiaLandmarkExchangeRoute(getName(), getDescription(), wgs84Positions);
  }
Esempio n. 13
0
 /**
  * Removes duplicate adjacent {@link #getPositions() positions} from this route, leaving only
  * distinct neighbours
  */
 public void removeDuplicates() {
   List<P> positions = getPositions();
   P previous = null;
   int index = 0;
   while (index < positions.size()) {
     P next = positions.get(index);
     if (previous != null && (!next.hasCoordinates() || next.calculateDistance(previous) <= 0.0)) {
       positions.remove(index);
     } else index++;
     previous = next;
   }
 }
Esempio n. 14
0
 public double getDistance(int startIndex, int endIndex) {
   double result = 0;
   List<P> positions = getPositions();
   NavigationPosition previous = null;
   for (int i = startIndex; i <= endIndex; i++) {
     NavigationPosition next = positions.get(i);
     if (previous != null) {
       Double distance = previous.calculateDistance(next);
       if (distance != null) result += distance;
     }
     previous = next;
   }
   return result;
 }
Esempio n. 15
0
 public double getElevationDescend(int startIndex, int endIndex) {
   double result = 0;
   List<P> positions = getPositions();
   NavigationPosition previous = null;
   for (int i = startIndex; i <= endIndex; i++) {
     NavigationPosition next = positions.get(i);
     if (previous != null) {
       Double elevation = previous.calculateElevation(next);
       if (elevation != null && elevation < 0) result += abs(elevation);
     }
     previous = next;
   }
   return result;
 }
Esempio n. 16
0
  public void revert() {
    List<P> positions = getPositions();
    List<P> reverted = new ArrayList<>();
    for (P position : positions) {
      reverted.add(0, position);
    }
    order(reverted);

    String routeName = getName();
    if (!routeName.endsWith(REVERSE_ROUTE_NAME_POSTFIX))
      routeName = routeName + REVERSE_ROUTE_NAME_POSTFIX;
    else
      routeName = routeName.substring(0, routeName.length() - REVERSE_ROUTE_NAME_POSTFIX.length());
    setName(routeName);
  }
Esempio n. 17
0
  public int getClosestPosition(double longitude, double latitude, double threshold) {
    int closestIndex = -1;
    double closestDistance = MAX_VALUE;

    List<P> positions = getPositions();
    for (int i = 0; i < positions.size(); ++i) {
      P point = positions.get(i);
      Double distance = point.calculateDistance(longitude, latitude);
      if (distance != null && distance < closestDistance && distance < threshold) {
        closestDistance = distance;
        closestIndex = i;
      }
    }
    return closestIndex;
  }
Esempio n. 18
0
 public double[] getDistancesFromStart(int startIndex, int endIndex) {
   double[] result = new double[endIndex - startIndex + 1];
   List<P> positions = getPositions();
   int index = 0;
   double distance = 0.0;
   NavigationPosition previous = positions.size() > 0 ? positions.get(0) : null;
   while (index <= endIndex) {
     NavigationPosition next = positions.get(index);
     if (previous != null) {
       Double delta = previous.calculateDistance(next);
       if (delta != null) distance += delta;
       if (index >= startIndex) result[index - startIndex] = distance;
     }
     index++;
     previous = next;
   }
   return result;
 }
Esempio n. 19
0
 public int[] getPositionsWithinDistanceToPredecessor(double distance) {
   List<Integer> result = new ArrayList<>();
   List<P> positions = getPositions();
   if (positions.size() <= 2) return new int[0];
   P previous = positions.get(0);
   for (int i = 1; i < positions.size() - 1; i++) {
     P next = positions.get(i);
     if (!next.hasCoordinates() || next.calculateDistance(previous) <= distance) result.add(i);
     else previous = next;
   }
   return toArray(result);
 }
Esempio n. 20
0
  public double[] getDistancesFromStart(int[] indices) {
    double[] result = new double[indices.length];
    if (indices.length > 0 && getPositionCount() > 0) {
      Arrays.sort(indices);
      int endIndex = min(indices[indices.length - 1], getPositionCount() - 1);

      int index = 0;
      double distance = 0.0;
      List<P> positions = getPositions();
      NavigationPosition previous = positions.get(0);
      while (index <= endIndex) {
        NavigationPosition next = positions.get(index);
        if (previous != null) {
          Double delta = previous.calculateDistance(next);
          if (delta != null) distance += delta;
          int indexInIndices = binarySearch(indices, index);
          if (indexInIndices >= 0) result[indexInIndices] = distance;
        }
        index++;
        previous = next;
      }
    }
    return result;
  }
Esempio n. 21
0
 public void order(List<P> positions) {
   List<P> existing = getPositions();
   for (int i = 0; i < positions.size(); i++) {
     existing.set(i, positions.get(i));
   }
 }
Esempio n. 22
0
 public P getSuccessor(P position) {
   List<P> positions = getPositions();
   int index = positions.indexOf(position);
   return index != -1 && index < positions.size() - 1 ? positions.get(index + 1) : null;
 }
Esempio n. 23
0
 public P remove(int index) {
   List<P> positions = getPositions();
   return positions.remove(index);
 }