Example usage for java.awt.geom Rectangle2D intersects

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

Introduction

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

Prototype

public boolean intersects(double x, double y, double w, double h) 

Source Link

Usage

From source file:org.kalypsodeegree_impl.model.geometry.GM_Envelope_Impl.java

/**
 * returns a new GM_Envelope object representing the intersection of this GM_Envelope with the specified GM_Envelope.
 * * Note: If there is no intersection at all GM_Envelope will be null.
 * //from ww  w .  ja va 2 s  .  com
 * @param bb
 *          the GM_Envelope to be intersected with this GM_Envelope
 * @return the largest GM_Envelope contained in both the specified GM_Envelope and in this GM_Envelope.
 */
@Override
public GM_Envelope createIntersection(final GM_Envelope bb) {
    Rectangle2D rect = new Rectangle2D.Double(bb.getMin().getX(), bb.getMin().getY(), bb.getWidth(),
            bb.getHeight());
    final Rectangle2D rect2 = new Rectangle2D.Double(getMin().getX(), getMin().getY(), getWidth(), getHeight());

    if (rect2.intersects(bb.getMin().getX(), bb.getMin().getY(), bb.getWidth(), bb.getHeight())) {
        rect = rect.createIntersection(rect2);
    } else {
        rect = null;
    }

    if (rect == null) {
        return null;
    }

    final double xmin = rect.getX();
    final double ymin = rect.getY();
    final double xmax = rect.getX() + rect.getWidth();
    final double ymax = rect.getY() + rect.getHeight();

    // TODO Check coordinate systems, if equal.
    return new GM_Envelope_Impl(xmin, ymin, xmax, ymax, m_coordinateSystem);
}