1+ using System ;
2+
3+ #pragma warning disable CS1591 // 缺少对公共可见类型或成员的 XML 注释
4+
5+ namespace dotnetCampus . OpenXmlUnitConverter
6+ {
7+ /// <summary>
8+ /// 采用 <see cref="Emu"/> 表示的矩形
9+ /// </summary>
10+ public readonly struct EmuRectangle : IEquatable < EmuRectangle >
11+ {
12+ /// <summary>
13+ /// 创建使用 <see cref="Emu"/> 表示的矩形
14+ /// </summary>
15+ public EmuRectangle ( Emu left , Emu top , Emu right , Emu bottom )
16+ {
17+ Left = left ;
18+ Top = top ;
19+ Right = right ;
20+ Bottom = bottom ;
21+ }
22+
23+ /// <summary>
24+ /// 创建使用 <see cref="Emu"/> 表示的矩形
25+ /// </summary>
26+ public EmuRectangle ( EmuPoint point , EmuSize size )
27+ {
28+ Left = point . X ;
29+ Top = point . Y ;
30+ Right = new Emu ( point . X . Value + size . Width . Value ) ;
31+ Bottom = new Emu ( point . Y . Value + size . Height . Value ) ;
32+ }
33+
34+ public Emu Left { get ; }
35+ public Emu Top { get ; }
36+
37+ public Emu Right { get ; }
38+ public Emu Bottom { get ; }
39+
40+ public Emu Width => new Emu ( Right . Value - Left . Value ) ;
41+ public Emu Height => new Emu ( Bottom . Value - Top . Value ) ;
42+
43+ public EmuPoint LeftTop => new EmuPoint ( Left , Top ) ;
44+ public EmuPoint RightBottom => new EmuPoint ( Right , Bottom ) ;
45+ public EmuSize Size => new EmuSize ( Width , Height ) ;
46+
47+ public bool Equals ( EmuRectangle other )
48+ {
49+ return Left . Equals ( other . Left )
50+ && Top . Equals ( other . Top )
51+ && Right . Equals ( other . Right )
52+ && Bottom . Equals ( other . Bottom ) ;
53+ }
54+
55+ public override bool Equals ( object ? obj )
56+ {
57+ return obj is EmuRectangle other && Equals ( other ) ;
58+ }
59+
60+ public override int GetHashCode ( )
61+ {
62+ unchecked
63+ {
64+ var hashCode = Left . GetHashCode ( ) ;
65+ hashCode = ( hashCode * 397 ) ^ Top . GetHashCode ( ) ;
66+ hashCode = ( hashCode * 397 ) ^ Right . GetHashCode ( ) ;
67+ hashCode = ( hashCode * 397 ) ^ Bottom . GetHashCode ( ) ;
68+ return hashCode ;
69+ }
70+ }
71+
72+ /// <summary>
73+ /// 判断相等
74+ /// </summary>
75+ public static bool operator == ( in EmuRectangle left , in EmuRectangle right )
76+ {
77+ return left . Equals ( right ) ;
78+ }
79+
80+ /// <summary>
81+ /// 判断不相等
82+ /// </summary>
83+ public static bool operator != ( in EmuRectangle left , in EmuRectangle right )
84+ {
85+ return ! left . Equals ( right ) ;
86+ }
87+
88+ /// <inheritdoc />
89+ public override string ToString ( ) =>
90+ $ "{ LeftTop } ;{ Size } ";
91+ }
92+ }
0 commit comments