C
Crirus
What do you think about this approaches, wich one is the best?
For x As Integer = u.GetViewBounds.X To u.GetViewBounds.X +
u.GetViewBounds.Width
For y As Integer = u.GetViewBounds.Y To
u.GetViewBounds.Y + u.GetViewBounds.Height
Dim Dx As Integer = x - u.Location.X
Dim Dy As Integer = y - u.Location.Y
If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange
Then 'punctul e in cercul vizual
AddCorrectPoint(x, y)
End If
Next
Next
or
dim vr as rectangle=u.GetViewBounds
For x As Integer = vr.X To vr.X + vr.Width
For y As Integer = vr.Y To vr.Y + vr.Height
Dim Dx As Integer = x - u.Location.X
Dim Dy As Integer = y - u.Location.Y
If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange
Then 'punctul e in cercul vizual
AddCorrectPoint(x, y)
End If
Next
Next
Should I declare a variable as rectangle?
I'm not sure how compiler will optimize this and a call to u.GetViewBounds
each time is looping is a speed problem to me
For x As Integer = u.GetViewBounds.X To u.GetViewBounds.X +
u.GetViewBounds.Width
For y As Integer = u.GetViewBounds.Y To
u.GetViewBounds.Y + u.GetViewBounds.Height
Dim Dx As Integer = x - u.Location.X
Dim Dy As Integer = y - u.Location.Y
If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange
Then 'punctul e in cercul vizual
AddCorrectPoint(x, y)
End If
Next
Next
or
dim vr as rectangle=u.GetViewBounds
For x As Integer = vr.X To vr.X + vr.Width
For y As Integer = vr.Y To vr.Y + vr.Height
Dim Dx As Integer = x - u.Location.X
Dim Dy As Integer = y - u.Location.Y
If Dx * Dx + Dy * Dy <= u.ViewRange * u.ViewRange
Then 'punctul e in cercul vizual
AddCorrectPoint(x, y)
End If
Next
Next
Should I declare a variable as rectangle?
I'm not sure how compiler will optimize this and a call to u.GetViewBounds
each time is looping is a speed problem to me