Imports System
Class RectangleCenter
Class Point
Public x, y As Double
Public Sub New(ByVal x As Double, ByVal y As Double)
Me.x = x
Me.y = y
End Sub
End Class
Class Rectangle
Public topLeft As Point
Public bottomRight As Point
Public Sub New(ByVal topLeft As Point, ByVal bottomRight As Point)
Me.topLeft = topLeft
Me.bottomRight = bottomRight
End Sub
End Class
Private Shared Function GetCenter(ByVal rect As Rectangle) As Point
Dim centerX As Double = (rect.topLeft.x + rect.bottomRight.x) / 2.0
Dim centerY As Double = (rect.topLeft.y + rect.bottomRight.y) / 2.0
Return New Point(centerX, centerY)
End Function
Public Shared Sub Main()
Dim rect As Rectangle = New Rectangle(New Point(10.0, 20.0), New Point(110.0, 70.0))
Dim center As Point = GetCenter(rect)
Console.WriteLine("Center of the rectangle: ({0:F2}, {1:F2})", center.x, center.y)
End Sub
End Class
' run:
'
' Center of the rectangle: (60.00, 45.00)
'