asmrobot
2019-11-21 589ed88a5924a7494e21b95b6bbff5e46ff49ddd
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
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 .Equals( b.Start) && a.End.Equals( b.End))
            {
                return true;
            }
            return false;
        }
 
        public static bool operator !=(ZTRectangle a, ZTRectangle b)
        {
            if (!a.Start.Equals( b.Start) || !a.End.Equals(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.Equals(other.Start) && this.End.Equals(other.End))
            {
                return true;
            }
            return false;
        }
        #endregion
    }
}