Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #ifndef CC_MATH_CLAMP_H_ | |
| 6 #define CC_MATH_CLAMP_H_ | |
| 7 | |
| 8 #include "cc/math/clamp.h" | |
|
tfarina
2012/09/28 19:39:30
we are self including here?
| |
| 9 #include "cc/math/int_point.h" | |
|
tfarina
2012/09/28 19:39:30
I guess unused in this header file.
| |
| 10 #include <limits> | |
| 11 | |
| 12 namespace ccmath { | |
| 13 | |
| 14 class Clamp { | |
| 15 private: | |
|
tfarina
2012/09/28 19:39:30
private sections after public
the other we usuall
| |
| 16 template<typename FromType, typename ToType> | |
| 17 static ToType ClampFromTo(FromType value) { | |
| 18 ToType min = std::numeric_limits<ToType>::min(); | |
| 19 ToType max = std::numeric_limits<ToType>::max(); | |
| 20 if (value >= static_cast<FromType>(max)) | |
| 21 return max; | |
| 22 if (value <= static_cast<FromType>(min)) | |
| 23 return min; | |
| 24 return value; | |
| 25 } | |
| 26 | |
| 27 public: | |
| 28 static int ToInteger(double d) { return ClampFromTo<double, int>(d); } | |
| 29 static int ToInteger(float f) { return ClampFromTo<float, int>(f); } | |
| 30 }; | |
|
tfarina
2012/09/28 19:39:30
DISALLOW_IMPLICIT_CONSTRUCTORS
| |
| 31 | |
| 32 } // namespace ccmath | |
| 33 | |
| 34 #endif // CC_MATH_CLAMP_H_ | |
| OLD | NEW |