Try this:
The Int-Functions are a little faster than the Float-Ones, also the Quad-Ones are really fast compared to the Non-Quad-ones. But, keep in Mind: If you use the Int-Version, it'll give you an overflow if the quad of the distance is higher than Int can handle.
The fastest Distance-Approximation I've seen so far is the ApproxDistance-Function above. Really really fast.
'iParXD = (iParX1 - iParX2) 'iParYD = (iParY1 - iParY2) Function ApproxDistance:Int(iParXD:Int, iParYD:Int) Local iMin:Int Local iMax:Int If iParXD < 0 Then iParXD = -iParXD If iParYD < 0 Then iParYD = -iParYD If iParXD < iParYD Then iMin = iParXD iMax = iParYD Else iMin = iParYD iMax = iParXD EndIf Return (((iMax Shl 8) + (iMax Shl 3) - (iMax Shl 4) - (iMax Shl 1) + (iMin Shl 7) - (iMin Shl 5) + (iMin Shl 3) - (iMin Shl 1)) Shr 8) End Function Function Distance:Float(fParX1:Float, fParY1:Float, fParX2:Float = 0, fParY2:Float = 0) Return Sqr((fParX1 - fParX2) * (fParX1 - fParX2) + (fParY1 - fParY2) * (fParY1 - fParY2)) End Function Function DistanceQuad:Float(fParX1:Float, fParY1:Float, fParX2:Float = 0, fParY2:Float = 0) Return ((fParX1 - fParX2) * (fParX1 - fParX2) + (fParY1 - fParY2) * (fParY1 - fParY2)) End Function Function IntDistance:Int(iParX1:Int, iParY1:Int, iParX2:Int = 0, iParY2:Int = 0) Return Sqr((iParX1 - iParX2) * (iParX1 - iParX2) + (iParY1 - iParY2) * (iParY1 - iParY2)) End Function Function IntDistanceQuad:Int(iParX1:Int, iParY1:Int, iParX2:Int = 0, iParY2:Int = 0) Return ((iParX1 - iParX2) * (iParX1 - iParX2) + (iParY1 - iParY2) * (iParY1 - iParY2)) End Function
The Int-Functions are a little faster than the Float-Ones, also the Quad-Ones are really fast compared to the Non-Quad-ones. But, keep in Mind: If you use the Int-Version, it'll give you an overflow if the quad of the distance is higher than Int can handle.
The fastest Distance-Approximation I've seen so far is the ApproxDistance-Function above. Really really fast.