00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019 #include "utils.h"
00020
00021
00022
00024
00025 int rectangle::isIntersect(const rectangle & r2) const
00026 {
00027 if ((r2.left > right || r2.right < left ||
00028 r2.top > bottom || r2.bottom < top ))
00029 {
00030 return 0;
00031 }
00032
00033 int width = min(right, r2.right) - max(left, r2.left);
00034 int height = min(bottom, r2.bottom) - max(top, r2.top);
00035 return width * height;
00036 }
00037
00039
00040 int rectangle::isVerInter(const rectangle & r2) const
00041 {
00042 if (r2.top > bottom || r2.bottom < top)
00043 {
00044 return 0;
00045 }
00046 int height = min(bottom, r2.bottom) - max(top, r2.top);
00047 return height;
00048 }
00049
00051
00052 int rectangle::ivHorInter(const rectangle & r2) const
00053 {
00054 if (r2.left > right || r2.right < left)
00055 {
00056 return 0;
00057 }
00058 int width = min(right, r2.right) - max(left, r2.left);
00059 return width;
00060 }
00061
00062 void rectangle::normalize()
00063 {
00064 if (left > right) { swap(left, right);}
00065 if (top > bottom) { swap(top, bottom);}
00066 }
00067
00068 GBool rectangle::hitTest(const point & pt) const
00069 {
00070 return (left <= pt.x && right >= pt.x &&
00071 top <= pt.y && bottom >= pt.y);
00072 }
00073
00074 GBool rectangle::hitTest(const int x, const int y) const
00075 {
00076 return (left <= x && right >= x &&
00077 top <= y && bottom >= y);
00078 }
00079