| 1 | #Region "Microsoft.VisualBasic::f88945d5b9a69e8946e33cab3084d3e2, Microsoft.VisualBasic.Core\Extensions\Image\GDI+\Layouts\Point2D.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 Point2D |
| 35 | ' |
| 36 | ' Properties: Point, X, Y |
| 37 | ' |
| 38 | ' Constructor: (+4 Overloads) Sub New |
| 39 | ' Function: Clone, Equals, ToString |
| 40 | ' |
| 41 | ' |
| 42 | ' /********************************************************************************/ |
| 43 | |
| 44 | #End Region |
| 45 | |
| 46 | Imports System.Drawing |
| 47 | Imports sys = System.Math |
| 48 | |
| 49 | Namespace Imaging.LayoutModel |
| 50 | |
| 51 | ''' <summary> |
| 52 | ''' Implements a 2-dimensional point with <see cref="Double"/> precision coordinates. |
| 53 | ''' </summary> |
| 54 | <Serializable> Public Class Point2D : Implements ICloneable |
| 55 | |
| 56 | ''' <summary> |
| 57 | ''' Constructs a new point at (0, 0). |
| 58 | ''' </summary> |
| 59 | Public Sub New() |
| 60 | Me.New(0, 0) |
| 61 | End Sub |
| 62 | |
| 63 | ''' <summary> |
| 64 | ''' Constructs a new point at the location of the given point. |
| 65 | ''' </summary> |
| 66 | ''' <param name="point"> Point that specifies the location. </param> |
| 67 | Public Sub New(point As Point) |
| 68 | Me.New(point.X, point.Y) |
| 69 | End Sub |
| 70 | |
| 71 | ''' <summary> |
| 72 | ''' Constructs a new point at the location of the given point. |
| 73 | ''' </summary> |
| 74 | ''' <param name="point"> Point that specifies the location. </param> |
| 75 | Public Sub New(point As Point2D) |
| 76 | Me.New(point.X, point.Y) |
| 77 | End Sub |
| 78 | |
| 79 | ''' <summary> |
| 80 | ''' Constructs a new point at (x, y). |
| 81 | ''' </summary> |
| 82 | ''' <param name="x"> X-coordinate of the point to be created. </param> |
| 83 | ''' <param name="y"> Y-coordinate of the point to be created. </param> |
| 84 | Public Sub New(x As Double, y As Double) |
| 85 | Me.X = x |
| 86 | Me.Y = y |
| 87 | End Sub |
| 88 | |
| 89 | ''' <summary> |
| 90 | ''' Returns the x-coordinate of the point. |
| 91 | ''' </summary> |
| 92 | ''' <returns> Returns the x-coordinate. </returns> |
| 93 | Public Overridable Property X As Double |
| 94 | |
| 95 | ''' <summary> |
| 96 | ''' Returns the x-coordinate of the point. |
| 97 | ''' </summary> |
| 98 | ''' <returns> Returns the x-coordinate. </returns> |
| 99 | Public Overridable Property Y As Double |
| 100 | |
| 101 | ''' <summary> |
| 102 | ''' Returns the coordinates as a new point. |
| 103 | ''' </summary> |
| 104 | ''' <returns> Returns a new point for the location. </returns> |
| 105 | Public Overridable ReadOnly Property Point As Point |
| 106 | Get |
| 107 | Return New Point(CInt(Fix(sys.Round(X))), CInt(Fix(sys.Round(Y)))) |
| 108 | End Get |
| 109 | End Property |
| 110 | |
| 111 | ''' |
| 112 | ''' <summary> |
| 113 | ''' Returns true if the given object equals this rectangle. |
| 114 | ''' </summary> |
| 115 | Public Overrides Function Equals(obj As Object) As Boolean |
| 116 | If TypeOf obj Is Point2D Then |
| 117 | Dim pt As Point2D = CType(obj, Point2D) |
| 118 | |
| 119 | Return pt.X = X AndAlso pt.Y = Y |
| 120 | End If |
| 121 | |
| 122 | Return False |
| 123 | End Function |
| 124 | |
| 125 | ''' <summary> |
| 126 | ''' Returns a new instance of the same point. |
| 127 | ''' </summary> |
| 128 | Public Overridable Function Clone() As Object Implements ICloneable.Clone |
| 129 | Return New Point2D(X, Y) |
| 130 | End Function |
| 131 | |
| 132 | ''' <summary> |
| 133 | ''' Returns a <code>String</code> that represents the value |
| 134 | ''' of this <code>mxPoint</code>. </summary> |
| 135 | ''' <returns> a string representation of this <code>mxPoint</code>. </returns> |
| 136 | Public Overrides Function ToString() As String |
| 137 | Return Me.GetType().Name & "[" & X & ", " & Y & "]" |
| 138 | End Function |
| 139 | End Class |
| 140 | End Namespace |