Question: After speed meassuring i find blitz sqr is just as fast or slow as the euclidean formula. am i doing something wrong here?
SuperStrict Graphics 640,480,0,200 Local dist1:Float, dist2:Float Local test:Int=0 Local time:Int Repeat time=MilliSecs() For Local l:Int=0 To 200000 If test=0 Then dist1=approxdist(GraphicsWidth()/2,GraphicsHeight()/2,MouseX(),MouseY()) Else dist1=realdist(GraphicsWidth()/2,GraphicsHeight()/2,MouseX(),MouseY()) End If Next DrawText MilliSecs()-time,0,0 DrawText "test:"+test,0,20 DrawText dist1,0,40 If KeyHit(key_1) Then test=0 If KeyHit(key_2) Then test=1 Flip False Cls Until KeyDown(key_escape) Function RealDist:Float(x1:Float, y1:Float, x2:Float,y2:Float) Local dx:Float=x1-x2 Local dy:Float=y1-y2 Return Sqr( dx*dx + dy*dy) End Function Function ApproxDist:Float(x1:Float, y1:Float, x2:Float,y2:Float) Local dx:Float=Abs(x1-x2) Local dy:Float=Abs(y1-y2) If dy>dx Then Return (dx*0.41 + dy*0.941246) Else Return (dy*0.41 + dx*0.941246) End If End Function