using System;
|
using System.Collections.Generic;
|
using System.Linq;
|
using System.Text;
|
using System.Threading.Tasks;
|
|
namespace RichCreator.Utility.Structs
|
{
|
/// <summary>
|
/// 方框
|
/// </summary>
|
public struct ZTRectangle:IEquatable<ZTRectangle>
|
{
|
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);
|
}
|
|
/// <summary>
|
/// 左上角点
|
/// </summary>
|
public ZTPoint Start;
|
|
/// <summary>
|
/// 右下角点
|
/// </summary>
|
public ZTPoint End;
|
|
/// <summary>
|
/// 得到中心点
|
/// </summary>
|
/// <returns></returns>
|
public ZTPoint GetCenterPoint()
|
{
|
return GetRatioPoint(0.5f);
|
}
|
|
/// <summary>
|
/// 得到一个比例的某个点
|
/// </summary>
|
/// <param name="ratio"></param>
|
/// <returns></returns>
|
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
|
}
|
}
|