MathUtil.bmx 1.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960
  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. Type MathUtil
  14. '#Region Method: QWrapF
  15. ' Wraps only once, if the value is out of the range by twice as much, this function will return incorrect values,
  16. ' However, it is faster than Wrap. Use Wrap for accurate results.
  17. Function QWrapF:Float(Value:Float,Minimum:Float,Maximum:Float)
  18. If Value > Maximum
  19. Return Minimum + (Value Mod Maximum)
  20. ElseIf Value < Minimum
  21. Return Maximum - Abs(Minimum - Value)
  22. EndIf
  23. Return Value
  24. End Function
  25. '#End Region
  26. '#Region Method: QWrapDegrees
  27. Function QWrapDegrees:Double(Value:Double)
  28. If Value > 359.0
  29. Return (0.0 + (Value Mod 359.0))
  30. ElseIf Value < 0.0
  31. Return (359.0 - Abs(0.0 - Value))
  32. EndIf
  33. Return Value
  34. End Function
  35. '#End Region
  36. '#Region Method: Wrap
  37. Function Wrap:Float(Value:Float,Minimum:Float,Maximum:Float)
  38. Local Difference:Float = Maximum - Minimum
  39. While ((Value < Minimum) Or (Value => Maximum))
  40. If Value => Maximum
  41. Value:- Difference
  42. Else
  43. If Value < Minimum
  44. Value:+ Difference
  45. EndIf
  46. EndIf
  47. Wend
  48. Return value
  49. End Function
  50. '#End Region
  51. '#Region Method: CurveValue
  52. Function CurveValue:Float(Current:Float,Destination:Float,Curve:Int)
  53. Current = Current + ( (Destination - Current) /Curve)
  54. Return Current
  55. End Function
  56. '#End Region
  57. End Type