Example usage for java.awt.geom GeneralPath contains

List of usage examples for java.awt.geom GeneralPath contains

Introduction

In this page you can find the example usage for java.awt.geom GeneralPath contains.

Prototype

public static boolean contains(PathIterator pi, Point2D p) 

Source Link

Document

Tests if the specified Point2D is inside the closed boundary of the specified PathIterator .

Usage

From source file:com.gargoylesoftware.htmlunit.html.HtmlArea.java

/**
 * Indicates if this area contains the specified point.
 * @param x the x coordinate of the point
 * @param y the y coordinate of the point
 * @return {@code true} if the point is contained in this area
 *//*from w w  w .j ava 2  s  . c om*/
boolean containsPoint(final int x, final int y) {
    final String shape = StringUtils.defaultIfEmpty(getShapeAttribute(), "rect").toLowerCase(Locale.ROOT);

    if ("default".equals(shape) && getCoordsAttribute() != null) {
        return true;
    }

    if ("rect".equals(shape) && getCoordsAttribute() != null) {
        final Rectangle2D rectangle = parseRect();
        return rectangle.contains(x, y);
    }

    if ("circle".equals(shape) && getCoordsAttribute() != null) {
        final Ellipse2D ellipse = parseCircle();
        return ellipse.contains(x, y);
    }

    if ("poly".equals(shape) && getCoordsAttribute() != null) {
        final GeneralPath path = parsePoly();
        return path.contains(x, y);
    }

    return false;
}

From source file:com.cburch.draw.shapes.Poly.java

@Override
public final boolean contains(Location loc, boolean assumeFilled) {
    Object type = getPaintType();
    if (assumeFilled && type == DrawAttr.PAINT_STROKE) {
        type = DrawAttr.PAINT_STROKE_FILL;
    }/*from  w ww  . j  a  v a 2  s .c om*/
    if (type == DrawAttr.PAINT_STROKE) {
        int thresh = Math.max(Line.ON_LINE_THRESH, getStrokeWidth() / 2);
        PolyUtil.ClosestResult result = PolyUtil.getClosestPoint(loc, closed, handles);
        return result.getDistanceSq() < thresh * thresh;
    } else if (type == DrawAttr.PAINT_FILL) {
        GeneralPath path = getPath();
        return path.contains(loc.getX(), loc.getY());
    } else { // fill and stroke
        GeneralPath path = getPath();
        if (path.contains(loc.getX(), loc.getY()))
            return true;
        int width = getStrokeWidth();
        PolyUtil.ClosestResult result = PolyUtil.getClosestPoint(loc, closed, handles);
        return result.getDistanceSq() < (width * width) / 4;
    }
}