strength.h 1.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344
  1. /*-----------------------------------------------------------------------------
  2. | Copyright (c) 2013-2017, Nucleic Development Team.
  3. |
  4. | Distributed under the terms of the Modified BSD License.
  5. |
  6. | The full license is in the file COPYING.txt, distributed with this software.
  7. |----------------------------------------------------------------------------*/
  8. #pragma once
  9. #include <algorithm>
  10. namespace kiwi
  11. {
  12. namespace strength
  13. {
  14. inline double create( double a, double b, double c, double w = 1.0 )
  15. {
  16. double result = 0.0;
  17. result += std::max( 0.0, std::min( 1000.0, a * w ) ) * 1000000.0;
  18. result += std::max( 0.0, std::min( 1000.0, b * w ) ) * 1000.0;
  19. result += std::max( 0.0, std::min( 1000.0, c * w ) );
  20. return result;
  21. }
  22. const double required = create( 1000.0, 1000.0, 1000.0 );
  23. const double strong = create( 1.0, 0.0, 0.0 );
  24. const double medium = create( 0.0, 1.0, 0.0 );
  25. const double weak = create( 0.0, 0.0, 1.0 );
  26. inline double clip( double value )
  27. {
  28. return std::max( 0.0, std::min( required, value ) );
  29. }
  30. } // namespace strength
  31. } // namespace kiwi