Check if two rectangle intersect - Node.js Geometry

Node.js examples for Geometry:Rectangle

Description

Check if two rectangle intersect

Demo Code


utils.intersect = function(bounds1, bounds2) {
  if (bounds1.end_x < bounds2.start_x) {
      return true;
  }//  w  w w  .j a va 2  s  .c  o  m
  if (bounds2.end_x < bounds1.start_x) {
      return true;
  }
  if (bounds1.end_y < bounds2.start_y) {
      return true;
  }
  if (bounds2.end_y < bounds1.start_y) {
      return true;
  }
  return false;
};

Related Tutorials