A excepción de mi Rect de clase:¿Forma más rápida de revisar rectángulos intersecados?
public class Rect {
public int x;
public int y;
public int w;
public int h;
public Rect(int x, int y, int w, int h) {
this.x = x;
this.y = y;
this.w = w;
this.h = h;
}
...
}
que tienen un método para comprobar si dos intersecciones rectas (sin doble sentido): caso
public boolean intersect(Rect r) {
return (((r.x >= this.x) && (r.x < (this.x + this.w))) || ((this.x >= r.x) && (this.x < (r.x + r.w)))) &&
(((r.y >= this.y) && (r.y < (this.y + this.h))) || ((this.y >= r.y) && (this.y < (r.y + r.h))));
}
prueba:
r1 = (x, y, w, h) = (0, 0, 15, 20) center: (x, y) = (7, 10)
r2 = (x, y, w, h) = (10, 11, 42, 15) center: (x, y) = (31, 18)
r1 Intersect r2: true
El la clase funciona bien
Lo que me pregunto es si hay otra forma, quizás más rápida, de comprobar si los rectángulos se cruzan. ¿Puedo optimizarlo de alguna manera?