/** * Returns all {@link RoadUser}s in <code>model</code> that are * <strong>within</strong> a bird-flight distance of <code>radius</code> to * <code>position</code>. * @param position The position which is used to measure distance. * @param model The {@link RoadModel} which contains the objects. * @param radius Objects with a distance smaller than <code>radius</code> to * <code>position</code> are included. * @return A collection of {@link RoadUser}s. */ public static Collection<RoadUser> findObjectsWithinRadius( final Point position, final RoadModel model, final double radius) { return RoadModels.findObjectsWithinRadius(position, model, radius, model.getObjects()); }
/** * Returns all {@link RoadUser}s of type <code> type</code> in * <code>model</code> that are <strong>within</strong> a bird-flight distance * of <code>radius</code> to <code>position</code>. * @param position The position which is used to measure distance. * @param model The {@link RoadModel} which contains the objects. * @param radius Objects with a distance smaller than <code>radius</code> to * <code>position</code> are included. * @param type The {@link Class} of the required type. * @param <T> The type of the objects in the returned collection. * @return A collection of type <code>type</code>. */ public static <T extends RoadUser> Collection<T> findObjectsWithinRadius( final Point position, final RoadModel model, final double radius, final Class<T> type) { return RoadModels.findObjectsWithinRadius(position, model, radius, model.getObjectsOfType(type)); }
@Test public void findObjectsWithinRadiusTest() { final Point ref = new Point(10, 10); assertArrayEquals(asList(o1, o2, o3, o4, o6).toArray(), RoadModels .findObjectsWithinRadius(ref, rm, 15).toArray()); assertArrayEquals(asList(o3).toArray(), RoadModels.findObjectsWithinRadius(ref, rm, 10).toArray()); assertArrayEquals(asList(o2, o3).toArray(), RoadModels .findObjectsWithinRadius(ref, rm, 10.000000001).toArray()); assertArrayEquals(asList().toArray(), RoadModels.findObjectsWithinRadius(ref, rm, 5).toArray()); assertArrayEquals(asList(o1, o2, o3).toArray(), RoadModels .findObjectsWithinRadius(ref, rm, 15, StringRoadUser.class).toArray()); assertArrayEquals(asList(o3).toArray(), RoadModels.findObjectsWithinRadius(ref, rm, 10, StringRoadUser.class) .toArray()); assertArrayEquals(allObjects.toArray(), RoadModels.findObjectsWithinRadius(ref, rm, 30, RoadUser.class) .toArray()); assertArrayEquals(asList().toArray(), RoadModels.findObjectsWithinRadius(ref, rm, 30, EmptyRoadUser.class) .toArray()); }