判断两个矩阵是否相交

//Write a function to check if two rectangles defined as below, have common area or not. The functions take the top left and bottom   right coordinate as input and return 1 if they have common area, otherwise return 0.
struct Point {
  int x;
  int y;
};

struct Rec {
  Point l_top;
  Point r_bot;
};

bool CheckHasCommenRange(Rec& rec_a, Rec& rec_b) {
  if (rec_a.l_top.x > rec_b.l_top.x) swap(rec_a, rec_b);
  if (rec_b.l_top.x >= rec_a.r_bot.x) return false;
  if (rec_a.r_bot.y > rec_b.r_bot.y) swap(rec_a, rec_b);
  if (rec_b.r_bot.y >= rec_a.r_bot.y) return false;
  return true;
}

 

posted @ 2013-09-15 22:58  dmthinker  阅读(1199)  评论(0)    收藏  举报