Example usage for java.awt Shape contains

List of usage examples for java.awt Shape contains

Introduction

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

Prototype

public boolean contains(double x, double y, double w, double h);

Source Link

Document

Tests if the interior of the Shape entirely contains the specified rectangular area.

Usage

From source file:Main.java

public static void main(String[] args) throws Exception {
    Shape s = new Rectangle2D.Double(0, 0, 72, 72);

    System.out.println(s.contains(30, 40, 40, 40));
}

From source file:VASSAL.counters.Labeler.java

/**
 * Return the Shape of the counter by adding the shape of this label to the shape of all inner traits.
 * Minimize generation of new Area objects.
 *///from  www .jav  a  2s.c o  m
public Shape getShape() {
    Shape innerShape = piece.getShape();

    // If the label has a Control key, then the image of the label is NOT included in the selectable area of the
    // counter
    if (!labelKey.isNull()) {
        return innerShape;
    } else {
        final Rectangle r = new Rectangle(getLabelPosition(), imagePainter.getImageSize());

        // If the label is completely enclosed in the current counter shape, then we can just return
        // the current shape
        if (innerShape.contains(r.x, r.y, r.width, r.height)) {
            return innerShape;
        } else {
            final Area a = new Area(innerShape);

            // Cache the Area object generated. Only recreate if the label position or size has changed
            if (!r.equals(lastRect)) {
                lastShape = new Area(r);
                lastRect = new Rectangle(r);
            }
            a.add(lastShape);
            return a;
        }
    }
}