File tree Expand file tree Collapse file tree
dotnetCampus.OpenXMLUnitConverter
dotnetCampus.OpenXmlUnitConverter
tests/dotnetCampus.OpenXmlUnitConverter.Tests Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ using System ;
2+
3+ namespace dotnetCampus . OpenXmlUnitConverter
4+ {
5+ /// <summary>
6+ /// 采用 <see cref="Pixel"/> 表示的点
7+ /// </summary>
8+ public readonly struct PixelPoint : IEquatable < PixelPoint >
9+ {
10+ /// <summary>
11+ /// 创建 <see cref="Pixel"/> 表示的点
12+ /// </summary>
13+ /// <param name="x"></param>
14+ /// <param name="y"></param>
15+ public PixelPoint ( Pixel x , Pixel y )
16+ {
17+ X = x ;
18+ Y = y ;
19+ }
20+
21+ /// <summary>
22+ /// 表示 X 坐标
23+ /// </summary>
24+ public Pixel X { get ; }
25+
26+ /// <summary>
27+ /// 表示 Y 坐标
28+ /// </summary>
29+ public Pixel Y { get ; }
30+
31+ /// <inheritdoc />
32+ public override string ToString ( ) => $ "X={ X } ;Y={ Y } ";
33+
34+ /// <inheritdoc />
35+ public bool Equals ( PixelPoint other )
36+ {
37+ return X . Equals ( other . X ) && Y . Equals ( other . Y ) ;
38+ }
39+
40+ /// <inheritdoc />
41+ public override bool Equals ( object ? obj )
42+ {
43+ return obj is PixelPoint other && Equals ( other ) ;
44+ }
45+
46+ /// <inheritdoc />
47+ public override int GetHashCode ( )
48+ {
49+ unchecked
50+ {
51+ return ( X . GetHashCode ( ) * 397 ) ^ Y . GetHashCode ( ) ;
52+ }
53+ }
54+
55+ /// <summary>
56+ /// 判断相等
57+ /// </summary>
58+ public static bool operator == ( PixelPoint left , PixelPoint right )
59+ {
60+ return left . Equals ( right ) ;
61+ }
62+
63+ /// <summary>
64+ /// 判断不相等
65+ /// </summary>
66+ public static bool operator != ( PixelPoint left , PixelPoint right )
67+ {
68+ return ! left . Equals ( right ) ;
69+ }
70+ }
71+ }
Original file line number Diff line number Diff line change @@ -196,5 +196,15 @@ public static Pt ToPt(this Emu emu)
196196 }
197197
198198 #endregion
199+
200+ #region PixelPoint
201+
202+ public static PixelPoint ToPixelPoint ( this EmuPoint emuPoint ) =>
203+ new PixelPoint ( emuPoint . X . ToPixel ( ) , emuPoint . Y . ToPixel ( ) ) ;
204+
205+ public static EmuPoint ToEmuPoint ( this PixelPoint pixelPoint ) =>
206+ new EmuPoint ( pixelPoint . X . ToEmu ( ) , pixelPoint . Y . ToEmu ( ) ) ;
207+
208+ #endregion
199209 }
200210}
Original file line number Diff line number Diff line change 1+ using Microsoft . VisualStudio . TestTools . UnitTesting ;
2+ using MSTest . Extensions . Contracts ;
3+
4+ namespace dotnetCampus . OpenXmlUnitConverter . Tests
5+ {
6+ [ TestClass ]
7+ public class PixelPointTest
8+ {
9+ [ ContractTestCase ]
10+ public void Convert ( )
11+ {
12+ "传入 Emu 表示的点,可以转换为像素表示的点" . Test ( ( ) =>
13+ {
14+ var emuPoint = new EmuPoint ( new Emu ( 952500 ) , new Emu ( 952500 ) ) ;
15+ var pixelPoint = emuPoint . ToPixelPoint ( ) ;
16+ Assert . AreEqual ( 100 , pixelPoint . X . Value ) ;
17+ Assert . AreEqual ( 100 , pixelPoint . Y . Value ) ;
18+
19+ Assert . AreEqual ( emuPoint , pixelPoint . ToEmuPoint ( ) ) ;
20+ } ) ;
21+ }
22+ }
23+ }
You can’t perform that action at this time.
0 commit comments