Optimising Challenge

BlitzMax Forums/BlitzMax Programming/Optimising Challenge

There is an error in:

Function TweenAngle:Float( C:Float , T:Float , S:Float)
		Local DX:Float = T-C
	 	If Abs(DX)>180 Then DX=DX-Sgn(DX)*360
		Return (C + DX*S)
	
End Function


But even that does not seem to be correct for tweening. It only works for the given sample with the drawing. When tweening from 0 to 190, it gets stuck at -169.99999994

I modified mine as well:

SuperStrict
Local v1:Float
Local v2:Float

Local time1:Int	= MilliSecs()
For Local i:Int = 1 To 1000
	v1 = 0
	v2 = 190
	While v1 < v2 - 0.1 Or v1 > v2 + 0.1
		v1	= tweenangle1(v1,v2,0.1)
	Wend
Next
time1	= MilliSecs() - time1
Print "Time1: " + time1

Local time2:Int	= MilliSecs()
For Local i:Int = 1 To 1000
	v1 = 0
	v2 = 190
	While v1 < v2 - 0.1 Or v1 > v2 + 0.1
		v1	= tweenangle(v1,v2,0.1)
		Print v1 + "," + v2
	Wend
Next
time2	= MilliSecs() - time2
Print "Time2: " + time2

End


Function TweenAngle1:Float( p1:Float , p2:Float , t:Float)
	If Abs(p2-p1) > 180
		If p2 < 180 Return wrapangle(p1 - t * (p1 - p2) + 180)
		Else Return wrapangle(p1 - t * (p1 - p2))
	EndIf
	Return wrapangle(p1 + t * (p2 - p1))
	
	Function WrapAngle:Float(angle:Float)
		Return (angle + 360) Mod 360
	End Function
End Function

Function TweenAngle:Float( C:Float , T:Float , S:Float)
		Local DX:Float = T-C
	 	If Abs(DX)>180 Then DX=DX-Sgn(DX)*360
		Return (C + DX*S)
	
End Function


*mine takes 31ms for 1000 full tweens with 0.1 iteration. Can't say for the other as it stucks*