TizzyT

RectF -TizzyT

Aug 7th, 2015
294
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 4.52 KB | None | 0 0
  1.     Public Structure RectF
  2.         Private _Top As Single 'Top Y axis
  3.         Private _Bottom As Single 'Bottom Y axis
  4.         Private _Left As Single 'Left X axis
  5.         Private _Right As Single 'Right X axis
  6.         Private _Width As Single 'Width of rectangle
  7.         Private _Height As Single 'Height of rectangle
  8.         Private _InitialWidth As Single 'Initial width of rectangle when it was created
  9.         Private _InitialHeight As Single 'Initial height of rectangle when it was created
  10.         Private _Warpable As Boolean 'Is rectangle's shape able to change
  11.  
  12.         'Gets or sets the top side of rectangle on the Y axis
  13.         Public Property Top() As Single
  14.             Get
  15.                 Return _Top
  16.             End Get
  17.             Set(value As Single)
  18.                 If _Warpable Then
  19.                     If value > _Bottom Then
  20.                         _Top = _Bottom
  21.                         _Bottom = value
  22.                     Else
  23.                         _Top = value
  24.                         _Height = _Bottom - _Top
  25.                     End If
  26.                 Else
  27.                     _Bottom = _Top + _Height
  28.                 End If
  29.             End Set
  30.         End Property
  31.  
  32.         'Gets or sets the bottom side of rectangle on the Y axis
  33.         Public Property Bottom() As Single
  34.             Get
  35.                 Return _Bottom
  36.             End Get
  37.             Set(value As Single)
  38.                 If _Warpable Then
  39.                     If value < _Top Then
  40.                         _Bottom = _Top
  41.                         _Top = value
  42.                     Else
  43.                         _Bottom = value
  44.                         _Height = _Bottom - _Top
  45.                     End If
  46.                 Else
  47.                     _Top = _Bottom - _Height
  48.                 End If
  49.             End Set
  50.         End Property
  51.  
  52.         'Gets or sets the left side of rectangle on the X axis
  53.         Public Property Left() As Single
  54.             Get
  55.                 Return _Left
  56.             End Get
  57.             Set(value As Single)
  58.                 If _Warpable Then
  59.                     If value > _Right Then
  60.                         _Left = _Right
  61.                         _Right = value
  62.                     Else
  63.                         _Left = value
  64.                         _Width = _Right - _Left
  65.                     End If
  66.                 Else
  67.                     _Right = _Left + _Width
  68.                 End If
  69.             End Set
  70.         End Property
  71.  
  72.         'Gets or sets the right side of the rectangle on the X axis
  73.         Public Property Right() As Single
  74.             Get
  75.                 Return _Right
  76.             End Get
  77.             Set(value As Single)
  78.                 If _Warpable Then
  79.                     If value < _Left Then
  80.                         _Right = _Left
  81.                         _Left = value
  82.                     Else
  83.                         _Right = value
  84.                         _Width = Right - Left
  85.                     End If
  86.                 Else
  87.                     _Left = _Right - _Width
  88.                 End If
  89.             End Set
  90.         End Property
  91.  
  92.         'Returns whether or not this rectangle is warpable or not(if the size can change)
  93.         Public ReadOnly Property Warpable() As Boolean
  94.             Get
  95.                 Return _Warpable
  96.             End Get
  97.         End Property
  98.  
  99.         'Uses 4 singles as position and size information to construct a new RectF, and if it can change sizes
  100.         Public Sub New(ByVal X As Single, ByVal Y As Single,
  101.                        ByVal Width As Single, ByVal Height As Single,
  102.                        Optional ByVal Warpable As Boolean = False)
  103.             _Warpable = Warpable
  104.             _Width = Width
  105.             _InitialWidth = Width
  106.             _Height = Height
  107.             _InitialHeight = Height
  108.             _Left = X
  109.             _Top = Y
  110.             _Right = X + Width
  111.             _Bottom = Y + Width
  112.         End Sub
  113.  
  114.         'Resets the size of this rectangle to the initial size using the current top and left position
  115.         Public Sub ResetSize()
  116.             Right = Left + _InitialWidth
  117.             Bottom = Top + _InitialHeight
  118.         End Sub
  119.  
  120.         'Returns whether or not this rectangles intersects with another given rectangle
  121.         Public Function IntersectsWith(ByVal R2 As RectF) As Boolean
  122.             If Left > R2.Right OrElse R2.Left > Right Then Return False
  123.             If Top > R2.Bottom OrElse R2.Top > Bottom Then Return False
  124.             Return True
  125.         End Function
  126.     End Structure
Advertisement
Add Comment
Please, Sign In to add comment