MathUtil.bmx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061
  1. ' *******************************************************************
  2. ' Source: Math Util
  3. ' Version: 1.00
  4. ' Author: Rob Hutchinson 2004
  5. ' Email: [email protected]
  6. ' WWW: http://www.proteanide.co.uk/
  7. ' -------------------------------------------------------------------
  8. ' Some generic functions. Certainly nothing to do with Math. HURRAH!
  9. ' -------------------------------------------------------------------
  10. ' Required:
  11. ' - Nothing.
  12. ' *******************************************************************
  13. Strict
  14. Type MathUtil
  15. '#Region Method: QWrapF
  16. ' Wraps only once, if the value is out of the range by twice as much, this function will return incorrect values,
  17. ' However, it is faster than Wrap. Use Wrap for accurate results.
  18. Function QWrapF:Float(Value:Float,Minimum:Float,Maximum:Float)
  19. If Value > Maximum
  20. Return Minimum + (Value Mod Maximum)
  21. ElseIf Value < Minimum
  22. Return Maximum - Abs(Minimum - Value)
  23. EndIf
  24. Return Value
  25. End Function
  26. '#End Region
  27. '#Region Method: QWrapDegrees
  28. Function QWrapDegrees:Double(Value:Double)
  29. If Value > 359.0
  30. Return (0.0 + (Value Mod 359.0))
  31. ElseIf Value < 0.0
  32. Return (359.0 - Abs(0.0 - Value))
  33. EndIf
  34. Return Value
  35. End Function
  36. '#End Region
  37. '#Region Method: Wrap
  38. Function Wrap:Float(Value:Float,Minimum:Float,Maximum:Float)
  39. Local Difference:Float = Maximum - Minimum
  40. While ((Value < Minimum) Or (Value => Maximum))
  41. If Value => Maximum
  42. Value:- Difference
  43. Else
  44. If Value < Minimum
  45. Value:+ Difference
  46. EndIf
  47. EndIf
  48. Wend
  49. Return value
  50. End Function
  51. '#End Region
  52. '#Region Method: CurveValue
  53. Function CurveValue:Float(Current:Float,Destination:Float,Curve:Int)
  54. Current = Current + ( (Destination - Current) /Curve)
  55. Return Current
  56. End Function
  57. '#End Region
  58. End Type