Private Function PointInFences(pnt1 As point, fencePnts As point()) As Boolean
Dim j As Integer = 0, cnt As Integer = 0
For i As Integer = 0 To fencePnts.Length - 1
j = If((i = fencePnts.Length - 1), 0, j + 1)
If (fencePnts(i).y <> fencePnts(j).y) AndAlso (((pnt1.y >= fencePnts(i).y) AndAlso (pnt1.y < fencePnts(j).y)) OrElse ((pnt1.y >= fencePnts(j).y) AndAlso (pnt1.y < fencePnts(i).y))) AndAlso (pnt1.x < (fencePnts(j).x - fencePnts(i).x) * (pnt1.y - fencePnts(i).y) / (fencePnts(j).y - fencePnts(i).y) + fencePnts(i).x) Then
cnt += 1
End If
Next
Return If((cnt Mod 2 > 0), True, False)
End Function
Dim j As Integer = 0, cnt As Integer = 0
For i As Integer = 0 To fencePnts.Length - 1
j = If((i = fencePnts.Length - 1), 0, j + 1)
If (fencePnts(i).y <> fencePnts(j).y) AndAlso (((pnt1.y >= fencePnts(i).y) AndAlso (pnt1.y < fencePnts(j).y)) OrElse ((pnt1.y >= fencePnts(j).y) AndAlso (pnt1.y < fencePnts(i).y))) AndAlso (pnt1.x < (fencePnts(j).x - fencePnts(i).x) * (pnt1.y - fencePnts(i).y) / (fencePnts(j).y - fencePnts(i).y) + fencePnts(i).x) Then
cnt += 1
End If
Next
Return If((cnt Mod 2 > 0), True, False)
End Function