OTSRect.cpp 1.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394959697
  1. #include "stdafx.h"
  2. #include "OTSRect.h"
  3. OTSDATA::COTSRect::COTSRect()
  4. {
  5. m_left = 0;
  6. m_top = 0;
  7. m_right = 0;
  8. m_bottom = 0;
  9. }
  10. OTSDATA::COTSRect::COTSRect(int left, int top, int right, int bottom)
  11. {
  12. m_left = left;
  13. m_top = top;
  14. m_right = right;
  15. m_bottom = bottom;
  16. }
  17. OTSDATA::COTSRect::COTSRect(CPoint leftTop, CPoint bottomRight)
  18. {
  19. m_left = leftTop.x;
  20. m_top = leftTop.y;
  21. m_right = bottomRight.x;
  22. m_bottom = bottomRight.y;
  23. }
  24. BOOL OTSDATA::COTSRect::operator==(const COTSRect& a_oSource) // ==operator
  25. {
  26. // return FASLE, if the two segments list are in different size
  27. return (m_left == a_oSource.m_left &&
  28. m_top == a_oSource.m_top &&
  29. m_right == a_oSource.m_right &&
  30. m_bottom == a_oSource.m_bottom);
  31. }
  32. void OTSDATA::COTSRect::SetRectData(int left, int top, int right, int bottom)
  33. {
  34. m_left = left;
  35. m_top = top;
  36. m_right = right;
  37. m_bottom = bottom;
  38. }
  39. bool OTSDATA::COTSRect::PointInRect(CPoint p)
  40. {
  41. if (p.x > m_left && p.x<m_right && p.y>m_bottom && p.y < m_top)
  42. {
  43. return true;
  44. }
  45. else
  46. {
  47. return false;
  48. }
  49. }
  50. bool OTSDATA::COTSRect::IntersectOtherRect(COTSRect r)
  51. {
  52. CPoint leftTop = r.GetTopLeft();
  53. CPoint rightBottom = r.GetBottomRight();
  54. CPoint rightTop = CPoint(rightBottom.x, leftTop.y);
  55. CPoint leftBottom = CPoint(leftTop.x, rightBottom.y);
  56. if (PointInRect(leftTop))
  57. {
  58. return true;
  59. }
  60. else if (PointInRect(rightBottom))
  61. {
  62. return true;
  63. }
  64. else if (PointInRect(rightTop))
  65. {
  66. return true;
  67. }
  68. else if (PointInRect(leftBottom))
  69. {
  70. return true;
  71. }
  72. else if (r.PointInRect(CPoint(m_left, m_top)) || r.PointInRect(CPoint(m_right, m_bottom)))
  73. {
  74. return true;
  75. }
  76. else
  77. {
  78. return false;
  79. }
  80. }
  81. OTSDATA::COTSRect::~COTSRect()
  82. {
  83. }