public Room getActRoomTypeExitsNext() { Room nextRoom = null; Direction exit = getExit(); if (exit != null) { if (exit == Direction.LEFT) { nextRoom = grid.getRoom(position.goLeft()); System.err.println("LEFT"); } else if (exit == Direction.RIGHT) { nextRoom = grid.getRoom(position.goRight()); System.err.println("RIGHT"); } else if (exit == Direction.DOWN) { nextRoom = grid.getRoom(position.goDown()); System.err.println("DOWN"); } } if (nextRoom != null && nextRoom.isGateWay()) { nextRoom.actEntrance = getExit().opposite(); nextRoom.prev = this; next = nextRoom; } else { nextRoom = null; } return nextRoom; }
private void makeRadialWallTerrainConformant( DrawContext dc, int pillars, int stacks, float[] verts, double[] altitudes, boolean[] terrainConformant, Vec4 referenceCenter) { Globe globe = dc.getGlobe(); Matrix transform = this.computeTransform(dc.getGlobe(), dc.getVerticalExaggeration()); for (int p = 0; p <= pillars; p++) { int index = p; index = 3 * index; Vec4 vec = new Vec4(verts[index], verts[index + 1], verts[index + 2]); vec = vec.transformBy4(transform); Position pos = globe.computePositionFromPoint(vec); for (int s = 0; s <= stacks; s++) { double elevation = altitudes[s]; if (terrainConformant[s]) elevation += this.computeElevationAt(dc, pos.getLatitude(), pos.getLongitude()); vec = globe.computePointFromPosition(pos.getLatitude(), pos.getLongitude(), elevation); index = p + s * (pillars + 1); index = 3 * index; verts[index] = (float) (vec.x - referenceCenter.x); verts[index + 1] = (float) (vec.y - referenceCenter.y); verts[index + 2] = (float) (vec.z - referenceCenter.z); } } }
private void makePartialCylinderTerrainConformant( DrawContext dc, int slices, int stacks, float[] verts, double[] altitudes, boolean[] terrainConformant, Vec4 referenceCenter) { Globe globe = dc.getGlobe(); Matrix transform = this.computeTransform(dc.getGlobe(), dc.getVerticalExaggeration()); for (int i = 0; i <= slices; i++) { int index = i * (stacks + 1); index = 3 * index; Vec4 vec = new Vec4(verts[index], verts[index + 1], verts[index + 2]); vec = vec.transformBy4(transform); Position p = globe.computePositionFromPoint(vec); for (int j = 0; j <= stacks; j++) { double elevation = altitudes[j]; if (terrainConformant[j]) elevation += this.computeElevationAt(dc, p.getLatitude(), p.getLongitude()); vec = globe.computePointFromPosition(p.getLatitude(), p.getLongitude(), elevation); index = j + i * (stacks + 1); index = 3 * index; verts[index] = (float) (vec.x - referenceCenter.x); verts[index + 1] = (float) (vec.y - referenceCenter.y); verts[index + 2] = (float) (vec.z - referenceCenter.z); } } }
/** * Checks whether the position is located on the inner board (the playing area). Returns false for * positions on the outer positions, as well as positions that are not on the board. * * <p>By Leroy * * @param p position of which is to be determined whether the position is located on the inner * board */ private boolean isOnInnerBoard(Position p) { int col = p.getColName() - 'a' + 1; int row = p.getRowNumber(); // See google doc for explanation of the formula return !(row <= 1 || col >= 9 || row + col >= 14 || col - row <= -4 || col <= 1); }
/** * @param p position we are asking about * @return bool - true if this figure is at position p - false if this figure is not at position p */ public boolean isAtPosition(Position p) { if (p.sameColumn(this.pos) && p.sameRow(this.pos)) { return true; } else { return false; } }
protected static boolean isTileVisible( DrawContext dc, Tile tile, double minDistanceSquared, double maxDistanceSquared) { if (!tile.getSector().intersects(dc.getVisibleSector())) return false; View view = dc.getView(); Position eyePos = view.getEyePosition(); if (eyePos == null) return false; Angle lat = clampAngle( eyePos.getLatitude(), tile.getSector().getMinLatitude(), tile.getSector().getMaxLatitude()); Angle lon = clampAngle( eyePos.getLongitude(), tile.getSector().getMinLongitude(), tile.getSector().getMaxLongitude()); Vec4 p = dc.getGlobe().computePointFromPosition(lat, lon, 0d); double distSquared = dc.getView().getEyePoint().distanceToSquared3(p); //noinspection RedundantIfStatement if (minDistanceSquared > distSquared || maxDistanceSquared < distSquared) return false; return true; }
public Map<String, String> getPositionIdentifiers() { Map<String, String> idMap = new Hashtable<String, String>(); for (Position p : getPositions()) { idMap.put(p.getID(), p.getTitle()); } return idMap; }
/** * Clones this Step. * * @return a cloned step */ public Object clone() { PositionStep step = (PositionStep) super.clone(); if (step != null) step.points[0] = step.p = step.new Position(p.getX(), p.getY()); step.textLayouts = new HashMap<TrackerPanel, TextLayout>(); step.layoutBounds = new HashMap<TrackerPanel, Rectangle>(); return step; }
private void makePartialDiskTerrainConformant( DrawContext dc, int numCoords, float[] verts, double altitude, boolean terrainConformant, Vec4 referenceCenter) { Globe globe = dc.getGlobe(); Matrix transform = this.computeTransform(dc.getGlobe(), dc.getVerticalExaggeration()); for (int i = 0; i < numCoords; i += 3) { Vec4 vec = new Vec4(verts[i], verts[i + 1], verts[i + 2]); vec = vec.transformBy4(transform); Position p = globe.computePositionFromPoint(vec); double elevation = altitude; if (terrainConformant) elevation += this.computeElevationAt(dc, p.getLatitude(), p.getLongitude()); vec = globe.computePointFromPosition(p.getLatitude(), p.getLongitude(), elevation); verts[i] = (float) (vec.x - referenceCenter.x); verts[i + 1] = (float) (vec.y - referenceCenter.y); verts[i + 2] = (float) (vec.z - referenceCenter.z); } }
public City getCityAt(Position p) { if (p.getRow() == 1 && p.getColumn() == 1) { return new City() { public Player getOwner() { return Player.RED; } public int getSize() { return 1; } public String getProduction() { return null; } public String getWorkforceFocus() { return null; } @Override public int getTreasure() { // TODO Auto-generated method stub return 0; } }; } return null; }
public Set<Participant> resolveParticipantsFromResourceName(String anyName) { Set<Participant> pSet = new HashSet<Participant>(); Participant p = getParticipantFromUserID(anyName); if (p != null) { pSet.add(p); return pSet; } Role r = getRoleByName(anyName); if (r != null) { pSet.addAll(getRoleParticipants(r.getID())); return pSet; } Position pos = getPositionByLabel(anyName); if (pos != null) { pSet.addAll(getPositionParticipants(pos.getID())); return pSet; } OrgGroup o = getOrgGroupByLabel(anyName); if (o != null) { pSet.addAll(getOrgGroupParticipants(o.getID())); return pSet; } Capability c = getCapabilityByLabel(anyName); if (c != null) { pSet.addAll(getCapabilityParticipants(c.getID())); } return pSet; }
/** * Performs one line of sight calculation between the reference position and a specified grid * position. * * @param gridPosition the grid position. * @throws InterruptedException if the operation is interrupted. */ protected void performIntersection(Position gridPosition) throws InterruptedException { // Intersect the line between this grid point and the selected position. Intersection[] intersections = this.terrain.intersect(this.referencePosition, gridPosition); if (intersections == null || intersections.length == 0) { // No intersection, so the line goes from the center to the grid point. this.sightLines.add(new Position[] {this.referencePosition, gridPosition}); return; } // Only the first intersection is shown. Vec4 iPoint = intersections[0].getIntersectionPoint(); Vec4 gPoint = terrain.getSurfacePoint( gridPosition.getLatitude(), gridPosition.getLongitude(), gridPosition.getAltitude()); // Check to see whether the intersection is beyond the grid point. if (iPoint.distanceTo3(this.referencePoint) >= gPoint.distanceTo3(this.referencePoint)) { // Intersection is beyond the grid point; the line goes from the center to the grid point. this.addSightLine(this.referencePosition, gridPosition); return; } // Compute the position corresponding to the intersection. Position iPosition = this.terrain.getGlobe().computePositionFromPoint(iPoint); // The sight line goes from the user-selected position to the intersection position. this.addSightLine(this.referencePosition, new Position(iPosition, 0)); // Keep track of the intersection positions. this.addIntersectionPosition(iPosition); this.updateProgress(); }
/** * Checks whether the position is located on the playing area or the outer dots. * * @param p the position of which should be determined whether it is on the board */ public boolean isPositionOnPlayAreaOrOuterDots(Position p) { int col = p.getColName() - 'a' + 1; int row = p.getRowNumber(); // See google doc for explanation of the formula return !(row <= 0 || col >= 10 || row + col >= 15 || col - row <= -5 || col <= 0); }
public static void main1(String[] args) throws ClassNotFoundException, SQLException { OlapConnection conn = getConnection(url); CellSet cs = getResultSet(mdx, conn); // CellSetAxis c; int count = 0; if (cs.getAxes().size() > 1) { for (Position row : cs.getAxes().get(1)) { for (Position column : cs.getAxes().get(0)) { for (Member member : row.getMembers()) { System.out.println("rows:" + member.getUniqueName()); } for (Member member : column.getMembers()) { System.out.println("columns:" + member.getUniqueName()); } final Cell cell = cs.getCell(column, row); System.out.println("values:" + cell.getValue()); Position[] positions = new Position[2]; positions[0] = column; positions[1] = row; OlapCell oalpCell = new OlapCell(positions, cell.getValue()); System.out.println("****" + oalpCell.toString()); System.out.println(count++); } } } }
/** By Dingding */ private Set<Line.Segment> getRemovableLineSegments( Map<Position, Piece> pieceMap, PieceColor pieceColor) { Set<Line.Segment> removableLines = new HashSet<>(); Set<Line> linesOnTheBoard = Line.getLinesOnTheBoard( this); // Get all the possible lines on the board. Positions don't need to be occupied. for (Line line : linesOnTheBoard) { Position currentPosition = line.getStartPosition(); Position startOfSegment = null; Position endOfSegment = null; Direction direction = line.getDirection(); int consecutivePieces = 0; // We start at a dot position, so we can assume that we don't start in a set of // consecutive pieces boolean isInLineSegment = false; // Break the for-loop if an endOfSegment has been found (because the largest lines only have 7 // positions on the board, there // can't be more than one set of four pieces of the same color (requiring at least 9 // positions) on the board. for (; endOfSegment == null && isPositionOnPlayAreaOrOuterDots(currentPosition); currentPosition = currentPosition.next(direction)) { PieceColor currentPieceColor = pieceMap.containsKey(currentPosition) ? pieceMap.get(currentPosition).getPieceColor() : null; // Update the consecutivePieces if (currentPieceColor == pieceColor) consecutivePieces++; if (consecutivePieces == 4) isInLineSegment = true; if (currentPieceColor != pieceColor) consecutivePieces = 0; if (isInLineSegment) { if (isDotPosition(currentPosition) || currentPieceColor == null) { endOfSegment = currentPosition.previous(direction); } } // Update the startOfSegment if necessary if (startOfSegment == null) { if (currentPieceColor != null) { startOfSegment = currentPosition; } } if (currentPieceColor == null && endOfSegment == null) { startOfSegment = null; } // Add a line segment to the list if we have found one if (endOfSegment != null) { removableLines.add(new Line.Segment(this, startOfSegment, endOfSegment, direction)); } } } return removableLines; }
public void fillPosition(String title, Person hire) { for (Position position : this) if (position.getTitle().equals(title) && position.getPerson() == Person.NULL) { position.setPerson(hire); return; } throw new RuntimeException("Position " + title + " not available"); }
public final void setLocation(int x, int y) { if (position.x != x || position.y != y) { position.x = x; position.y = y; if (!this.isInvalid()) this.setInvalid(); } }
public Position getPositionByLabel(String label) { for (Position p : positionMap.values()) { if (p.getTitle().equals(label)) { return p; } } return null; }
public Tile getTileAt(Position p) { if (p.getRow() == 0 && p.getColumn() == 0) { return new StubTile(GameConstants.FOREST, 0, 0); } if (p.getRow() == 1 && p.getColumn() == 0) { return new StubTile(GameConstants.HILLS, 1, 0); } return new StubTile(GameConstants.PLAINS, 0, 1); }
public String getPositionsAsXML() { ArrayList<Position> pList = new ArrayList<Position>(positionMap.values()); Collections.sort(pList); StringBuilder xml = new StringBuilder("<positions>"); for (Position p : pList) xml.append(p.toXML()); xml.append("</positions>"); return xml.toString(); }
public Set<Participant> getParticipantsWithPosition(String positionName) { Set<Participant> result = null; if (positionName != null) { Position p = getPositionByLabel(positionName); if (p != null) { result = getPositionParticipants(p.getID()); } } return result; }
/** * Gets the set of Participants the ultimately report to the Position passed * * @param manager the 'manager' Position * @return the set of Particpants 'managed' by this Position */ public Set<Participant> getParticipantsReportingToPosition(Position manager) { Set<Participant> result = new HashSet<Participant>(); Set<Position> posSet = getPositions(); for (Position pos : posSet) { if (pos.ultimatelyReportsTo(manager)) { result.addAll(castToParticipantSet(pos.getResources())); } } return result; }
public String getParticipantPositionsAsXML(String pid) { Set<Position> posSet = getParticipantPositions(pid); if (posSet != null) { String header = String.format("<positions participantid=\"%s\">", pid); StringBuilder xml = new StringBuilder(header); for (Position p : posSet) xml.append(p.toXML()); xml.append("</positions>"); return xml.toString(); } else return ("<positions/>"); }
public String getParticpantsWithPositionAsXML(String positionName) { String result = "<participants/>"; if (positionName != null) { Position p = getPositionByLabel(positionName); if (p != null) { result = getPositionParticipantsAsXML(p.getID()); } } return result; }
public PositionView createPositionView(Portfolio portfolio, Integer instrumentId) { Double lastPrice = mapStockPrices.get(instrumentId); if (lastPrice == null) return null; Position position = portfolio.getPosition(instrumentId); return new PositionView( portfolio.pmId, instrumentId, position.quantity, lastPrice, position.calculateProfitLoss(lastPrice)); }
public void onSuccess(Position[] positions) { for (Position p : positions) { Logging.logger() .info( p.getLatitude().degrees + "," + p.getLongitude().degrees + " --> " + p.getElevation()); } }
public ArrayList<Position> getMoves(Position p) { String e = ask("moves:" + p.getX() + ":" + p.getY() + ";"); ArrayList<Position> m = new ArrayList<Position>(); String[] o = e.split(":"); for (int i = 0; i < o.length; i = i + 2) { m.add(new Position(Integer.parseInt(o[i]), Integer.parseInt(o[i + 1]))); } return m; }
public AStarNode createStartNode(Object state) { Position p = (Position) state; AStarNode n = new AStarNode(p); n.setDistTravelled(0); n.setApproxTotalDist(p.distance((Position) getEndingState())); List<Position> path = new ArrayList<Position>(); path.add(p); n.setPath(path); // System.out.print("createStartNode"); n.printNode(); return n; }
private void fillPointsPanel() { int i = 0; for (Position pos : lineBuilder.getLine().getPositions()) { if (i == this.pointLabels.length) break; String las = String.format("Lat %7.4f\u00B0", pos.getLatitude().getDegrees()); String los = String.format("Lon %7.4f\u00B0", pos.getLongitude().getDegrees()); pointLabels[i++].setText(las + " " + los); } for (; i < this.pointLabels.length; i++) pointLabels[i++].setText(""); }
protected static boolean isNameVisible( DrawContext dc, PlaceNameService service, Position namePosition) { double elevation = dc.getVerticalExaggeration() * namePosition.getElevation(); Vec4 namePoint = dc.getGlobe() .computePointFromPosition( namePosition.getLatitude(), namePosition.getLongitude(), elevation); Vec4 eyeVec = dc.getView().getEyePoint(); double dist = eyeVec.distanceTo3(namePoint); return dist >= service.getMinDisplayDistance() && dist <= service.getMaxDisplayDistance(); }