TizzyT

CircleF_Simple -TizzyT

Aug 8th, 2015
298
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 2.26 KB | None | 0 0
  1.     Public Structure CircleF
  2.         Private _Diameter As Single
  3.         Private _Radius As Single
  4.         Private _X As Single
  5.         Private _Y As Single
  6.  
  7.         'Takes 3 singles and creates a new circle
  8.         Public Sub New(ByVal X As Single,
  9.                        ByVal Y As Single,
  10.                        ByVal Radius As Single)
  11.             _Diameter = Radius * 2
  12.             _Radius = Radius
  13.             _X = X
  14.             _Y = Y
  15.         End Sub
  16.  
  17.         'Returns or sets the radius of the circle
  18.         Public Property Radius() As Single
  19.             Get
  20.                 Return _Radius
  21.             End Get
  22.             Set(value As Single)
  23.                 _Radius = value
  24.                 _Diameter = _Radius * 2
  25.             End Set
  26.         End Property
  27.  
  28.         'Returns the Diameter length
  29.         Public ReadOnly Property Diameter() As Single
  30.             Get
  31.                 Return _Diameter
  32.             End Get
  33.         End Property
  34.  
  35.         'Returns or sets the center coordinates of the circle
  36.         Public Property X() As Single
  37.             Get
  38.                 Return _X
  39.             End Get
  40.             Set(value As Single)
  41.                 _X = value
  42.             End Set
  43.         End Property
  44.  
  45.         'Returns or sets the center coordinates of the circle
  46.         Public Property Y() As Single
  47.             Get
  48.                 Return _Y
  49.             End Get
  50.             Set(value As Single)
  51.                 _Y = value
  52.             End Set
  53.         End Property
  54.  
  55.         'Returns the center coordinates of the circle
  56.         Public ReadOnly Property Center() As PointF
  57.             Get
  58.                 Return New PointF(_X, _Y)
  59.             End Get
  60.         End Property
  61.  
  62.         'Returns whether this circle intersects with another circle
  63.         Public Function IntersectsWith(ByVal C2 As CircleF) As Boolean
  64.             If (_Radius + C2.Radius) ^ 2 >= ((_X - C2.X) ^ 2) + ((_Y - C2.Y) ^ 2) Then Return True
  65.             Return False
  66.         End Function
  67.  
  68.         'Returns whether this circle contains a given point
  69.         Public Function Contains(ByVal Point As PointF) As Boolean
  70.             If _Radius ^ 2 >= ((_X - Point.X) ^ 2) + ((_Y - Point.Y) ^ 2) Then Return True
  71.             Return False
  72.         End Function
  73.     End Structure
Advertisement
Add Comment
Please, Sign In to add comment