Example #1
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);
 }
Example #2
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);
  }
Example #3
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);
  }
Example #4
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);
  }
Example #5
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);
  }
Example #6
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);
  }
Example #7
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);
  }
Example #8
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);
  }
Example #9
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);
 }
Example #10
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;
   }
 }
Example #11
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;
  }
Example #12
0
 P isLL(P p1, P p2, P q1, P q2) {
   double d = q2.sub(q1).det(p2.sub(p1));
   if (abs(d) < EPS) {
     return null;
   }
   return p1.add(p2.sub(p1).mul(q2.sub(q1).det(q1.sub(p1)) / d));
 }
Example #13
0
  public long getTime() {
    CompactCalendar minimum = null, maximum = null;
    long totalTimeMilliSeconds = 0;
    List<P> positions = getPositions();
    P previous = null;
    for (P next : positions) {
      if (previous != null) {
        Long time = previous.calculateTime(next);
        if (time != null && time > 0) totalTimeMilliSeconds += time;
      }

      CompactCalendar calendar = next.getTime();
      if (calendar == null) continue;
      if (minimum == null || calendar.before(minimum)) minimum = calendar;
      if (maximum == null || calendar.after(maximum)) maximum = calendar;

      previous = next;
    }

    long maxMinusMin = minimum != null ? maximum.getTimeInMillis() - minimum.getTimeInMillis() : 0;
    return max(maxMinusMin, totalTimeMilliSeconds);
  }
Example #14
0
  public void solve() throws Exception {
    P[] ps = new P[N];
    Map<Integer, Set<Integer>> map = new HashMap<Integer, Set<Integer>>();
    for (int i = 0; i < N; i++) {
      P p = new P();
      p.x = sc.nextInt();
      p.y = sc.nextInt();
      ps[i] = p;
      if (!map.containsKey(p.x)) {
        Set<Integer> set = new HashSet<Integer>();
        map.put(p.x, set);
      }
      map.get(p.x).add(p.y);
    }
    Arrays.sort(
        ps,
        new Comparator<P>() {
          @Override
          public int compare(P p1, P p2) {
            if (p1.x != p2.x) {
              return p1.x - p2.x;
            }
            return p1.y - p2.y;
          }
        });

    List<Pair> yp = new ArrayList<Pair>();
    for (int i = 0; i < ps.length - 1; i++) {
      if (ps[i].x != ps[i + 1].x) continue;
      int lidx = i + 1;
      while (lidx + 1 < ps.length && ps[i].x == ps[lidx + 1].x) {
        lidx++;
      }
      Pair pair = new Pair();
      pair.s = ps[i].y;
      pair.l = ps[lidx].y;
      pair.base = ps[i].x;
      yp.add(pair);
      i = lidx;
    }

    Arrays.sort(
        ps,
        new Comparator<P>() {
          @Override
          public int compare(P p1, P p2) {
            if (p1.y != p2.y) {
              return p1.y - p2.y;
            }
            return p1.x - p2.x;
          }
        });
    List<Pair> xp = new ArrayList<Pair>();
    for (int i = 0; i < ps.length - 1; i++) {
      if (ps[i].y != ps[i + 1].y) continue;
      int lidx = i + 1;
      while (lidx + 1 < ps.length && ps[i].y == ps[lidx + 1].y) {
        lidx++;
      }
      Pair pair = new Pair();
      pair.s = ps[i].x;
      pair.l = ps[lidx].x;
      pair.base = ps[i].y;
      xp.add(pair);
      i = lidx;
    }

    int ans = 0;
    for (int i = 0; i < yp.size(); i++) {
      int xnow = yp.get(i).base;
      int sy = yp.get(i).s;
      int ly = yp.get(i).l;
      for (int j = 0; j < xp.size(); j++) {
        int y = xp.get(j).base;
        if (y < sy || ly < y) continue;
        if (xp.get(j).s > xnow || xp.get(j).l < xnow) continue;
        try {
          if (!map.get(xnow).contains(y)) {
            ans++;
            map.get(xnow).add(y);
          }
        } catch (Exception ex) {

        }
      }
    }
    ans += ps.length;
    out.println(ans);
  }
Example #15
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;
    }
  }