Ejemplo n.º 1
0
 public boolean collidesWith(Rectangle r) {
   if (r.getX() + r.getWidth() < getX()) {
     return false;
   }
   if (r.getY() + r.getHeight() < getY()) {
     return false;
   }
   if (r.getX() > getX() + getWidth()) {
     return false;
   }
   if (r.getY() > getY() + getHeight()) {
     return false;
   }
   return true;
 }
Ejemplo n.º 2
0
 /** Test for overlap of projection of one vector on to anoter */
 boolean testoverlap(double rx, double rz, double sx, double sz, Rectangle r) {
   double rmin_dot_s0 = Double.MAX_VALUE;
   double rmax_dot_s0 = Double.MIN_VALUE;
   /* Project each point from rectangle on to vector: find lowest and highest */
   for (int i = 0; i < 4; i++) {
     double r_x = r.getX(i) - rx; /* Get relative positon of second vector start to origin */
     double r_z = r.getZ(i) - rz;
     double r_dot_s0 = r_x * sx + r_z * sz; /* Projection of start of vector */
     if (r_dot_s0 < rmin_dot_s0) rmin_dot_s0 = r_dot_s0;
     if (r_dot_s0 > rmax_dot_s0) rmax_dot_s0 = r_dot_s0;
   }
   /* Compute dot products */
   double s0_dot_s0 = sx * sx + sz * sz; /* End of our side */
   if ((rmax_dot_s0 < 0.0) || (rmin_dot_s0 > s0_dot_s0)) return false;
   else return true;
 }