Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Public Structure RectF
- Private _Top As Single 'Top Y axis
- Private _Bottom As Single 'Bottom Y axis
- Private _Left As Single 'Left X axis
- Private _Right As Single 'Right X axis
- Private _Width As Single 'Width of rectangle
- Private _Height As Single 'Height of rectangle
- Private _InitialWidth As Single 'Initial width of rectangle when it was created
- Private _InitialHeight As Single 'Initial height of rectangle when it was created
- Private _Warpable As Boolean 'Is rectangle's shape able to change
- 'Gets or sets the top side of rectangle on the Y axis
- Public Property Top() As Single
- Get
- Return _Top
- End Get
- Set(value As Single)
- If _Warpable Then
- If value > _Bottom Then
- _Top = _Bottom
- _Bottom = value
- Else
- _Top = value
- _Height = _Bottom - _Top
- End If
- Else
- _Bottom = _Top + _Height
- End If
- End Set
- End Property
- 'Gets or sets the bottom side of rectangle on the Y axis
- Public Property Bottom() As Single
- Get
- Return _Bottom
- End Get
- Set(value As Single)
- If _Warpable Then
- If value < _Top Then
- _Bottom = _Top
- _Top = value
- Else
- _Bottom = value
- _Height = _Bottom - _Top
- End If
- Else
- _Top = _Bottom - _Height
- End If
- End Set
- End Property
- 'Gets or sets the left side of rectangle on the X axis
- Public Property Left() As Single
- Get
- Return _Left
- End Get
- Set(value As Single)
- If _Warpable Then
- If value > _Right Then
- _Left = _Right
- _Right = value
- Else
- _Left = value
- _Width = _Right - _Left
- End If
- Else
- _Right = _Left + _Width
- End If
- End Set
- End Property
- 'Gets or sets the right side of the rectangle on the X axis
- Public Property Right() As Single
- Get
- Return _Right
- End Get
- Set(value As Single)
- If _Warpable Then
- If value < _Left Then
- _Right = _Left
- _Left = value
- Else
- _Right = value
- _Width = Right - Left
- End If
- Else
- _Left = _Right - _Width
- End If
- End Set
- End Property
- 'Returns whether or not this rectangle is warpable or not(if the size can change)
- Public ReadOnly Property Warpable() As Boolean
- Get
- Return _Warpable
- End Get
- End Property
- 'Uses 4 singles as position and size information to construct a new RectF, and if it can change sizes
- Public Sub New(ByVal X As Single, ByVal Y As Single,
- ByVal Width As Single, ByVal Height As Single,
- Optional ByVal Warpable As Boolean = False)
- _Warpable = Warpable
- _Width = Width
- _InitialWidth = Width
- _Height = Height
- _InitialHeight = Height
- _Left = X
- _Top = Y
- _Right = X + Width
- _Bottom = Y + Width
- End Sub
- 'Resets the size of this rectangle to the initial size using the current top and left position
- Public Sub ResetSize()
- Right = Left + _InitialWidth
- Bottom = Top + _InitialHeight
- End Sub
- 'Returns whether or not this rectangles intersects with another given rectangle
- Public Function IntersectsWith(ByVal R2 As RectF) As Boolean
- If Left > R2.Right OrElse R2.Left > Right Then Return False
- If Top > R2.Bottom OrElse R2.Top > Bottom Then Return False
- Return True
- End Function
- End Structure
Advertisement
Add Comment
Please, Sign In to add comment