Attribute VB_Name = "IntersectRectFunc"
'Copyright Stephen Blyskal 2002

'This intersectRect Func checks to see if 2 rects intersect(duh)
'Typer something like this to use:
'If IntersectRect(Shape2, Shape1.Left) = True Then


Function IntersectRect(Image1 As PictureBox, Image2 As PictureBox) As Boolean 'x1 As Integer, x2 As Integer, y1 As Integer, y2 As Integer, x1a As Integer, x2a As Integer, y1a As Integer, y2a As Integer) As Boolean
Dim x1 As Integer
Dim x2 As Integer
Dim y1 As Integer
Dim y2 As Integer
Dim x1a As Integer
Dim x2a As Integer
Dim y1a As Integer
Dim y2a As Integer

x1 = Image1.Left
x2 = Image1.Left + Image1.Width
y1 = Image1.Top + Image1.Height
y2 = Image1.Top
x1a = Image2.Left
x2a = Image2.Left + Image2.Width
y1a = Image2.Top + Image2.Height
y2a = Image2.Top
'------------------------------'
Dim Xin As Boolean
Dim Yin As Boolean

If x1a < x2 And x1a > x1 Then
Xin = True
Else: Xin = False
End If

If y2a < y1 And y2a > y2 Then
Yin = True
Else: Yin = False
End If

If Yin = True And Xin = True Then IntersectRect = True
'*************************************************************************************************************************************************************

If x2a < x2 And x2a > x1 Then
Xin = True
Else: Xin = False
End If

If y2a < y1 And y2a > y2 Then
Yin = True
Else: Yin = False
End If

If Yin = True And Xin = True Then IntersectRect = True
'*************************************************************************************************************************************************************

If x1a < x2 And x1a > x1 Then
Xin = True
Else: Xin = False
End If

If y1a < y1 And y1a > y2 Then
Yin = True
Else: Yin = False
End If

If Yin = True And Xin = True Then IntersectRect = True
'*************************************************************************************************************************************************************

If x2a < x2 And x2a > x1 Then
Xin = True
Else: Xin = False
End If

If y1a < y1 And y1a > y2 Then
Yin = True
Else: Yin = False
End If

If Yin = True And Xin = True Then IntersectRect = True
'**************************************************************************************************************************************************************
'**************************************************************************************************************************************************************
'**************************************************************************************************************************************************************
'**************************************************************************************************************************************************************
'**************************************************************************************************************************************************************

If x1 > x1a And x1 < x2a Then
Xin = True
Else: Xin = False
End If

If y1 > y2a And y1 < y1a Then
Yin = True
Else: Yin = False
End If

If Yin = True And Xin = True Then IntersectRect = True
'*************************************************************************************************************************************************************

If x2 > x1a And x2 < x2a Then
Xin = True
Else: Xin = False
End If

If y2 > y2a And y2 < y1a Then
Yin = True
Else: Yin = False
End If

If Yin = True And Xin = True Then IntersectRect = True
'*************************************************************************************************************************************************************

If x1 > x1a And x1 < x2a Then
Xin = True
Else: Xin = False
End If

If y2 > y2a And y2 < y1a Then
Yin = True
Else: Yin = False
End If

If Yin = True And Xin = True Then IntersectRect = True
'*************************************************************************************************************************************************************

If x2 > x1a And x2 < x2a Then
Xin = True
Else: Xin = False
End If

If y1 > y2a And y1 < y1a Then
Yin = True
Else: Yin = False
End If

If Yin = True And Xin = True Then IntersectRect = True

End Function

