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