using System; using System.Collections.Generic; using System.Drawing; using System.Linq; using System.Text; using System.Threading.Tasks; namespace OTSMeasureApp._0_OTSModel.OTSDataType { class COTSRect { private float m_left; private float m_top; private float m_right; private float m_bottom; public COTSRect() { m_left = 0; m_top = 0; m_right = 0; m_bottom = 0; } public COTSRect(int left, int top, int right, int bottom) { m_left = left; m_top = top; m_right = right; m_bottom = bottom; } COTSRect(PointF leftTop, PointF bottomRight) { m_left = leftTop.X; m_top = leftTop.Y; m_right = bottomRight.X; m_bottom = bottomRight.Y; } void SetRectData(int left, int top, int right, int bottom) { m_left = left; m_top = top; m_right = right; m_bottom = bottom; } bool PointInRect(PointF p) { if (p.X > m_left && p.X < m_right && p.X > m_bottom && p.X < m_top) { return true; } else { return false; } } PointF GetTopLeft() { return new PointF(m_left, m_top); } PointF GetBottomRight() { return new PointF(m_right, m_bottom); } float GetWidth() { return (m_right - m_left); } float GetHeight() { return (m_top - m_bottom); } PointF GetCenterPoint() { double w = GetWidth(); double h = GetHeight(); PointF lt = GetTopLeft(); return new PointF((float)(lt.X + w / 2), (float)(lt.Y - h / 2)); } bool IntersectOtherRect(COTSRect r) { PointF leftTop = r.GetTopLeft(); PointF rightBottom = r.GetBottomRight(); PointF rightTop =new PointF(rightBottom.X, leftTop.Y); PointF leftBottom =new PointF(leftTop.X, rightBottom.Y); if (PointInRect(leftTop)) { return true; } else if (PointInRect(rightBottom)) { return true; } else if (PointInRect(rightTop)) { return true; } else if (PointInRect(leftBottom)) { return true; } else if (r.PointInRect(new PointF(m_left, m_top)) || r.PointInRect(new PointF(m_right, m_bottom))) { return true; } else { return false; } } } }