Java Rectangle Intersect intersects(double oldx, double oldy, double oldwidth, double oldheight, double oldx2, double oldy2, double oldwidth2, double oldheight2)

Here you can find the source of intersects(double oldx, double oldy, double oldwidth, double oldheight, double oldx2, double oldy2, double oldwidth2, double oldheight2)

Description

intersects

License

Open Source License

Declaration

public static boolean intersects(double oldx, double oldy, double oldwidth, double oldheight, double oldx2,
            double oldy2, double oldwidth2, double oldheight2) 

Method Source Code

//package com.java2s;
//License from project: Open Source License 

public class Main {
    public static boolean intersects(double oldx, double oldy, double oldwidth, double oldheight, double oldx2,
            double oldy2, double oldwidth2, double oldheight2) {

        double x, y, width, height, x2, y2, width2, height2;

        x = oldx;/*from   w  ww .java  2s . co  m*/
        y = oldy;
        width = oldwidth;
        height = oldheight;
        if (oldwidth < 0) {
            width = oldx + oldwidth;
            x -= Math.abs(oldwidth);
        }
        if (oldheight < 0) {
            height = oldy + oldheight;
            y -= Math.abs(oldheight);
        }
        x2 = oldx2;
        y2 = oldy2;
        width2 = oldwidth2;
        height2 = oldheight2;
        if (oldwidth2 < 0) {
            width2 = oldx2 + oldwidth2;
            x2 -= Math.abs(oldwidth2);
        }
        if (oldheight2 < 0) {
            height2 = oldy2 + oldheight2;
            y -= Math.abs(oldheight2);
        }

        // System.out.print(x + ", " + y + ":" + width + ", " + height + " = ");
        // System.out.println(x2 + ", " + y2 + ":" + width2 + ", " + height2);

        if ((x > (x2 + width2))) {
            // System.out.println("x > ");
            return false;
        }
        if (((x + width) < x2)) {
            // System.out.println("x2 >");
            return false;
        }

        if ((y > (y2 + height2))) {
            // System.out.println("y >");
            return false;
        }
        if (((y + height) < y2)) {
            // System.out.println("y2 >");
            return false;
        }

        return true;
    }
}

Related

  1. intersect(Rectangle rect1, Rectangle rect2)
  2. intersection(Line2D.Double line, Rectangle2D.Double bounds)
  3. intersection(Rectangle r1, Rectangle r2, Rectangle out)
  4. intersection(Rectangle rectangle, Rectangle rectangle1, Rectangle rectangle2)
  5. intersectRect(double x1, double y1, double w1, double h1, double x2, double y2, double w2, double h2)
  6. intersects(double x1, double y1, double x2, double y2, double x3, double y3, double x4, double y4)
  7. intersects(final float x, final float y, final float z, final int sx, final int sy, final int sz)
  8. intersects(final Rectangle elementRect, final Rectangle viewportRect)
  9. intersects(final Rectangle2D a, final Rectangle2D b)