PlaneRoadModel extends AbstractRoadModel { @Override public void addObjectAt(RoadUser obj, Point pos) { checkArgument( isPointInBoundary(pos), "objects can only be added within the boundaries of the plane, %s is " + "not in the boundary.", pos); super.addObjectAt(obj, pos); } PlaneRoadModel(RoadModelBuilders.AbstractPlaneRMB<?, ?> b); @Override Point getRandomPosition(RandomGenerator rnd); @Override void addObjectAt(RoadUser obj, Point pos); @Override List<Point> getShortestPathTo(Point from, Point to); @Override RoadPath getPathTo(Point from, Point to, Unit<Duration> timeUnit,
      Measure<Double, Velocity> speed, GeomHeuristic heuristic); @Override RoadPath getPathTo(MovingRoadUser object, Point destination,
      Unit<Duration> timeUnit, Measure<Double, Velocity> speed,
      GeomHeuristic heuristic); @Override Measure<Double, Length> getDistanceOfPath(Iterable<Point> path); @Override ImmutableList<Point> getBounds(); @Override @Nonnull U get(Class<U> type); @Override RoadModelSnapshot getSnapshot(); final Point min; final Point max; final double width; final double height; final double maxSpeed; }
@Test public void followPath() { final MovingRoadUser mru = new TestRoadUser(); model.addObjectAt(mru, new Point(0, 0)); final Queue<Point> path = asPath(new Point(0, 0), new Point(5, 0), new Point( 5, 5)); final MoveProgress pp = model.followPath(mru, path, hour()); assertEquals(asPath(new Point(5, 0), new Point(5, 5)), path); assertEquals(1, pp.distance().getValue(), EPSILON); assertEquals(hour().getTickLength(), pp.time().getValue(), EPSILON); assertEquals(asList(new Point(0, 0)), pp.travelledNodes()); assertTrue( Point.distance(new Point(1, 0), model.getPosition(mru)) < EPSILON); final MoveProgress pp2 = model.followPath(mru, path, hour(5)); assertEquals(asPath(new Point(5, 5)), path); assertEquals(5, pp2.distance().getValue(), EPSILON); assertEquals(hour(5).getTickLength(), pp2.time().getValue(), EPSILON); assertEquals(asList(new Point(5, 0)), pp2.travelledNodes()); assertTrue( Point.distance(new Point(5, 1), model.getPosition(mru)) < EPSILON); final MoveProgress pp3 = model.followPath(mru, path, hour(50)); assertTrue(path.isEmpty()); assertEquals(4, pp3.distance().getValue(), EPSILON); assertEquals(hour(4).getTickLength(), pp3.time().getValue(), EPSILON); assertEquals(asList(new Point(5, 5)), pp3.travelledNodes()); assertTrue( Point.distance(new Point(5, 5), model.getPosition(mru)) < EPSILON); }
@Test(expected = IllegalArgumentException.class) public void followPathFail() { final Queue<Point> path = asPath(new Point(0, 0), new Point(5, 0), new Point( 5, 5), new Point(100, 0)); final MovingRoadUser mru = new TestRoadUser(); model.addObjectAt(mru, new Point(0, 0)); model.followPath(mru, path, hour(100)); }
@Test public void moveTo() { final MovingRoadUser agent = new SpeedyRoadUser(1); model.addObjectAt(agent, SW); assertEquals(new Point(0, 0), model.getPosition(agent)); model.moveTo(agent, NW, hour(9)); assertTrue( Point.distance(model.getPosition(agent), new Point(0, 9)) < EPSILON); model.followPath(agent, newLinkedList(asList(SW, SE)), hour(10)); assertTrue( Point.distance(model.getPosition(agent), new Point(1, 0)) < EPSILON); model.moveTo(agent, SE, hour(4)); assertTrue( Point.distance(model.getPosition(agent), new Point(5, 0)) < EPSILON); model.moveTo(agent, NW, hour(Math.sqrt(5))); assertTrue( Point.distance(model.getPosition(agent), new Point(4, 2)) < EPSILON); model.moveTo(agent, new Point(6, 2), hour(2)); assertTrue( Point.distance(model.getPosition(agent), new Point(6, 2)) < EPSILON); model.followPath(agent, newLinkedList(asList(NE)), hour(Math.sqrt(5))); assertTrue( Point.distance(model.getPosition(agent), new Point(7, 4)) < EPSILON); model.moveTo(agent, NW, hour(13)); assertTrue( Point.distance(model.getPosition(agent), new Point(0, 10)) < EPSILON); final MovingRoadUser agent2 = new SpeedyRoadUser(1); model.addObjectAt(agent2, SW); assertEquals(new Point(0, 0), model.getPosition(agent2)); model.moveTo(agent2, agent, hour(30)); assertEquals(model.getPosition(agent), model.getPosition(agent2)); }