List of usage examples for java.awt.geom Area contains
public boolean contains(Rectangle2D r)
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0); Ellipse2D e2 = new Ellipse2D.Double(20.0, 70.0, 40.0, 40.0); Area a1 = new Area(e1); Area a2 = new Area(e2); a1.subtract(a2);//from w w w . java 2 s .co m g2.setColor(Color.orange); g2.fill(a1); g2.setColor(Color.black); g2.drawString("subtract", 20, 140); System.out.println(a1.contains(new Point(50, 50))); }
From source file:Main.java
public void paint(Graphics g) { Graphics2D g2 = (Graphics2D) g; Ellipse2D e1 = new Ellipse2D.Double(20.0, 20.0, 80.0, 70.0); Ellipse2D e2 = new Ellipse2D.Double(20.0, 70.0, 40.0, 40.0); Area a1 = new Area(e1); Area a2 = new Area(e2); a1.subtract(a2);//from w ww . j a v a 2 s . c o m g2.setColor(Color.orange); g2.fill(a1); g2.setColor(Color.black); g2.drawString("subtract", 20, 140); System.out.println(a1.contains(new Rectangle(50, 50, 5, 5))); }
From source file:com.t3.macro.api.views.TokenView.java
/** * Returns a set of the parts of a token that can be seen by this token. * @param target the token of which we want to check what this token can see * @return the set of visible token parts *///from w ww . j a v a 2s . c o m public EnumSet<TokenPart> getVisibleTokenParts(TokenView target) { if (!token.getHasSight()) return EnumSet.noneOf(TokenPart.class); ZoneRenderer zr = TabletopTool.getFrame().getZoneRenderer(token.getZone()); Zone zone = zr.getZone(); Area tokensVisibleArea = zr.getZoneView().getVisibleArea(token); if (tokensVisibleArea == null) return EnumSet.noneOf(TokenPart.class); if (target == null) throw new NullPointerException(); if (!target.isVisible() || (target.token.isVisibleOnlyToOwner() && !AppUtil.playerOwns(target.token))) { return EnumSet.noneOf(TokenPart.class); } Grid grid = zone.getGrid(); Rectangle bounds = target.token.getFootprint(grid).getBounds(grid, grid.convert(new ZonePoint(target.token.getX(), target.token.getY()))); if (!target.token.isSnapToGrid()) bounds = target.token.getBounds(zone); EnumSet<TokenPart> ret = EnumSet.noneOf(TokenPart.class); int x = (int) bounds.getX(); int y = (int) bounds.getY(); int w = (int) bounds.getWidth(); int h = (int) bounds.getHeight(); int halfX = x + (w) / 2; int halfY = y + (h) / 2; if (tokensVisibleArea.intersects(bounds)) { if (tokensVisibleArea.contains(new Point(x, y))) ret.add(TokenPart.TOP_LEFT); if (tokensVisibleArea.contains(new Point(x, y + h))) if (tokensVisibleArea.contains(new Point(x + w, y))) ret.add(TokenPart.TOP_RIGHT); if (tokensVisibleArea.contains(new Point(x + w, y + h))) ret.add(TokenPart.BOTTOM_LEFT); if (tokensVisibleArea.contains(new Point(halfX, halfY))) ret.add(TokenPart.BOTTOM_RIGHT); } return ret; }