using System; using System.Collections.Generic; using System.Linq; using System.Text; using System.Threading.Tasks; namespace RichCreator.Utility.Structs { /// /// 方框 /// public struct ZTRectangle:IEquatable { public static ZTRectangle Empty = new ZTRectangle(0, 0, 0, 0); public ZTRectangle(Int32 startX, Int32 startY, Int32 endX, Int32 endY) { this.Start = new ZTPoint(startX, startY); this.End = new ZTPoint(endX, endY); } /// /// 左上角点 /// public ZTPoint Start; /// /// 右下角点 /// public ZTPoint End; /// /// 得到中心点 /// /// public ZTPoint GetCenterPoint() { return GetRatioPoint(0.5f); } /// /// 得到一个比例的某个点 /// /// /// public ZTPoint GetRatioPoint(float ratio) { return new ZTPoint((Int32)(Start.X + (End.X - Start.X)*ratio), (Int32)(Start.Y + (End.Y - Start.Y) *ratio)); } public Int32 GetWidth() { return End.X - Start.X; } public Int32 GetHight() { return End.Y - Start.Y; } public static bool operator ==(ZTRectangle a, ZTRectangle b) { if (a.Start == b.Start && a.End == b.End) { return true; } return false; } public static bool operator !=(ZTRectangle a, ZTRectangle b) { if (a.Start != b.Start || a.End != b.End) { return true; } return false; } public override string ToString() { return "start:" + Start.ToString() + ",end:" + End.ToString(); } #region IEquatable public bool Equals(ZTRectangle other) { if (this.Start == other.Start && this.End == other.End) { return true; } return false; } #endregion } }