/** Returns a list of all the top-level areas. */ public List<Area> findTopAreas() { List<Area> tops = new ArrayList<Area>(); Area first = null; Area last = null; for (Area area : findPlugins(Area.class)) { if (area.getParent() == null) { if (area.getTool() instanceof CmsTool) { String internalName = area.getInternalName(); if ("dashboard".equals(internalName)) { first = area; } else if ("admin".equals(internalName)) { last = area; } else { tops.add(area); } } else { tops.add(area); } } } if (first != null) { tops.add(0, first); } if (last != null) { tops.add(last); } return tops; }
public static void main(String[] args) { /**/ // UNCOMMENT THIS WHEN YOU DO AREA Area[] twos = new Area[5]; for (int i = 0; i < twos.length; i++) { twos[i] = makeRandomAreaShape(); } System.out.println("Area tests:"); for (Area a : twos) { System.out.println(a); System.out.println(a.getArea()); } /**/ // UNCOMMENT THIS WHEN YOU DO VOLUME Volume[] threes = new Volume[6]; for (int i = 0; i < threes.length; i++) { threes[i] = makeRandomVolumeShape(); } System.out.println("\nVolume tests:"); for (Volume v : threes) { System.out.println(v); System.out.println(v.getVolume()); } }
@Test public void getTilesInDirection() { Set<Tile> tiles = new HashSet<>(); tiles.add(Tile.at(1, 1)); tiles.add(Tile.at(1, 2)); tiles.add(Tile.at(2, 1)); tiles.add(Tile.at(2, 2)); Area area = new Area(0, tiles); Set<Tile> result = area.tilesIn(Direction.LEFT); assertEquals(2, result.size()); assertTrue(result.contains(Tile.at(1, 1))); assertTrue(result.contains(Tile.at(1, 2))); result = area.tilesIn(Direction.DOWN); assertEquals(2, result.size()); assertTrue(result.contains(Tile.at(1, 2))); assertTrue(result.contains(Tile.at(2, 2))); result = area.tilesIn(Direction.RIGHT); assertEquals(2, result.size()); assertTrue(result.contains(Tile.at(2, 1))); assertTrue(result.contains(Tile.at(2, 2))); result = area.tilesIn(Direction.UP); assertEquals(2, result.size()); assertTrue(result.contains(Tile.at(1, 1))); assertTrue(result.contains(Tile.at(2, 1))); }
private void organize(Petal[] opts) { Area bounds = parent.area().xl(c.inv()); int l = 1, p = 0, i = 0, mp = 0, ml = 1, t = 0, tt = -1; boolean muri = false; while (i < opts.length) { place: { double ta = (PI / 2) - (p * (2 * PI / (l * ppl))); double tr = 75 + (50 * (l - 1)); if (!muri && !bounds.contains(opts[i].ta(ta, tr))) { if (tt < 0) { tt = ppl * l; t = 1; mp = p; ml = l; } else if (++t >= tt) { muri = true; p = mp; l = ml; continue; } break place; } tt = -1; opts[i].ta = ta; opts[i].tr = tr; i++; } if (++p >= (ppl * l)) { l++; p = 0; } } }
public void paint(Graphics g) { Graphics2D g_2d = (Graphics2D) g; Ellipse2D ellipse = new Ellipse2D.Double(0, 2, 80, 80); Rectangle2D rect = new Rectangle2D.Double(40, 2, 80, 80); Area a1 = new Area(ellipse); Area a2 = new Area(rect); a1.intersect(a2); // "Óë" g_2d.fill(a1); ellipse.setFrame(130, 2, 80, 80); rect.setFrame(170, 2, 80, 80); a1 = new Area(ellipse); a2 = new Area(rect); a1.add(a2); // "»ò" g_2d.draw(a1); ellipse.setFrame(0, 90, 80, 80); rect.setFrame(40, 90, 80, 80); a1 = new Area(ellipse); a2 = new Area(rect); a1.subtract(a2); // "²î" g_2d.draw(a1); ellipse.setFrame(130, 90, 80, 80); rect.setFrame(170, 90, 80, 80); a1 = new Area(ellipse); a2 = new Area(rect); a1.exclusiveOr(a2); // "Òì»ò" g_2d.fill(a1); }
public static boolean isInArea(Position position, Area area) { return position.getZ() == area.getSouthWestCorner().getZ() && position.getX() > area.getSouthWestCorner().getX() && position.getY() > area.getSouthWestCorner().getY() && position.getX() < area.getNorthEastCorner().getX() && position.getY() < area.getNorthEastCorner().getY(); }
public List<Area> getAllArea() { List<Area> areaList = new ArrayList<Area>(); con = new DBConnection(); try { cstmt = con.connection.prepareCall("{call getAllArea()}"); ResultSet rs = cstmt.executeQuery(); while (rs.next()) { Area objArea = new Area(); objArea.setAreaID(rs.getInt("AreaID")); objArea.setAreaName(rs.getString("AreaName")); City c = new City(); c.setCityName(rs.getString("CityName")); objArea.setCity(c); areaList.add(objArea); } rs.close(); } catch (Exception ex) { ex.getMessage(); } finally { con.closeConnection(); } return areaList; }
// Reports public ArrayList<Customer> getAllCustomers() { con = new DBConnection(); ArrayList<Customer> customers = new ArrayList<Customer>(); try { cstmt = con.connection.prepareCall("{call getAllCustomer()}"); ResultSet rs = cstmt.executeQuery(); while (rs.next()) { Customer objCustomer = new Customer(); Area objArea = new Area(); objCustomer.setFirstName(rs.getString("FirstName")); objCustomer.setLastName(rs.getString("LastName")); objArea.setAreaName(rs.getString("AreaName")); objCustomer.setArea(objArea); objCustomer.setUserName(rs.getString("UserName")); objCustomer.setLane(rs.getString("Lane")); objCustomer.setMobileNo(rs.getString("MobileNo")); objCustomer.setEmailID(rs.getString("EmailID")); objCustomer.setStatus(rs.getBoolean("Status")); customers.add(objCustomer); } rs.close(); } catch (Exception ex) { ex.getMessage(); } finally { con.closeConnection(); } return customers; }
@Override public boolean overlaps(Area other) { for (Area a : parts) { if (a.overlaps(other)) { return true; } } return false; }
@Override public boolean contains(Vector point) { for (Area a : parts) { if (a.contains(point)) { return true; } } return false; }
private static final Shape createMask(int width, int height) { Shape outside = new Rectangle2D.Double(0, 0, width, height); Shape inside = new RoundRectangle2D.Double(10, 10, width - 20, height - 20, 50, 50); Area area = new Area(outside); area.subtract(new Area(inside)); return area; }
/** * Creates a new area. Does NOT save the area to repository. * * @param name name of the area * @param person owner of the area * @param visibility is area visible for unauthenticated visitors * @return created Area */ public Area createArea(String name, Person person, Boolean visibility) { Area area = new Area(); area.setName(name); area.setOwner(person); area.setVisibility(visibility); area.setElements(new ArrayList<>()); return area; }
protected Area getParentArea() { int x = Name().indexOf("_"); if (x < 0) return null; if (!CMath.isNumber(Name().substring(0, x))) return null; Area parentA = CMLib.map().getArea(Name().substring(x + 1)); if ((parentA == null) || (!CMath.bset(parentA.flags(), Area.FLAG_INSTANCE_PARENT)) || (CMath.bset(parentA.flags(), Area.FLAG_INSTANCE_CHILD))) return null; return parentA; }
@Override public Pair<Vector, Float> cast(Ray ray, GL2 debug) { Pair<Vector, Float> hit = null; for (Area area : parts) { Pair<Vector, Float> tHit = area.cast(ray, debug); if (tHit != null && (hit == null || hit.b > tHit.b)) { hit = tHit; } } return hit; }
/** * Updates an Area's attributes if the currently logged in user is the owner of the Area. * * @param areaId which area will be updated * @param name areas new name * @param visibility areas new visibility * @param whoIsLogged to check who is logged in * @return true if update was successful, false if not */ public boolean updateArea(Long areaId, String name, boolean visibility, Person whoIsLogged) { Area area = findAreaById(areaId); if (whoIsLogged.getId() == area.getOwner().getId()) { area.setName(name); area.setVisibility(visibility); areaRepository.save(area); return true; } return false; }
private void drawArea(Area area, View view, Drawable drawable, Canvas canvas) { int left = area.getLeft(view, drawable); int top = area.getTop(view, drawable); int right = area.getRight(view, drawable); int bottom = area.getBottom(view, drawable); if (drawable != null) { drawable.setBounds(left, top, right, bottom); drawable.draw(canvas); } }
public Item buildMyThing(MOB mob, Room room) { Area A = room.getArea(); boolean bonusWorthy = (Druid_MyPlants.myPlant(room, mob, 0) == null); Vector V = Druid_MyPlants.myAreaPlantRooms(mob, room.getArea()); int pct = 0; if (A.getAreaIStats()[Area.Stats.VISITABLE_ROOMS.ordinal()] > 10) pct = (int) Math.round( 100.0 * CMath.div( V.size(), A.getAreaIStats()[Area.Stats.VISITABLE_ROOMS.ordinal()])); Item I = buildMyPlant(mob, room); if ((I != null) && ((mob.charStats().getCurrentClass().baseClass().equalsIgnoreCase("Druid")) || (CMSecurity.isASysOp(mob)))) { if (!CMLib.law().isACity(A)) { if (pct > 0) { int newPct = (int) Math.round( 100.0 * CMath.div( V.size(), A.getAreaIStats()[Area.Stats.VISITABLE_ROOMS.ordinal()])); if ((newPct >= 50) && (A.fetchEffect("Chant_DruidicConnection") == null)) { Ability A2 = CMClass.getAbility("Chant_DruidicConnection"); if (A2 != null) A2.invoke(mob, A, true, 0); } } } else if ((bonusWorthy) && (!mob.isMonster())) { long[] num = (long[]) plantBonuses.get(mob.Name() + "/" + room.getArea().Name()); if ((num == null) || (System.currentTimeMillis() - num[1] > (room.getArea().getTimeObj().getDaysInMonth() * room.getArea().getTimeObj().getHoursInDay() * CMProps.getMillisPerMudHour()))) { num = new long[2]; plantBonuses.remove(mob.Name() + "/" + room.getArea().Name()); plantBonuses.put(mob.Name() + "/" + room.getArea().Name(), num); num[1] = System.currentTimeMillis(); } if (V.size() >= num[0]) { num[0]++; if (num[0] < 19) { mob.tell("You have made this city greener."); CMLib.leveler().postExperience(mob, null, null, (int) num[0], false); } } } } return I; }
@Override public int compareTo(StreamName streamName) { if (streamName == null) { return -1; } Area area = getArea(kind); Area otherArea = streamName.getArea(streamName.kind); if (area != otherArea) { return -area.compareTo(otherArea); } if (column != streamName.column) { return column < streamName.column ? -1 : 1; } return kind.compareTo(streamName.kind); }
/** * Deletes an Area if the currently logged in user is the owner of the Area. * * @param areaid which area will be deleted * @param whoIsLoggedIn to check who is logged in * @return true if deletion was successful, false if not */ public boolean deleteArea(Long areaid, Person whoIsLoggedIn) { if (areaRepository.exists(areaid)) { Area area = areaRepository.findOne(areaid); if (area.getOwner().getId() == whoIsLoggedIn.getId()) { if (findAreaById(areaid).getElements().isEmpty()) { areaRepository.delete(areaid); return true; } } return false; } return false; }
private boolean checkLayering(Area b) { ArrayList<Number> id = getVisible(); Vector<Rectangle> rects = new Vector<Rectangle>(id.size()); for (Number n : id) { rects.add(getIE().get(n).toRectangle()); } Rectangle r = b.toRectangle(); int index = 0; for (Rectangle rect : rects) { if (r.equals(rect)) { index = rects.indexOf(rect) + 1; } } for (int i = index; i < rects.size(); i++) { Rectangle rect = rects.get(i); if (r.intersects(rect)) { Rectangle isect = r.intersection(rect); isect.setRect(isect.x, isect.y, isect.getWidth() + 1, isect.getHeight() + 2); if (isect.contains(mascot.getAnchor())) { return false; } } } return true; }
public int calcOffset() { if (isAbsolute()) { return _offset; } else { return _offset + _area.getOffset(); } }
/** * Moves the Robot parsing the command in String format Eg: 'MML' moves two steps ahead and turns * its Direction 90 degrees Left * * @param {@code String} the command * @return the new position of the Robot * @throws {@code IllegalArgumentException} if command is empty * @throws {@code IllegalArgumentException} if Robot reaches the boundaries of the area */ public Position move(String command) { if (command == null || "".equals(command)) { throw new IllegalArgumentException("Command must not be null or empty"); } char[] chars = command.toUpperCase().toCharArray(); Position backupCopyOfLastPosition = new Position(position.getX(), position.getY(), position.getDirection()); for (char item : chars) { switch (item) { case 'R': case 'L': position = position.turn(item); break; case 'M': if (area.canMoveFrom(position)) { position = position.move(); break; } else { position = backupCopyOfLastPosition; throw new IllegalStateException( "Cannot move, it already reached the boundaries of area"); } default: throw new IllegalArgumentException("Invalid command"); } } return position; }
/** * Saves an Area to the database. * * @param area the Area to be saved * @return true if Area was successfully saved, false otherwise */ public boolean saveArea(Area area) { if ((area != null) && (findAreaByName(area.getName()) == null)) { areaRepository.save(area); return true; } return false; }
private void paintGenome(Graphics2D g) { g.setColor(Color.WHITE); g.fillRect(0, 0, viewRect.width, viewRect.height); g.setColor(new Color(0.9f, 0.9f, 1f)); g.fill( new Ellipse2D.Double( context.getCenterX() - getRadiusInt(), context.getCenterY() - getRadiusInt(), getRadiusInt() * 2, getRadiusInt() * 2)); for (int i = 0; i < this.context.getDictionary().getSequences().size(); ++i) { SAMSequenceRecord rec = this.context.getDictionary().getSequence(i); Arc2D outer = context.getArc(rec, 0, rec.getSequenceLength(), getRadiusExt(), Arc2D.PIE); if (outer.getAngleExtent() == 0) continue; Area area = new Area(outer); Ellipse2D.Double ed = new Ellipse2D.Double( context.getCenter().getX() - getRadiusInt(), context.getCenter().getY() - getRadiusInt(), getRadiusInt() * 2, getRadiusInt() * 2); area.subtract(new Area(ed)); g.setColor(i % 2 == 0 ? Color.LIGHT_GRAY : Color.WHITE); g.fill(area); g.setColor(Color.BLACK); g.draw(area); if ((rec.getSequenceLength() / (double) this.context.getDictionary().getReferenceLength()) < 0.01) continue; String title = rec.getSequenceName(); double midangle = context.convertPositionToRadian(rec, rec.getSequenceLength() / 2); AffineTransform old = g.getTransform(); AffineTransform tr = new AffineTransform(old); g.translate(context.getCenterX(), context.getCenterY()); g.rotate(midangle); g.translate(getRadiusExt(), 0); g.drawString(title, 0, 0); g.setTransform(tr); g.setTransform(old); } }
/* * (non-Javadoc) * * @see javax.swing.Icon#paintIcon(java.awt.Component, java.awt.Graphics, * int, int) */ @Override public void paintIcon(Component c, Graphics g, int x, int y) { Graphics2D g2d = (Graphics2D) g.create(); g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2d.translate(x, y); Area clip = new Area(new Rectangle(0, 0, this.width, this.height)); if (g2d.getClip() != null) clip.intersect(new Area(g2d.getClip())); g2d.setClip(clip); double coef1 = (double) this.width / (double) getOrigWidth(); double coef2 = (double) this.height / (double) getOrigHeight(); double coef = Math.min(coef1, coef2); g2d.scale(coef, coef); paint(g2d); g2d.dispose(); }
public Room getRoom(String roomID) { if (!CMath.bset(flags(), Area.FLAG_INSTANCE_CHILD)) return super.getRoom(roomID); if (!isRoom(roomID)) return null; Room R = super.getRoom(roomID); if (((R == null) || (R.amDestroyed())) && (roomID != null)) { Area parentA = getParentArea(); if (parentA == null) return null; if (roomID.toUpperCase().startsWith(Name().toUpperCase() + "#")) roomID = Name() + roomID.substring(Name().length()); // for case sensitive situations R = parentA.getRoom(parentA.Name() + getStrippedRoomID(roomID)); if (R == null) return null; Room origRoom = R; R = (Room) R.copyOf(); R.clearSky(); if (R instanceof GridLocale) ((GridLocale) R).clearGrid(null); for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) R.rawDoors()[d] = null; R.setRoomID(roomID); R.setArea(this); addProperRoom(R); synchronized (("SYNC" + roomID).intern()) { for (int d = Directions.NUM_DIRECTIONS() - 1; d >= 0; d--) { Room dirR = origRoom.rawDoors()[d]; if (dirR != null) { String myRID = dirR.roomID(); if (dirR.getArea() == parentA) { String localDirRID = convertToMyArea(myRID); Room localDirR = getProperRoom(localDirRID); if (localDirR != null) R.rawDoors()[d] = localDirR; else { R.rawDoors()[d] = CMClass.getLocale("ThinRoom"); R.rawDoors()[d].setRoomID(localDirRID); R.rawDoors()[d].setArea(this); } } else R.rawDoors()[d] = dirR; } } } fillInAreaRoom(R); R.setExpirationDate(System.currentTimeMillis() + WorldMap.ROOM_EXPIRATION_MILLIS); } return R; }
@Override public boolean tick(Tickable ticking, int tickID) { super.tick(ticking, tickID); if (anyWetWeather(lastWeather)) { if (ticking instanceof Room) { final Room R = (Room) ticking; final Area A = R.getArea(); if ((!anyWetWeather(A.getClimateObj().weatherType(R))) && (!dryWeather(A.getClimateObj().weatherType(R))) && (CMLib.dice().rollPercentage() < pct())) makePuddle(R, lastWeather, A.getClimateObj().weatherType(R)); } else if (ticking instanceof Area) { final Area A = (Area) ticking; if ((!anyWetWeather(A.getClimateObj().weatherType(null))) && (!dryWeather(A.getClimateObj().weatherType(null)))) { for (final Enumeration<Room> e = A.getProperMap(); e.hasMoreElements(); ) { final Room R = e.nextElement(); if (((R.domainType() & Room.INDOORS) == 0) && (R.domainType() != Room.DOMAIN_OUTDOORS_AIR) && (!CMLib.flags().isWateryRoom(R)) && (CMLib.dice().rollPercentage() < pct())) makePuddle(R, lastWeather, A.getClimateObj().weatherType(null)); } } } } if (ticking instanceof Room) lastWeather = ((Room) ticking).getArea().getClimateObj().weatherType((Room) ticking); else if (ticking instanceof Area) lastWeather = ((Area) ticking).getClimateObj().weatherType(null); return true; }
public ArrayList<Area> getAllCityArea(int cityid) { con = new DBConnection(); try { cstmt = con.connection.prepareCall("{call getAreaCityID(?)}"); cstmt.setInt(1, cityid); ArrayList<Area> areas = new ArrayList<Area>(); ResultSet rs = cstmt.executeQuery(); while (rs.next()) { Area objArea = new Area(); objArea.setAreaID(rs.getInt("AreaID")); objArea.setAreaName(rs.getString("AreaName")); areas.add(objArea); } return areas; } catch (SQLException ex) { return null; } }
public NewPolygon2D clip(Rectangle2D boundingBox) { Area thisArea = new Area(path); thisArea.intersect(new Area(boundingBox)); PathIterator iterator = thisArea.getPathIterator(null); double[] v = new double[2]; while (!iterator.isDone()) { int type = iterator.currentSegment(v); System.err.println(":" + v[0] + v[1] + "\n"); iterator.next(); } System.exit(-1); GeneralPath path = new GeneralPath(thisArea); path.closePath(); NewPolygon2D newPolygon = new NewPolygon2D(path); newPolygon.setFillValue(this.getFillValue()); return newPolygon; }
@Override public void repaint(Graphics g) { if (tiles.size() >= 2) { g.setColor(new Color(255, 255, 255, 255)); Tile[] t = new Tile[tiles.size()]; tiles.toArray(t); Area a = new Area(t); for (int i = 0; i < a.getPolygon().npoints; i++) { Point p = new Point( tiles.get(i).matrix(ctx).bounds().xpoints[0], tiles.get(i).matrix(ctx).bounds().ypoints[0]); Point pp; if (i == a.getPolygon().npoints - 1) pp = new Point( tiles.get(0).matrix(ctx).bounds().xpoints[0], tiles.get(0).matrix(ctx).bounds().ypoints[0]); else pp = new Point( tiles.get(i + 1).matrix(ctx).bounds().xpoints[0], tiles.get(i + 1).matrix(ctx).bounds().ypoints[0]); g.drawLine(p.x, p.y, pp.x, pp.y); } g.drawPolygon(a.getPolygon()); if (a.contains(ctx.players.local())) { g.setColor(new Color(0, 255, 0, 100)); } else { g.setColor(new Color(255, 0, 0, 100)); } g.fillPolygon(ctx.players.local().tile().matrix(ctx).bounds()); } else { g.setColor(new Color(255, 0, 0, 100)); g.fillPolygon(ctx.players.local().tile().matrix(ctx).bounds()); } for (int i = 0; i < tiles.size(); i++) { if (i == gui.tileList.getSelectedIndex()) g.setColor(Color.yellow); else g.setColor(new Color(0, 0, 255, 150)); g.fillPolygon(tiles.get(i).matrix(ctx).bounds()); } }