Chromium Code Reviews| Index: cc/math/clamp.h |
| diff --git a/cc/math/clamp.h b/cc/math/clamp.h |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..355ac0cbcfd322e8163d8157be113d7af8db2946 |
| --- /dev/null |
| +++ b/cc/math/clamp.h |
| @@ -0,0 +1,34 @@ |
| +// Copyright 2012 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#ifndef CC_MATH_CLAMP_H_ |
| +#define CC_MATH_CLAMP_H_ |
| + |
| +#include "cc/math/clamp.h" |
|
tfarina
2012/09/28 19:39:30
we are self including here?
|
| +#include "cc/math/int_point.h" |
|
tfarina
2012/09/28 19:39:30
I guess unused in this header file.
|
| +#include <limits> |
| + |
| +namespace ccmath { |
| + |
| +class Clamp { |
| +private: |
|
tfarina
2012/09/28 19:39:30
private sections after public
the other we usuall
|
| + template<typename FromType, typename ToType> |
| + static ToType ClampFromTo(FromType value) { |
| + ToType min = std::numeric_limits<ToType>::min(); |
| + ToType max = std::numeric_limits<ToType>::max(); |
| + if (value >= static_cast<FromType>(max)) |
| + return max; |
| + if (value <= static_cast<FromType>(min)) |
| + return min; |
| + return value; |
| + } |
| + |
| +public: |
| + static int ToInteger(double d) { return ClampFromTo<double, int>(d); } |
| + static int ToInteger(float f) { return ClampFromTo<float, int>(f); } |
| +}; |
|
tfarina
2012/09/28 19:39:30
DISALLOW_IMPLICIT_CONSTRUCTORS
|
| + |
| +} // namespace ccmath |
| + |
| +#endif // CC_MATH_CLAMP_H_ |