1 #Region "Microsoft.VisualBasic::a4fe024ece0d0edf2eebf5960b00f08e, Microsoft.VisualBasic.Core\Text\Xml\Models\Coordinate.vb"
2
3     ' Author:
4     
5     '       asuka (amethyst.asuka@gcmodeller.org)
6     '       xie (genetics@smrucc.org)
7     '       xieguigang (xie.guigang@live.com)
8     
9     ' Copyright (c) 2018 GPL3 Licensed
10     
11     
12     ' GNU GENERAL PUBLIC LICENSE (GPL3)
13     
14     
15     ' This program is free software: you can redistribute it and/or modify
16     ' it under the terms of the GNU General Public License as published by
17     ' the Free Software Foundation, either version 3 of the License, or
18     ' (at your option) any later version.
19     
20     ' This program is distributed in the hope that it will be useful,
21     ' but WITHOUT ANY WARRANTY; without even the implied warranty of
22     ' MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
23     ' GNU General Public License for more details.
24     
25     ' You should have received a copy of the GNU General Public License
26     ' along with this program. If not, see <http://www.gnu.org/licenses/>.
27
28
29
30     ' /********************************************************************************/
31
32     ' Summaries:
33
34     '     Structure Coordinate
35     
36     '         Properties: ID, X, Y
37     
38     '         Constructor: (+3 OverloadsSub New
39     '         FunctionToString
40     '         Operators: <>, =
41     
42     
43     ' /********************************************************************************/
44
45 #End Region
46
47 Imports System.Drawing
48 Imports System.Runtime.CompilerServices
49 Imports System.Xml.Serialization
50 Imports Microsoft.VisualBasic.Imaging.LayoutModel
51
52 Namespace Text.Xml.Models
53
54     ''' <summary>
55     ''' Improvements on the xml format layout compare with <see cref="PointF"/> type.
56     ''' </summary>
57     Public Structure Coordinate : Implements ILayoutCoordinate
58
59         ' 2017-6-22
60         ' 因为double类型可以兼容Integer类型,所以在这里改为double类型
61         ' 所以从pointf构建可以不再经过转换了
62
63         <XmlAttribute("x")> Public Property X As Double Implements ILayoutCoordinate.X
64         <XmlAttribute("y")> Public Property Y As Double Implements ILayoutCoordinate.Y
65         <XmlAttribute>
66         Public Property ID As String Implements ILayoutCoordinate.ID
67
68         <MethodImpl(MethodImplOptions.AggressiveInlining)>
69         Sub New(pt As Point)
70             Call Me.New(pt.X, pt.Y)
71         End Sub
72
73         <MethodImpl(MethodImplOptions.AggressiveInlining)>
74         Sub New(pt As PointF)
75             Call Me.New(pt.X, pt.Y)
76         End Sub
77
78         Sub New(x#, y#)
79             Me.X = x
80             Me.Y = y
81         End Sub
82
83         Public Overrides Function ToString() As String
84             Return $"[{X}, {Y}]"
85         End Function
86
87         <MethodImpl(MethodImplOptions.AggressiveInlining)>
88         Public Shared Operator =(c As Coordinate, pt As Point) As Boolean
89             Return c.X = pt.X AndAlso c.Y = pt.Y
90         End Operator
91
92         <MethodImpl(MethodImplOptions.AggressiveInlining)>
93         Public Shared Operator <>(c As Coordinate, pt As Point) As Boolean
94             Return Not c = pt
95         End Operator
96
97         <MethodImpl(MethodImplOptions.AggressiveInlining)>
98         Public Shared Widening Operator CType(pt As Point) As Coordinate
99             Return New Coordinate With {
100                 .X = pt.X,
101                 .Y = pt.Y
102             }
103         End Operator
104
105         <MethodImpl(MethodImplOptions.AggressiveInlining)>
106         Public Shared Narrowing Operator CType(x As Coordinate) As Point
107             Return New Point(x.X, x.Y)
108         End Operator
109
110         <MethodImpl(MethodImplOptions.AggressiveInlining)>
111         Public Shared Widening Operator CType(pt As Integer()) As Coordinate
112             Return New Coordinate(pt.FirstOrDefault, pt.LastOrDefault)
113         End Operator
114     End Structure
115 End Namespace