// Converts a Coordinates object to a LatLng object public static LatLng coordinatesToLatLng(Coordinates coordinates) { LatLng latLng = null; if (coordinates != null) { latLng = new LatLng(coordinates.getLatitude(), coordinates.getLongitude()); } return latLng; }
/** * Sets the occupied coordinates of this game. Method is synchronized so animation thread cannot * mutate the game state while this method is filling the board. * * @param coordinates */ synchronized void setFilledSquares(ArrayList<Coordinates> coordinates) { this.occupiedCell = new boolean[MAX_ROWS][MAX_COLUMNS]; for (Coordinates coord : coordinates) { this.occupiedCell[coord.getRow()][coord.getColumn()] = true; } this.repaint(); }
/** * Draws a Healpix pixel according to a coordinate system. * * <p>When the pixel area is "small", only the four points of the pixel are used to plot it. When * the pixel area is "large", intermediate points on boundaries pixel are automatically computed * to smooth the boundary of the pixel on the plot. * * @param graphic2D graph component to decore * @param healpix Healpix index * @param pix Pixel to draw * @param coordinateTransformation Coordinate transformation */ @Override protected final void drawHealpixPolygon( final Graphics2D graphic2D, final HealpixIndex healpix, final long pix, final CoordinateTransformation coordinateTransformation) { try { final int numberOfVectors = computeNumberPointsForPixel(getHealpixBase().getNside(), pix); final Vec3[] vectors = healpix.boundaries(pix, numberOfVectors); computeReferenceFrameTransformation(vectors, coordinateTransformation); final Coordinates[] shapes = splitHealpixPixelForDetectedBorder(vectors); final Polygon2D poly = new Polygon2D(); for (int i = 0; i < shapes.length; i++) { final Coordinates shape = shapes[i]; final List<Point2D.Double> pixels = shape.getPixelsFromProjection( this.getProjection(), getRange(), getPixelWidth(), getPixelHeight()); poly.setPoints(pixels); graphic2D.draw(poly); graphic2D.fill(poly); } } catch (Exception ex) { LOG.log(Level.SEVERE, null, ex); } }
private synchronized void adjust() { // Generate random position in graph space tempISOM = new ISOMVertexData(); tempXYD = new Coordinates(); // creates a new XY data location tempXYD.setX(10 + Math.random() * getCurrentSize().getWidth()); tempXYD.setY(10 + Math.random() * getCurrentSize().getHeight()); // Get closest vertex to random position Vertex winner = elementAccessor.getVertex(tempXYD.getX(), tempXYD.getY()); while (true) { try { for (Iterator iter = getVisibleVertices().iterator(); iter.hasNext(); ) { Vertex v = (Vertex) iter.next(); ISOMVertexData ivd = getISOMVertexData(v); ivd.distance = 0; ivd.visited = false; } break; } catch (ConcurrentModificationException cme) { } } adjustVertex(winner); }
public void printSolution(List<Field> fields, int width, int height) { int[][] solution = new int[height][width]; for (int[] row : solution) { Arrays.fill(row, -1); } for (int i = 0; i < fields.size(); i++) { Field field = fields.get(i); Coordinates coordinates = field.getCoordinates(); solution[coordinates.getX()][coordinates.getY()] = i; } for (int[] row : solution) { StringBuilder sb = new StringBuilder(); for (int i : row) { if (i == -1) { sb.append("**|"); } else if (i < 10) { sb.append("*" + i + "|"); } else { sb.append(i + "|"); } } System.out.println(sb.toString()); } }
/** This method is from GPSListener, used to notify the ProximityListener. */ public void sentenceReceived(NMEASentence sen) { // Check if this sentence has location info if (sen.getHeader().equals(GGASentence.HEADER)) { Coordinates cur = null; Location loc = null; try { loc = this.getLocation(-1); cur = loc.getQualifiedCoordinates(); } catch (InterruptedException e) { // TODO: This method should bail properly if it fails. System.err.println("Fail 1"); } catch (LocationException e) { // TODO: This method should bail properly if it fails. System.err.println("Fail 2"); } for (int i = 0; i < listeners.size(); i++) { Object[] array = listeners.get(i); ProximityListener pl = (ProximityListener) array[0]; Coordinates to = (Coordinates) array[1]; Float rad = (Float) array[2]; // Now check radius against coordinate and notify listener. if (cur.distance(to) <= rad.floatValue()) { // Remove this ProximityListener because it should be notified only once. // I prefer to do this BEFORE notifying the pl because the user might try // to re-add the pl in proximityEvent(). LocationProvider.removeProximityListener(pl); pl.proximityEvent(to, loc); } } // TODO: Handle LocationListeners here instead of inner? } }
@Test public void givenLocationInAngle_CanRetrieveTheLongitude() { Angle latitude = Angle.fromDegrees(39.54); Angle longitude = Angle.fromDegrees(-54.76); Coordinates location = Coordinates.locatedAt(latitude, longitude); assertThat(location.getLongitude()).isEqualTo(longitude); }
private static boolean isEdge(int height, int width, Coordinates coordinates) { if (coordinates.getX() == 0 || coordinates.getY() == 0) { return true; } else if (coordinates.getY() == height - 1 || coordinates.getX() == width - 1) { return true; } else { return false; } }
@Test public void canCalculateTheDistanceBetweenTwoLocationsOnTheSameContinent() { Coordinates centerBellInMontreal = Coordinates.locatedAt(45.4959755, -73.5693904); Coordinates yankeeStadiumInNewYork = Coordinates.locatedAt(40.8295818, -73.9261455); Length distance = centerBellInMontreal.getDistanceTo(yankeeStadiumInNewYork); assertThat(distance.toKilometers()).isWithin(0.5).of(519.23); }
@Test public void givenTwoFarLocationsButTooShortRange_ShouldBeInRange() { Coordinates manhattan = Coordinates.locatedAt(40.7791547, -73.9654464); Coordinates harvardUniversity = Coordinates.locatedAt(42.3770068, -71.1188488); Length range = Length.fromMiles(50); boolean inRange = manhattan.isInRange(harvardUniversity, range); assertThat(inRange).isFalse(); }
@Test public void givenTwoFarLocationsButVeryLargeRange_ShouldBeInRange() { Coordinates manhattan = Coordinates.locatedAt(40.7791547, -73.9654464); Coordinates harvardUniversity = Coordinates.locatedAt(42.3770068, -71.1188488); Length range = Length.fromMiles(200); boolean inRange = harvardUniversity.isInRange(manhattan, range); assertThat(inRange).isTrue(); }
@Test public void givenTwoVeryNearLocationsAndVeryShortRange_ShouldBeInRange() { Coordinates googlePlex = Coordinates.locatedAt(37.4218047, -122.0838097); Coordinates googleSoccerField = Coordinates.locatedAt(37.424242, -122.0874509); Length range = Length.fromMiles(0.30); boolean inRange = googlePlex.isInRange(googleSoccerField, range); assertThat(inRange).isTrue(); }
@Test public void canCalculateTheDistanceBetweenTwoLocationsOnDifferentContinents() { // Example found on http://janmatuschek.de/LatitudeLongitudeBoundingCoordinates Coordinates statueOfLiberty = Coordinates.locatedAt(40.6892, -74.0444); Coordinates eiffelTower = Coordinates.locatedAt(48.8583, 2.2945); Length distance = statueOfLiberty.getDistanceTo(eiffelTower); assertThat(distance.toKilometers()).isWithin(0.5).of(5_837); }
// This method is wrong, but yields an OK approximation. public Coordinates move(Coordinates start, Vector direction, double distance) { Vector v = new Vector(direction); v.normalize(); v.scale(distance); Coordinates retval = new Coordinates(start.u, start.v); retval.u += v.components[0]; retval.v += v.components[1]; return retval; }
/** * Public ctor. * * @param req Request * @param repo Repository * @param name Name of it */ RtLabel(final Request req, final Repo repo, final String name) { final Coordinates coords = repo.coordinates(); this.request = req.uri() .path("/repos") .path(coords.user()) .path(coords.repo()) .path("/labels") .path(name) .back(); this.owner = repo; this.txt = name; }
private XYDataset createDataset(final List<Coordinates>... lists) { final XYSeriesCollection dataset = new XYSeriesCollection(); int i = 0; for (final List<Coordinates> list : lists) { final XYSeries xySeries = new XYSeries(i); for (final Coordinates coordinates : list) { xySeries.add(coordinates.getFirst(), coordinates.getSecond()); } dataset.addSeries(xySeries); i++; } return dataset; }
private boolean funcLocMixVeloOk(ccr.app.Context ctx1, ccr.app.Context ctx2) { java.lang.String v1 = (java.lang.String) ctx1.get(Context.FLD_OBJECT); java.lang.String v2 = (java.lang.String) ctx1.get(Context.FLD_TIMESTAMP); java.lang.String v3 = (java.lang.String) ctx2.get(Context.FLD_OBJECT); java.lang.String v4 = (java.lang.String) ctx2.get(Context.FLD_TIMESTAMP); if (v1 == null || v2 == null || v3 == null || v4 == null) { return false; } java.util.StringTokenizer st = new java.util.StringTokenizer(v1); double x1 = Double.parseDouble(st.nextToken()); double y1 = Double.parseDouble(st.nextToken()); st = new java.util.StringTokenizer(v3); double x2 = Double.parseDouble(st.nextToken()); double y2 = Double.parseDouble(st.nextToken()); double dist = Coordinates.calDist(x1, y1, x2, y2); long t = TimeFormat.convert(v4) - TimeFormat.convert(v2) - STAY_TIME; boolean result = false; double vmin = (VELOCITY * ((double) t / 1000) - 2 * ERR) / ((double) t / 1000); double vmax = (VELOCITY * ((double) t / 1000) + 2 * ERR) / ((double) t / 1000); double ve = dist / ((double) t / 1000); if (ve >= vmin && ve <= vmax) { result = true; } return result; }
@Test public void testToCreateARobotAndPlaceIt() { DIRECTIONS pos = DIRECTIONS.valueOf("NORTH"); xy.setXY(0, 0); robot.place(pos, xy); assertEquals("0,0 NORTH", robot.report()); }
private boolean funcLocMixVeloOk(Context ctx1, Context ctx2) { // boolean function 4 String v1 = (String) ctx1.get(Context.FLD_OBJECT); String v2 = (String) ctx1.get(Context.FLD_TIMESTAMP); String v3 = (String) ctx2.get(Context.FLD_OBJECT); String v4 = (String) ctx2.get(Context.FLD_TIMESTAMP); if (v1 == null || v2 == null || v3 == null || v4 == null) { return false; } StringTokenizer st = new StringTokenizer(v1); double x1 = Double.parseDouble(st.nextToken()); double y1 = Double.parseDouble(st.nextToken()); st = new StringTokenizer(v3); double x2 = Double.parseDouble(st.nextToken()); double y2 = Double.parseDouble(st.nextToken()); double dist = Coordinates.calDist(x1, y1, x2, y2); long t = TimeFormat.convert(v4) - TimeFormat.convert(v2) - STAY_TIME; // Different here // The velocity should be between vmin and vmax boolean result = false; double vmin = (VELOCITY * ((double) t / 1000) - 2 * ERR) / ((double) t / 1000); double vmax = (VELOCITY * ((double) t / 1000) + 2 * ERR) / ((double) t / 1000); double ve = dist / ((double) t / 1000); if (ve >= vmin && ve <= vmax) { result = true; } return result; }
@Test public void testToTurnRobotFacingWestAndThenTurnRight() { DIRECTIONS pos = DIRECTIONS.valueOf("WEST"); xy.setXY(0, 0); robot.place(pos, xy); robot.turnRight(); assertEquals("0,0 NORTH", robot.report()); }
@Test public void testToTurnLeftRobotFacingNorth() { DIRECTIONS pos = DIRECTIONS.valueOf("NORTH"); xy.setXY(0, 0); robot.place(pos, xy); robot.turnLeft(); assertEquals("0,0 WEST", robot.report()); }
@Test public void testTomoveRobotFacingSouthAt00() { DIRECTIONS pos = DIRECTIONS.valueOf("SOUTH"); xy.setXY(0, 0); robot.place(pos, xy); robot.move(); assertEquals("0,-1 SOUTH", robot.report()); }
@Test public void testTomoveRobotFacingEastAt00() { DIRECTIONS pos = DIRECTIONS.valueOf("EAST"); xy.setXY(0, 0); robot.place(pos, xy); robot.move(); assertEquals("1,0 EAST", robot.report()); }
/** * This routine computes which positions on the board have to be flipped when a certain move is * made. The move is specified by the position <code>pos</code> and the player color <code>color * </code>. The array <code>flipped</code> will be filled with the result. A "0" indicates no * flip, while a "1" indicates that the stone at this position will be flipped when the * corresponding move is made. */ void computeTokensToFlip(GameBoard gb, Coordinates pos, int color, int[][] toFlip) { int drow, dcol; int opposite = color == GameBoard.RED ? GameBoard.GREEN : GameBoard.RED; boolean oneFlipped; int[][] currentBoard = new int[BOARD_LENGTH][BOARD_LENGTH]; int row = pos.getRow() - 1; int col = pos.getCol() - 1; try { for (int i = 1; i <= BOARD_LENGTH; i++) { for (int j = 1; j <= BOARD_LENGTH; j++) { currentBoard[i - 1][j - 1] = gb.getPosition(new Coordinates(i, j)); toFlip[i - 1][j - 1] = 0; } } } catch (OutOfBoundsException e) { System.out.println("I checked an illegal position. I am sorry."); } for (int idx = 0; idx < direction.length; idx += 2) { int delta_row = direction[idx]; int delta_col = direction[idx + 1]; drow = row + delta_row; dcol = col + delta_col; oneFlipped = false; while (onBoard(drow, dcol) && currentBoard[drow][dcol] == opposite) { oneFlipped = true; drow += delta_row; dcol += delta_col; } if (onBoard(drow, dcol) && oneFlipped && currentBoard[drow][dcol] == color) { drow = row + delta_row; dcol = col + delta_col; while (currentBoard[drow][dcol] == opposite) { toFlip[drow][dcol] = 1; drow += delta_row; dcol += delta_col; } } } }
private boolean funcLocDistOk(ccr.app.Context ctx1, ccr.app.Context ctx2) { java.lang.String v1 = (java.lang.String) ctx1.get(Context.FLD_OBJECT); java.lang.String v2 = (java.lang.String) ctx2.get(Context.FLD_OBJECT); if (v1 == null || v2 == null) { return false; } java.util.StringTokenizer st = new java.util.StringTokenizer(v1); double x1 = Double.parseDouble(st.nextToken()); double y1 = Double.parseDouble(st.nextToken()); st = new java.util.StringTokenizer(v2); double x2 = Double.parseDouble(st.nextToken()); double y2 = Double.parseDouble(st.nextToken()); double dist = Coordinates.calDist(x1, y1, x2, y2); boolean result = false; if (dist <= 2 * ERR) { result = true; } return result; }
private synchronized void adjustVertex(Vertex v) { queue.removeAllElements(); ISOMVertexData ivd = getISOMVertexData(v); ivd.distance = 0; ivd.visited = true; queue.add(v); Vertex current; while (!queue.isEmpty()) { current = (Vertex) queue.remove(0); ISOMVertexData currData = getISOMVertexData(current); Coordinates currXYData = getCoordinates(current); double dx = tempXYD.getX() - currXYData.getX(); double dy = tempXYD.getY() - currXYData.getY(); double factor = adaption / Math.pow(2, currData.distance); currXYData.addX(factor * dx); currXYData.addY(factor * dy); if (currData.distance < radius) { Set s = current.getNeighbors(); while (true) { try { for (Iterator iter = s.iterator(); iter.hasNext(); ) { Vertex child = (Vertex) iter.next(); ISOMVertexData childData = getISOMVertexData(child); if (childData != null && !childData.visited) { childData.visited = true; childData.distance = currData.distance + 1; queue.addElement(child); } } break; } catch (ConcurrentModificationException cme) { } } } } }
private boolean funcLocDistOk(Context ctx1, Context ctx2) { // boolean function 1 String v1 = (String) ctx1.get(Context.FLD_OBJECT); String v2 = (String) ctx2.get(Context.FLD_OBJECT); if (v1 == null || v2 == null) { return false; } StringTokenizer st = new StringTokenizer(v1); double x1 = Double.parseDouble(st.nextToken()); double y1 = Double.parseDouble(st.nextToken()); st = new StringTokenizer(v2); double x2 = Double.parseDouble(st.nextToken()); double y2 = Double.parseDouble(st.nextToken()); double dist = Coordinates.calDist(x1, y1, x2, y2); // The distance should not be larger than two times the allowed error boolean result = false; if (dist <= 2 * ERR) { result = true; } return result; }
public java.lang.Object application(java.lang.String testcase) { int seed = Integer.parseInt(testcase); queue = new java.util.Vector(); ccr.app.Coordinates location = null; java.util.Random rand = new java.util.Random(seed); ccr.app.CCRScenarios scenarios = new ccr.app.CCRScenarios(seed); long t; ccr.app.Coordinates actLoc; ccr.app.Coordinates estLoc; ccr.app.Coordinates lastLoc; double dist; double displace; double error; int c = 0; int bPos = -1; int cPos = -1; int stay = 0; int lastPos = -1; timestamp = System.currentTimeMillis(); counter = 0; int moved = 0; int reliable = 0; ccr.app.Coordinates lastLocation = new ccr.app.Coordinates(0, 0); cPos = rand.nextInt(CCRScenarios.POS_NUM); stay = rand.nextInt(MAX_STAY) + 1; c = c + stay; bPos = cPos; stay = stay - 1; actLoc = scenarios.getActLoc(sid, cPos); estLoc = scenarios.getEstLoc(sid, cPos); curEstX = estLoc.x; curEstY = estLoc.y; curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; t = 0; timestamp = timestamp + t; lastPos = cPos; candidate = generateCtx(); resolve(); location = toCoordinates(candidate); displace = Math.sqrt( (location.x - lastLocation.x) * (location.x - lastLocation.x) + (location.y - lastLocation.y) * (location.y - lastLocation.y)); moved = moved + toBoolean(displace); error = Math.sqrt( (actLoc.x - location.x) * (actLoc.x - location.x) + (actLoc.y - location.y) * (actLoc.y - location.y)); lastLocation = location; counter = counter + 1; while (stay > 0) { stay = stay - 1; actLoc = scenarios.getActLoc(sid, cPos); estLoc = scenarios.getEstLoc(sid, cPos); curEstX = estLoc.x; curEstY = estLoc.y; curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; lastLoc = scenarios.getActLoc(sid, lastPos); dist = Coordinates.calDist(lastLoc, actLoc); t = STAY_TIME; timestamp = timestamp + t; candidate = generateCtx(); resolve(); location = toCoordinates(candidate); displace = Math.sqrt( (location.x - lastLocation.x) * (location.x - lastLocation.x) + (location.y - lastLocation.y) * (++location.y - lastLocation.y)); moved = moved + toBoolean(displace); error = Math.sqrt( (actLoc.x - location.x) * (actLoc.x - location.x) + (actLoc.y - location.y) * (actLoc.y - location.y)); if (error <= ERR) { reliable = reliable + 1; } lastLocation = location; counter = counter + 1; } cPos = rand.nextInt(CCRScenarios.POS_NUM); while (cPos == -1 || cPos == bPos || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos)) < WALK_DIST) { cPos = rand.nextInt(CCRScenarios.POS_NUM); } stay = rand.nextInt(MAX_STAY) + 1; c = c + stay; bPos = cPos; stay = stay - 1; actLoc = scenarios.getActLoc(sid, cPos); estLoc = scenarios.getEstLoc(sid, cPos); curEstX = estLoc.x; curEstY = estLoc.y; curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; lastLoc = scenarios.getActLoc(sid, lastPos); dist = Coordinates.calDist(lastLoc, actLoc); t = (long) (dist / VELOCITY * 1000); timestamp = timestamp + t; lastPos = cPos; candidate = generateCtx(); resolve(); location = toCoordinates(candidate); displace = Math.sqrt( (location.x - lastLocation.x) * (location.x - lastLocation.x) + (location.y - lastLocation.y) * (location.y - lastLocation.y)); moved = moved + toBoolean(displace); error = Math.sqrt( (actLoc.x - location.x) * (actLoc.x - location.x) + (actLoc.y - location.y) * (actLoc.y - location.y)); lastLocation = location; counter = counter + 1; while (stay > 0) { stay = stay - 1; actLoc = scenarios.getActLoc(sid, cPos); estLoc = scenarios.getEstLoc(sid, cPos); curEstX = estLoc.x; curEstY = estLoc.y; curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; lastLoc = scenarios.getActLoc(sid, lastPos); dist = Coordinates.calDist(lastLoc, actLoc); t = STAY_TIME; timestamp = timestamp + t; lastPos = cPos; candidate = generateCtx(); resolve(); location = toCoordinates(candidate); displace = Math.sqrt( (location.x - lastLocation.x) * (location.x - lastLocation.x) + (location.y - lastLocation.y) * (location.y - lastLocation.y)); moved = moved + toBoolean(displace); error = Math.sqrt( (actLoc.x - location.x) * (actLoc.x - location.x) + (actLoc.y - location.y) * (actLoc.y - location.y)); if (error <= ERR) { reliable = reliable + 1; } lastLocation = location; counter = counter + 1; } cPos = rand.nextInt(CCRScenarios.POS_NUM); while (cPos == -1 || cPos == bPos || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos)) < WALK_DIST) { cPos = rand.nextInt(CCRScenarios.POS_NUM); } stay = rand.nextInt(MAX_STAY) + 1; c = c + stay; bPos = cPos; stay = stay - 1; actLoc = scenarios.getActLoc(sid, cPos); estLoc = scenarios.getEstLoc(sid, cPos); curEstX = estLoc.x; curEstY = estLoc.y; curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; lastLoc = scenarios.getActLoc(sid, lastPos); dist = Coordinates.calDist(lastLoc, actLoc); t = (long) (dist / VELOCITY * 1000); timestamp = timestamp + t; lastPos = cPos; candidate = generateCtx(); resolve(); location = toCoordinates(candidate); displace = Math.sqrt( (location.x - lastLocation.x) * (location.x - lastLocation.x) + (location.y - lastLocation.y) * (location.y - lastLocation.y)); moved = moved + toBoolean(displace); error = Math.sqrt( (actLoc.x - location.x) * (actLoc.x - location.x) + (actLoc.y - location.y) * (actLoc.y - location.y)); lastLocation = location; counter = counter + 1; while (stay > 0) { stay = stay - 1; actLoc = scenarios.getActLoc(sid, cPos); estLoc = scenarios.getEstLoc(sid, cPos); curEstX = estLoc.x; curEstY = estLoc.y; curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; lastLoc = scenarios.getActLoc(sid, lastPos); dist = Coordinates.calDist(lastLoc, actLoc); t = STAY_TIME; timestamp = timestamp + t; lastPos = cPos; candidate = generateCtx(); resolve(); location = toCoordinates(candidate); displace = Math.sqrt( (location.x - lastLocation.x) * (location.x - lastLocation.x) + (location.y - lastLocation.y) * (location.y - lastLocation.y)); moved = moved + toBoolean(displace); error = Math.sqrt( (actLoc.x - location.x) * (actLoc.x - location.x) + (actLoc.y - location.y) * (actLoc.y - location.y)); if (error <= ERR) { reliable = reliable + 1; } lastLocation = location; counter = counter + 1; } cPos = rand.nextInt(CCRScenarios.POS_NUM); while (cPos == -1 || cPos == bPos || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos)) < WALK_DIST) { cPos = rand.nextInt(CCRScenarios.POS_NUM); } stay = rand.nextInt(MAX_STAY) + 1; c = c + stay; bPos = cPos; stay = stay - 1; actLoc = scenarios.getActLoc(sid, cPos); estLoc = scenarios.getEstLoc(sid, cPos); curEstX = estLoc.x; curEstY = estLoc.y; curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; lastLoc = scenarios.getActLoc(sid, lastPos); dist = Coordinates.calDist(lastLoc, actLoc); t = (long) (dist / VELOCITY * 1000); timestamp = timestamp + t; lastPos = cPos; candidate = generateCtx(); resolve(); location = toCoordinates(candidate); displace = Math.sqrt( (location.x - lastLocation.x) * (location.x - lastLocation.x) + (location.y - lastLocation.y) * (location.y - lastLocation.y)); moved = moved + toBoolean(displace); error = Math.sqrt( (actLoc.x - location.x) * (actLoc.x - location.x) + (actLoc.y - location.y) * (actLoc.y - location.y)); lastLocation = location; counter = counter + 1; while (stay > 0) { stay = stay - 1; actLoc = scenarios.getActLoc(sid, cPos); estLoc = scenarios.getEstLoc(sid, cPos); curEstX = estLoc.x; curEstY = estLoc.y; curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; lastLoc = scenarios.getActLoc(sid, lastPos); dist = Coordinates.calDist(lastLoc, actLoc); t = STAY_TIME; timestamp = timestamp + t; lastPos = cPos; candidate = generateCtx(); resolve(); location = toCoordinates(candidate); displace = Math.sqrt( (location.x - lastLocation.x) * (location.x - lastLocation.x) + (location.y - lastLocation.y) * (location.y - lastLocation.y)); moved = moved + toBoolean(displace); error = Math.sqrt( (actLoc.x - location.x) * (actLoc.x - location.x) + (actLoc.y - location.y) * (actLoc.y - location.y)); if (error <= ERR) { reliable = reliable + 1; } lastLocation = location; counter = counter + 1; } cPos = rand.nextInt(CCRScenarios.POS_NUM); while (cPos == -1 || cPos == bPos || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos)) < WALK_DIST) { cPos = rand.nextInt(CCRScenarios.POS_NUM); } stay = rand.nextInt(MAX_STAY) + 1; c = c + stay; bPos = cPos; stay = stay - 1; actLoc = scenarios.getActLoc(sid, cPos); estLoc = scenarios.getEstLoc(sid, cPos); curEstX = estLoc.x; curEstY = estLoc.y; curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; lastLoc = scenarios.getActLoc(sid, lastPos); dist = Coordinates.calDist(lastLoc, actLoc); t = (long) (dist / VELOCITY * 1000); timestamp = timestamp + t; lastPos = cPos; candidate = generateCtx(); resolve(); location = toCoordinates(candidate); displace = Math.sqrt( (location.x - lastLocation.x) * (location.x - lastLocation.x) + (location.y - lastLocation.y) * (location.y - lastLocation.y)); moved = moved + toBoolean(displace); error = Math.sqrt( (actLoc.x - location.x) * (actLoc.x - location.x) + (actLoc.y - location.y) * (actLoc.y - location.y)); lastLocation = location; counter = counter + 1; while (stay > 0) { stay = stay - 1; actLoc = scenarios.getActLoc(sid, cPos); estLoc = scenarios.getEstLoc(sid, cPos); curEstX = estLoc.x; curEstY = estLoc.y; curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; lastLoc = scenarios.getActLoc(sid, lastPos); dist = Coordinates.calDist(lastLoc, actLoc); t = STAY_TIME; timestamp = timestamp + t; lastPos = cPos; candidate = generateCtx(); resolve(); location = toCoordinates(candidate); displace = Math.sqrt( (location.x - lastLocation.x) * (location.x - lastLocation.x) + (location.y - lastLocation.y) * (location.y - lastLocation.y)); moved = moved + toBoolean(displace); error = Math.sqrt( (actLoc.x - location.x) * (actLoc.x - location.x) + (actLoc.y - location.y) * (actLoc.y - location.y)); if (error <= ERR) { reliable = reliable + 1; } lastLocation = location; counter = counter + 1; } cPos = rand.nextInt(CCRScenarios.POS_NUM); while (cPos == -1 || cPos == bPos || Coordinates.calDist(scenarios.getActLoc(sid, bPos), scenarios.getActLoc(sid, cPos)) < WALK_DIST) { cPos = rand.nextInt(CCRScenarios.POS_NUM); } stay = rand.nextInt(MAX_STAY) + 1; c = c + stay; bPos = cPos; stay = stay - 1; actLoc = scenarios.getActLoc(sid, cPos); estLoc = scenarios.getEstLoc(sid, cPos); curEstX = estLoc.x; curEstY = estLoc.y; curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; lastLoc = scenarios.getActLoc(sid, lastPos); dist = Coordinates.calDist(lastLoc, actLoc); t = (long) (dist / VELOCITY * 1000); timestamp = timestamp + t; lastPos = cPos; candidate = generateCtx(); resolve(); location = toCoordinates(candidate); displace = Math.sqrt( (location.x - lastLocation.x) * (location.x - lastLocation.x) + (location.y - lastLocation.y) * (location.y - lastLocation.y)); moved = moved + toBoolean(displace); error = Math.sqrt( (actLoc.x - location.x) * (actLoc.x - location.x) + (actLoc.y - location.y) * (actLoc.y - location.y)); lastLocation = location; counter = counter + 1; while (stay > 0) { stay = stay - 1; actLoc = scenarios.getActLoc(sid, cPos); estLoc = scenarios.getEstLoc(sid, cPos); curEstX = estLoc.x; curEstY = estLoc.y; curEstX = curEstX + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; curEstY = curEstY + ((double) 2 * rand.nextDouble() - (double) 1) * NOISE; lastLoc = scenarios.getActLoc(sid, lastPos); dist = Coordinates.calDist(lastLoc, actLoc); t = STAY_TIME; timestamp = timestamp + t; lastPos = cPos; candidate = generateCtx(); resolve(); location = toCoordinates(candidate); displace = Math.sqrt( (location.x - lastLocation.x) * (location.x - lastLocation.x) + (location.y - lastLocation.y) * (location.y - lastLocation.y)); moved = moved + toBoolean(displace); error = Math.sqrt( (actLoc.x - location.x) * (actLoc.x - location.x) + (actLoc.y - location.y) * (actLoc.y - location.y)); if (error <= ERR) { reliable = reliable + 1; } lastLocation = location; counter = counter + 1; } ccr.app.ApplicationResult result = new ccr.app.ApplicationResult(moved, reliable); return result; }
@Test public void testNextForwardPositionNorth() { Coordinates position = MapTools.nextForwardPosition(new Coordinates(0, 0), NORTH); Assert.assertEquals(0, position.getX()); Assert.assertEquals(1, position.getY()); }
@Test public void testNextBackwardPositionWest() { Coordinates position = MapTools.nextBackwardPosition(new Coordinates(0, 0), WEST); Assert.assertEquals(1, position.getX()); Assert.assertEquals(0, position.getY()); }