Example usage for java.awt.geom Area intersects

List of usage examples for java.awt.geom Area intersects

Introduction

In this page you can find the example usage for java.awt.geom Area intersects.

Prototype

public boolean intersects(Rectangle2D r) 

Source Link

Usage

From source file:Main.java

public static void main(String[] args) {
    Area shape = new Area(new Rectangle(1, 1, 1, 1));
    shape.add(new Area(new Rectangle(1, 1, 1, 1)));
    shape.subtract(new Area(new Rectangle(1, 1, 1, 1)));
    shape.intersect(new Area(new Rectangle(1, 1, 1, 1)));
    shape.exclusiveOr(new Area(new Rectangle(1, 1, 1, 1)));

    System.out.println(shape.intersects(new Rectangle(1, 1, 1, 1)));
}

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.intersects(new Rectangle(20, 20, 300, 300));

    g2.setColor(Color.orange);//w  ww.  j a v  a  2 s .  co m
    g2.fill(a1);

    g2.setColor(Color.black);
    g2.drawString("intersect", 20, 140);
}

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
 */// ww  w  . j  av a2 s . c om
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;
}

From source file:org.opensha.commons.geo.GriddedRegion.java

private List<Integer> indexLookupSlow(Rectangle2D rect) {
    //      System.out.println("Sloooooooow");
    List<Integer> indices = Lists.newArrayList();
    for (int i = 0; i < nodeCount; i++) {
        Area area = areaForIndex(i);
        if (area.intersects(rect))
            indices.add(i);/*ww w .  j  a va  2s .c  o  m*/
    }
    return indices;
}