435,080 Members | 1,855 Online + Ask a Question
Need help? Post your question and get tips & solutions from a community of 435,080 IT Pros & Developers. It's quick & easy.

 P: n/a 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 -- Cheers, Crirus ------------------------------ If work were a good thing, the boss would take it all from you ------------------------------ Nov 20 '05 #1
5 Replies

 P: n/a Crirus, IMHO, the second way will be faster because you only execute "GetViewBounds" once. You could always use the "With" clause to achieve the same effect. Generally if you have to do something like: a.b.z = a.b.x + a.b.y Then it would be more efficient to use: With a.b .z = .x + .y End With The advantage is even greater if a.b is a function that takes time to execute. The VB compiler probably does some optimizations with fields as opposed to properties and methods. Hope this helps, Trev. "Crirus" wrote in message news:%2****************@TK2MSFTNGP10.phx.gbl... 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 -- Cheers, Crirus ------------------------------ If work were a good thing, the boss would take it all from you ------------------------------ Nov 20 '05 #2 