b2Stat.cpp 1.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. /*
  2. * Copyright (c) 2013 Google, Inc.
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. * Permission is granted to anyone to use this software for any purpose,
  8. * including commercial applications, and to alter it and redistribute it
  9. * freely, subject to the following restrictions:
  10. * 1. The origin of this software must not be misrepresented; you must not
  11. * claim that you wrote the original software. If you use this software
  12. * in a product, an acknowledgment in the product documentation would be
  13. * appreciated but is not required.
  14. * 2. Altered source versions must be plainly marked as such, and must not be
  15. * misrepresented as being the original software.
  16. * 3. This notice may not be removed or altered from any source distribution.
  17. */
  18. #include "b2Stat.h"
  19. #include <algorithm>
  20. #include <cfloat>
  21. b2Stat::b2Stat()
  22. {
  23. Clear();
  24. }
  25. void b2Stat::Record( float32 t )
  26. {
  27. m_total += t;
  28. m_min = std::min(m_min,t);
  29. m_max = std::max(m_max,t);
  30. m_count++;
  31. }
  32. int b2Stat::GetCount() const
  33. {
  34. return m_count;
  35. }
  36. float32 b2Stat::GetMean() const
  37. {
  38. if (m_count == 0)
  39. {
  40. return 0.0f;
  41. }
  42. return (float32)(m_total / m_count);
  43. }
  44. float32 b2Stat::GetMin() const
  45. {
  46. return m_min;
  47. }
  48. float32 b2Stat::GetMax() const
  49. {
  50. return m_max;
  51. }
  52. void b2Stat::Clear()
  53. {
  54. m_count = 0;
  55. m_total = 0;
  56. m_min = FLT_MAX;
  57. m_max = -FLT_MAX;
  58. }