/** * Computes the difference between two points: <code>p1 - p2</code>. * @param p1 A point. * @param p2 Another point. * @return The difference as a point object. */ public static Point diff(Point p1, Point p2) { return new Point(p1.x - p2.x, p1.y - p2.y); }
/** * Multiplies the point, the result is returned as a new point. * @param p The point to multiply. * @param d The multiplicand. * @return A new point containing the result. */ public static Point multiply(Point p, double d) { return new Point(p.x * d, p.y * d); }
/** * Divides the point, the result is returned as a new point. * @param p The point to divide. * @param d The divisor. * @return A new point containing the result. */ public static Point divide(Point p, double d) { return new Point(p.x / d, p.y / d); }
VehicleUI(MovingRoadUser mru, CollisionGraphRoadModel m, int c, Set<VizOptions> t, int num) { vehicle = mru; model = m; angle = 0; color = c; vizOptions = t; creationNumber = num; position = new Point(0, 0); image = Optional.absent(); }
static Point on(Point from, Point to, double dist) { final double length = PointUtil.length(from, to); final double ratio = dist / length; final double invRatio = 1 - ratio; final double x = to.x * ratio + invRatio * from.x; final double y = to.y * ratio + invRatio * from.y; return new Point(x, y); }
@Override public Point getRandomPosition(RandomGenerator rnd) { return new Point(min.x + rnd.nextDouble() * width, min.y + rnd.nextDouble() * height); }
Image renderStatic() { size = new org.eclipse.swt.graphics.Point((int) (m * viewRect.width), (int) (m * viewRect.height)); final Image img = new Image(getDisplay(), size.x, size.y); final GC gc = new GC(img); for (final CanvasRenderer r : canvasRenderers) { r.renderStatic(gc, new ViewPort(new Point(0, 0), viewRect, m)); } gc.dispose(); return img; }
@Override public ImmutableList<Point> generate(long seed, int numOrders) { rng.setSeed(seed); final ImmutableList.Builder<Point> locs = ImmutableList.builder(); for (int i = 0; i < numOrders; i++) { locs.add(new Point( xSupplier.get(rng.nextLong()), ySupplier.get(rng.nextLong()))); } return locs.build(); } }
@Test public void setConnData() { final Point N = new Point(0, 5); final Point E = new Point(5, 0); final Point S = new Point(0, -5); final Point W = new Point(-5, 0); Graphs.addBiPath(graph, N, E, S, W, N); assertFalse(graph.setConnectionData(N, E, LengthData.create(100)) .isPresent()); assertEquals(LengthData.create(100), graph.removeConnectionData(N, E).get()); }
@Override public GenericRoadModel create(ForwardingRoadModelTest testClass) { return new ForwardingRoadModel( RoadModelBuilders.plane() .withMinPoint(new Point(0, 0)) .withMaxPoint(new Point(10, 10)) .withDistanceUnit(SI.METER) .withSpeedUnit(SI.METERS_PER_SECOND) .withMaxSpeed(10d) .build(mock(DependencyProvider.class))); } }}, {new Creator() {
@SuppressWarnings("null") @Test(expected = IllegalArgumentException.class) public void getShortestPathToFail4() { model.getShortestPathTo((Point) null, new Point(0, 0)); }
@SuppressWarnings("null") @Test(expected = IllegalArgumentException.class) public void computeConnectionLengthFail2() { model.computeDistanceOnConnection(new Point(1, 2), null); }
@Test(expected = IllegalArgumentException.class) public void addPackageInFail5() { final Depot d = new TestDepot(10); final Parcel p1 = Parcel.builder(new Point(0, 0), new Point(0, 0)) .neededCapacity(11d) .build(); model.register(p1); model.register(d); rm.addObjectAt(d, new Point(0, 0)); model.addParcelIn(d, p1); }
@Test public void testRandomNode() { final RandomGenerator rnd = new MersenneTwister(456); for (int i = 0; i < 500; i++) { Graphs.addBiPath(graph, new Point(rnd.nextInt(), rnd.nextInt()), new Point(rnd.nextInt(), rnd.nextInt())); } final Graph<LengthData> unmod = Graphs.unmodifiableGraph(graph); final Point p1 = graph.getRandomNode(new MersenneTwister(123)); final Point p2 = unmod.getRandomNode(new MersenneTwister(123)); assertEquals(p1, p2); }
static VehicleDTO vdto() { return VehicleDTO.builder() .startPosition(new Point(0, 0)) .speed(1d) .capacity(1) .availabilityTimeWindow(TimeWindow.always()) .build(); }