Here you can find the source of intersects(double oldx, double oldy, double oldwidth, double oldheight, double oldx2, double oldy2, double oldwidth2, double oldheight2)
public static boolean intersects(double oldx, double oldy, double oldwidth, double oldheight, double oldx2, double oldy2, double oldwidth2, double oldheight2)
//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; } }