Package rinde.sim.core.graph

Examples of rinde.sim.core.graph.Point


  }

  @Override
  public void initRoadUser(RoadModel model) {
    rs = model;
    final Point pos = rs.getRandomPosition(rnd);
    rs.addObjectAt(this, pos);
  }
View Full Code Here


    final Set<RandomWalkAgent> objects = rs
        .getObjectsOfType(RandomWalkAgent.class);

    synchronized (objects) {
      for (final RandomWalkAgent a : objects) {
        Point p = a.getPosition();
        if (p == null) {
          continue;
        }
        final int x = (int) (vp.origin.x + (p.x - vp.rect.min.x) * vp.scale);
        final int y = (int) (vp.origin.y + (p.y - vp.rect.min.y) * vp.scale);
 
View Full Code Here

  public void renderDynamic(GC gc, ViewPort vp, long time) {
    final List<Truck> trucks = gradientModel.getTruckEmitters();

    synchronized (trucks) {
      for (final Truck t : trucks) {
        final Point tp = t.getPosition();
        final Map<Point, Float> fields = t.getFields();

        float max = Float.NEGATIVE_INFINITY;
        float min = Float.POSITIVE_INFINITY;
View Full Code Here

      rm.moveTo(this, dto.startPosition, time);
      return;
    }

    // If none of the above, let the gradient field guide us!
    @Nullable
    final Point p = gradientModel.getTargetFor(this);
    if (p != null) {
      rm.moveTo(this, p, time);
    }
  }
View Full Code Here

        NonSI.KILOMETERS_PER_HOUR));
  }

  @Override
  public Point getRandomPosition(RandomGenerator rnd) {
    return new Point(min.x + (rnd.nextDouble() * width), min.y
        + (rnd.nextDouble() * height));
  }
View Full Code Here

  @Override
  protected MoveProgress doFollowPath(MovingRoadUser object, Queue<Point> path,
      TimeLapse time) {
    final long startTimeConsumed = time.getTimeConsumed();
    Point loc = objLocs.get(object);

    final UnitConverter toInternalTimeConv = time.getTimeUnit().getConverterTo(
        INTERNAL_TIME_UNIT);
    final UnitConverter toExternalTimeConv = INTERNAL_TIME_UNIT
        .getConverterTo(time.getTimeUnit());

    double traveled = 0;
    final double speed = min(toInternalSpeedConv.convert(object.getSpeed()),
        maxSpeed);
    if (speed == 0d) {
      // FIXME add test for this case, also check GraphRoadModel
      final Measure<Double, Length> dist = Measure.valueOf(0d,
          externalDistanceUnit);
      final Measure<Long, Duration> dur = Measure.valueOf(0L,
          time.getTimeUnit());
      return new MoveProgress(dist, dur, new ArrayList<Point>());
    }

    final List<Point> travelledNodes = new ArrayList<Point>();
    while (time.hasTimeLeft() && path.size() > 0) {
      checkArgument(isPointInBoundary(path.peek()),
          "points in the path must be within the predefined boundary of the plane");

      // distance in internal time unit that can be traveled with timeleft
      final double travelDistance = speed
          * toInternalTimeConv.convert(time.getTimeLeft());
      final double stepLength = toInternalDistConv.convert(Point.distance(loc,
          path.peek()));

      if (travelDistance >= stepLength) {
        loc = path.remove();
        travelledNodes.add(loc);

        final long timeSpent = DoubleMath.roundToLong(
            toExternalTimeConv.convert(stepLength / speed),
            RoundingMode.HALF_DOWN);
        time.consume(timeSpent);
        traveled += stepLength;
      } else {
        final Point diff = Point.diff(path.peek(), loc);

        if (stepLength - travelDistance < DELTA) { // 0.00000001) {
          loc = path.peek();
          traveled += stepLength;
        } else {
          final double perc = travelDistance / stepLength;
          loc = new Point(loc.x + perc * diff.x, loc.y + perc * diff.y);
          traveled += travelDistance;
        }
        time.consumeAll();

      }
View Full Code Here

      TimeLapse time) {
    checkArgument(objLocs.containsKey(object), "object must have a location");
    checkArgument(path.peek() != null, "path can not be empty");
    checkArgument(time.hasTimeLeft(),
        "can not follow path when to time is left");
    final Point dest = newArrayList(path).get(path.size() - 1);
    objDestinations.put(object, new DestinationPath(dest, path));
    final MoveProgress mp = doFollowPath(object, path, time);
    eventDispatcher.dispatchEvent(new MoveEvent(self, object, mp));
    return mp;
  }
View Full Code Here

        INTERNAL_TIME_UNIT);
    final UnitConverter toExternalTimeConv = INTERNAL_TIME_UNIT
        .getConverterTo(time.getTimeUnit());

    Loc tempLoc = objLoc;
    Point tempPos = objLoc;

    double newDis = Double.NaN;

    final List<Point> travelledNodes = new ArrayList<Point>();
    while (time.hasTimeLeft() && path.size() > 0) {
      checkIsValidMove(tempLoc, path.peek());

      // speed in internal speed unit
      final double speed = getMaxSpeed(object, tempPos, path.peek());

      // distance that can be traveled in current edge with timeleft
      final double travelDistance = speed
          * toInternalTimeConv.convert(time.getTimeLeft());
      final double connLength = toInternalDistConv
          .convert(computeConnectionLength(tempPos, path.peek()));

      if (travelDistance >= connLength) {
        // jump to next vertex
        tempPos = path.remove();
        if (!(tempPos instanceof Loc)) {
          travelledNodes.add(tempPos);
        }
        final long timeSpent = DoubleMath.roundToLong(
            toExternalTimeConv.convert(connLength / speed),
            RoundingMode.HALF_DOWN);
        time.consume(timeSpent);
        traveled += connLength;

        if (tempPos instanceof Loc) {
          tempLoc = checkLocation((Loc) tempPos);
        } else {
          tempLoc = checkLocation(newLoc(tempPos));
        }

      } else { // distanceLeft < connLength
        newDis = travelDistance;
        time.consumeAll();
        traveled += travelDistance;

        final Point from = isOnConnection(tempLoc) ? tempLoc.conn.from
            : tempLoc;
        final Point peekTo = isOnConnection(path.peek()) ? ((Loc) path.peek()).conn.to
            : path.peek();
        final Connection<?> conn = graph.getConnection(from, peekTo);
        tempLoc = checkLocation(newLoc(conn, tempLoc.relativePos
            + toExternalDistConv.convert(newDis)));
      }
View Full Code Here

  }

  @Override
  public List<Point> getShortestPathTo(Point from, Point to) {
    final List<Point> path = new ArrayList<Point>();
    Point start = from;
    if (isOnConnection(from)) {
      start = ((Loc) from).conn.to;
      path.add(from);
    }

    Point end = to;
    if (isOnConnection(to)) {
      end = ((Loc) to).conn.from;
    }
    path.addAll(doGetShortestPathTo(start, end));
    if (isOnConnection(to)) {
View Full Code Here

   *          {@link Connection}.
   * @return A new {@link Loc}
   */
  protected static Loc newLoc(Connection<? extends ConnectionData> conn,
      double relativePos) {
    final Point diff = Point.diff(conn.to, conn.from);
    final double roadLength = getConnectionLength(conn);

    final double perc = relativePos / roadLength;
    if (perc + DELTA >= 1) {
      return new Loc(conn.to.x, conn.to.y, null, -1, 0);
View Full Code Here

TOP

Related Classes of rinde.sim.core.graph.Point

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.