1 | #Region "Microsoft.VisualBasic::69ceea95906ed80e045120aa58ab0bf6, Microsoft.VisualBasic.Core\Extensions\Image\Math\Models\Vector2D.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 | ' Class Vector2D |
35 | ' |
36 | ' Properties: Length |
37 | ' |
38 | ' Constructor: (+3 Overloads) Sub New |
39 | ' Operators: -, (+2 Overloads) * |
40 | ' |
41 | ' |
42 | ' /********************************************************************************/ |
43 | |
44 | #End Region |
45 | |
46 | Namespace Imaging.Math2D |
47 | |
48 | ''' <summary> |
49 | ''' <see cref="Drawing.PointF"/> |
50 | ''' </summary> |
51 | Public Class Vector2D |
52 | |
53 | Public x As Double |
54 | Public y As Double |
55 | |
56 | Public ReadOnly Property Length As Double |
57 | Get |
58 | Return Math.Sqrt(x ^ 2 + y ^ 2) |
59 | End Get |
60 | End Property |
61 | |
62 | Public Sub New() |
63 | Me.New(0.0, 0.0) |
64 | End Sub |
65 | |
66 | Public Sub New(x As Double, y As Double) |
67 | Me.x = x |
68 | Me.y = y |
69 | End Sub |
70 | |
71 | Public Sub New(x As Integer, y As Integer) |
72 | Me.x = x |
73 | Me.y = y |
74 | End Sub |
75 | |
76 | ''' <summary> |
77 | ''' reverse |
78 | ''' </summary> |
79 | ''' <param name="v"></param> |
80 | ''' <returns></returns> |
81 | Public Shared Operator -(v As Vector2D) As Vector2D |
82 | With v |
83 | Return New Vector2D(- .x, - .y) |
84 | End With |
85 | End Operator |
86 | |
87 | ''' <summary> |
88 | ''' multiple |
89 | ''' </summary> |
90 | ''' <param name="scale#"></param> |
91 | ''' <param name="v"></param> |
92 | ''' <returns></returns> |
93 | Public Shared Operator *(scale#, v As Vector2D) As Vector2D |
94 | With v |
95 | Return New Vector2D(scale * .x, scale * .y) |
96 | End With |
97 | End Operator |
98 | |
99 | ''' <summary> |
100 | ''' multiple |
101 | ''' </summary> |
102 | ''' <param name="v"></param> |
103 | ''' <param name="scale#"></param> |
104 | ''' <returns></returns> |
105 | Public Shared Operator *(v As Vector2D, scale#) As Vector2D |
106 | With v |
107 | Return New Vector2D(scale * .x, scale * .y) |
108 | End With |
109 | End Operator |
110 | End Class |
111 | End Namespace |