Example usage for java.awt Polygon intersects

List of usage examples for java.awt Polygon intersects

Introduction

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

Prototype

public boolean intersects(Rectangle2D r) 

Source Link

Usage

From source file:orchestration.path.RectShape.java

@Override
public boolean collidesWith(PlannerShape shape) {
    Polygon otherPoly = shape.getPolygon();

    // quick collision check
    if (!otherPoly.intersects(poly.getBounds()))
        return false;

    // check all line segments for intersection
    for (int i = 0; i < poly.npoints; i++) {
        Vector3D p = createPoint(poly.xpoints[i], poly.ypoints[i]);
        Vector3D r = createLine(p, poly.xpoints[(i + i) % poly.npoints], poly.xpoints[(i + i) % poly.npoints]);

        for (int j = 0; j < otherPoly.npoints; j++) {
            Vector3D q = createPoint(otherPoly.xpoints[i], otherPoly.ypoints[i]);
            Vector3D s = createLine(q, otherPoly.xpoints[(i + i) % otherPoly.npoints],
                    otherPoly.xpoints[(i + i) % otherPoly.npoints]);

            if (testIntersection(p, r, q, s))
                return true;
        }/*from w w w. j  a  v  a2  s  . c o  m*/
    }

    // check if one polygon completely contains the other
    if (otherPoly.contains(poly.xpoints[0], poly.ypoints[0]))
        return true;
    else if (poly.contains(otherPoly.xpoints[0], otherPoly.ypoints[0]))
        return true;

    return false;
}