Java Rectangle Intersect intersectsOutline(Rectangle2D r, Shape s)

Here you can find the source of intersectsOutline(Rectangle2D r, Shape s)

Description

Return true if the outline of the given shape intersects with the given rectangle.

License

Open Source License

Declaration

public static boolean intersectsOutline(Rectangle2D r, Shape s) 

Method Source Code

//package com.java2s;

import java.awt.Shape;

import java.awt.geom.PathIterator;
import java.awt.geom.Rectangle2D;

public class Main {
    /** Return true if the outline of the given shape intersects with the
     *  given rectangle.//  ww w  . j a  va2 s . c o  m
     */
    public static boolean intersectsOutline(Rectangle2D r, Shape s) {
        PathIterator i = s.getPathIterator(null, .01);
        double points[] = new double[6];
        double lastX = 0, lastY = 0;
        double firstX = 0, firstY = 0;
        while (!i.isDone()) {
            int type = i.currentSegment(points);
            if (type == PathIterator.SEG_MOVETO) {
                firstX = points[0];
                firstY = points[1];
            } else if (type == PathIterator.SEG_LINETO) {
                if (r.intersectsLine(lastX, lastY, points[0], points[1]))
                    return true;
            } else if (type == PathIterator.SEG_CLOSE) {
                if (r.intersectsLine(lastX, lastY, firstX, firstY))
                    return true;
            }
            lastX = points[0];
            lastY = points[1];
            i.next();
        }
        return false;
    }
}

Related

  1. intersects(Point p1, Point p2, Rectangle rect)
  2. intersects(Rectangle aRectangle, Line2D aLine)
  3. intersects(Rectangle rect1, Rectangle rect2, boolean vertical)
  4. intersects(Rectangle2D r, Object o)
  5. intersects(Rectangle2D rect1, Rectangle2D rect2)
  6. intersectsRectangle(final double checkMinX, final double checkMinY, final double checkMaxX, final double checkMaxY, final double againstMinX, final double againstMinY, final double againstMaxX, final double againstMaxY)
  7. intersectsRectangle(final double checkMinX, final double checkMinY, final double checkMaxX, final double checkMaxY, final double againstMinX, final double againstMinY, final double againstMaxX, final double againstMaxY)