1 #Region "Microsoft.VisualBasic::f532319ba203ff80910141664ccdb0f8, Microsoft.VisualBasic.Core\Extensions\Image\Math\Models\Line.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 Line
35     
36     '         Properties: Length, P1, P2, X1, X2
37     '                     Y1, Y2
38     
39     '         Constructor: (+1 OverloadsSub New
40     '         FunctionToString
41     
42     
43     ' /********************************************************************************/
44
45 #End Region
46
47 Imports System.Drawing
48 Imports System.Runtime.CompilerServices
49
50 Namespace Imaging.Math2D
51
52     Public Structure Line
53
54         Public Shared ReadOnly Empty As New Line
55
56         ''' <summary>
57         ''' (<see cref="X1"/>, <see cref="Y1"/>)
58         ''' </summary>
59         ''' <returns></returns>
60         Public ReadOnly Property P1 As PointF
61             <MethodImpl(MethodImplOptions.AggressiveInlining)>
62             Get
63                 Return New PointF(X1, Y1)
64             End Get
65         End Property
66
67         ''' <summary>
68         ''' (<see cref="X2"/>, <see cref="Y2"/>)
69         ''' </summary>
70         ''' <returns></returns>
71         Public ReadOnly Property P2 As PointF
72             <MethodImpl(MethodImplOptions.AggressiveInlining)>
73             Get
74                 Return New PointF(X2, Y2)
75             End Get
76         End Property
77
78         Public ReadOnly Property Length As Double
79             <MethodImpl(MethodImplOptions.AggressiveInlining)>
80             Get
81                 Return P1.Distance(P2)
82             End Get
83         End Property
84
85         Public Sub New(p1 As PointF, p2 As PointF)
86             Me.X1 = p1.X
87             Me.Y1 = p1.Y
88             Me.X2 = p2.X
89             Me.Y2 = p2.Y
90         End Sub
91
92 #Region "Points"
93         Public Property X1 As Single
94         Public Property X2 As Single
95         Public Property Y1 As Single
96         Public Property Y2 As Single
97 #End Region
98
99         Public Overrides Function ToString() As String
100             Return $"[{{{X1}, {Y1}}}, {{{X2}, {Y2}}}]"
101         End Function
102
103         <MethodImpl(MethodImplOptions.AggressiveInlining)>
104         Public Shared Widening Operator CType(pointTuple As (X#, Y#)()) As Line
105             Return New Line With {
106                 .X1 = pointTuple(0).X,
107                 .Y1 = pointTuple(0).Y,
108                 .X2 = pointTuple(1).X,
109                 .Y2 = pointTuple(1).Y
110             }
111         End Operator
112
113         <MethodImpl(MethodImplOptions.AggressiveInlining)>
114         Public Shared Widening Operator CType(twoPoints As PointF()) As Line
115             Return New Line(twoPoints(0), twoPoints(1))
116         End Operator
117     End Structure
118 End Namespace