Here you can find the source of intersects(int x0, int y0, int w0, int h0, int x, int y, int w, int h)
Parameter | Description |
---|---|
x0 | the first point x, top left |
y0 | the first point y, top left |
w0 | the first rec width |
h0 | the first rec height |
x | the second point x, top left |
y | the second point y, top left |
w | h the second rec width |
h | the second rec height |
public static boolean intersects(int x0, int y0, int w0, int h0, int x, int y, int w, int h)
//package com.java2s; //License from project: Open Source License public class Main { /**//from ww w .ja v a 2 s. c o m * Test to see if two rectangles intersect * @param x0 the first point x, top left * @param y0 the first point y, top left * @param w0 the first rec width * @param h0 the first rec height * @param x the second point x, top left * @param y the second point y, top left * @param w h the second rec width * @param h the second rec height * @return true if rectangles intersect */ public static boolean intersects(int x0, int y0, int w0, int h0, int x, int y, int w, int h) { if (w0 <= 0 || h0 <= 0 || w <= 0 || h <= 0) { return false; } return (x + w > x0 && y + h > y0 && x < x0 + w0 && y < y0 + h0); } }