1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18
| static boolean intersecte(Rectangle R1, Rectangle R2) {
/*Quand le rectangle est entièrement inclus dans l'autre rectangle*/
boolean rectToutInclus = ((contientPoint(R1, R2.x, R2.y)
&& contientPoint(R1, R2.x+R2.longueur, R2.y)
&& contientPoint(R1, R2.x, R2.y+R2.hauteur)
&& contientPoint(R1, R2.x+R2.longueur, R2.y+R2.hauteur)));
/*ou quand le rectangle est entièrement exlus de l'autre rectangle*/
boolean rectToutExclu = ((!contientPoint(R1, R2.x, R2.y)
&& !contientPoint(R1, R2.x+R2.longueur, R2.y)
&& !contientPoint(R1, R2.x, R2.y+R2.hauteur)
&& !contientPoint(R1, R2.x+R2.longueur, R2.y+R2.hauteur)));
/*inter est faux donc pour tous les autres cas, les deux rectangles s'intersectent*/
return (!(rectToutInclus || rectToutExclu));
} |
Partager