List of usage examples for org.apache.commons.math3.util FastMath nextAfter
public static float nextAfter(final float f, final double direction)
From source file:it.unibo.alchemist.test.TestContinuous2DObstacle.java
@Test public void test() { final Continuous2DObstacles<Integer> env = new Continuous2DObstacles<>(); env.setLinkingRule(new NoLinks<Integer>()); env.addObstacle(R1021);//w w w.j a va 2 s . co m env.addObstacle(R0527); assertEquals(new Continuous2DEuclidean(FastMath.nextAfter(1.0, 0.0), FastMath.nextAfter(1.0, 0.0)), env.next(0, 0, 1, 1)); assertEquals(new Continuous2DEuclidean(0, 1), env.next(1, 1, 0, 0)); assertEquals(new Continuous2DEuclidean(FastMath.nextAfter(1.0, 0.0), FastMath.nextAfter(0.5, 0.0)), env.next(0, 0, 2, 1)); env.addNode(new DummyNode(env), new Continuous2DEuclidean(0, 0)); assertEquals(env.getNodesNumber(), 1); env.addNode(new DummyNode(env), new Continuous2DEuclidean(1, 1)); assertEquals(env.getNodesNumber(), 1); env.addNode(new DummyNode(env), new Continuous2DEuclidean(1.5, 0.5)); assertEquals(env.getNodesNumber(), 1); env.addNode(new DummyNode(env), new Continuous2DEuclidean(1, 5)); assertEquals(env.getNodesNumber(), 1); env.addNode(new DummyNode(env), new Continuous2DEuclidean(1, 2.999)); assertEquals(env.getNodesNumber(), 2); assertEquals(env.getObstaclesInRange(0d, 0d, 100d).size(), 2); assertEquals(env.getObstaclesInRange(0d, 0d, 1d).size(), 1); assertEquals(env.getObstaclesInRange(0d, 0d, 1d).get(0), R1021); assertEquals(env.getObstaclesInRange(1d, 5d, 1d).size(), 1); assertEquals(env.getObstaclesInRange(1d, 5d, 1d).get(0), R0527); assertEquals(env.getObstaclesInRange(0d, 0d, 0.5d).size(), 0); }
From source file:it.unibo.alchemist.model.implementations.utils.RectObstacle2D.java
@Override public Continuous2DEuclidean next(final double startx, final double starty, final double endx, final double endy) { final double[] onBorders = enforceBorders(startx, starty, endx, endy); if (onBorders != null) { /*/*from w ww.j a v a 2s . c om*/ * The starting point was on the border. */ return new Continuous2DEuclidean(onBorders); } final double[] intersection = nearestIntersection(startx, starty, endx, endy); /* * Ensure the intersection is outside the boundaries. Force it to be. */ while (contains(intersection[0], intersection[1])) { intersection[0] = FastMath.nextAfter(intersection[0], startx); intersection[1] = FastMath.nextAfter(intersection[1], starty); } final double[] restricted = enforceBorders(intersection[0], intersection[1], intersection[0], intersection[1]); if (restricted == null) { return new Continuous2DEuclidean(intersection); } return new Continuous2DEuclidean(restricted); }
From source file:it.unibo.alchemist.model.implementations.utils.RectObstacle2D.java
@SuppressFBWarnings("PZLA_PREFER_ZERO_LENGTH_ARRAYS") private double[] enforceBorders(final double startx, final double starty, final double endx, final double endy) { /*//from w ww . j av a 2s . c om * Check if the point is somehow inside the obstacle, and reply * accordingly */ if (fuzzyGreaterEquals(starty, minY) && fuzzyGreaterEquals(maxY, starty) && fuzzyGreaterEquals(startx, minX) && fuzzyGreaterEquals(maxX, startx)) { final double[] res = new double[] { endx, endy }; if (fuzzyEquals(startx, minX) && endx >= minX) { /* * Left border */ res[0] = FastMath.nextAfter(minX, startx); } else if (fuzzyEquals(startx, maxX) && endx <= maxX) { /* * Right border */ res[0] = FastMath.nextAfter(maxX, startx); } if (fuzzyEquals(starty, minY) && endy >= minY) { /* * Bottom border */ res[1] = FastMath.nextAfter(minY, starty); } else if (fuzzyEquals(starty, maxY) && endy <= maxY) { /* * Top border */ res[1] = FastMath.nextAfter(maxY, starty); } return res; } return null; }