Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include <cmath> | 5 #include <cmath> |
|
tfarina
2012/10/10 00:26:02
aren't you missing the include:
#include "ui/gfx/
danakj
2012/10/10 00:28:04
looks like it.
| |
| 6 #include <limits> | 6 #include <limits> |
| 7 | 7 |
| 8 namespace gfx { | 8 namespace gfx { |
| 9 | 9 |
| 10 int ClampToInt(float value) { | 10 int ClampToInt(float value) { |
| 11 if (value != value) | 11 if (value != value) |
| 12 return 0; // no int NaN. | 12 return 0; // no int NaN. |
| 13 if (value > std::numeric_limits<int>::max()) | 13 if (value > std::numeric_limits<int>::max()) |
| 14 return std::numeric_limits<int>::max(); | 14 return std::numeric_limits<int>::max(); |
| 15 if (value < std::numeric_limits<int>::min()) | 15 if (value < std::numeric_limits<int>::min()) |
| 16 return std::numeric_limits<int>::min(); | 16 return std::numeric_limits<int>::min(); |
| 17 return static_cast<int>(value); | 17 return static_cast<int>(value); |
| 18 } | 18 } |
| 19 | 19 |
| 20 int ToFlooredInt(float value) { | 20 int ToFlooredInt(float value) { |
| 21 return ClampToInt(std::floor(value)); | 21 return ClampToInt(std::floor(value)); |
| 22 } | 22 } |
| 23 | 23 |
| 24 int ToCeiledInt(float value) { | 24 int ToCeiledInt(float value) { |
| 25 return ClampToInt(std::ceil(value)); | 25 return ClampToInt(std::ceil(value)); |
| 26 } | 26 } |
| 27 | 27 |
| 28 int ToRoundedInt(float value) { | |
|
tfarina
2012/10/10 00:26:02
Looks like this is what SymmetricRound() is trying
danakj
2012/10/10 00:28:04
cool :)
| |
| 29 float rounded; | |
| 30 if (value >= 0.0f) | |
| 31 rounded = std::floor(value + 0.5f); | |
| 32 else | |
| 33 rounded = std::ceil(value - 0.5f); | |
| 34 return ClampToInt(rounded); | |
| 35 } | |
| 36 | |
| 28 } // namespace gfx | 37 } // namespace gfx |
| 29 | 38 |
|
tfarina
2012/10/10 00:26:02
rm extra blank line.
danakj
2012/10/10 00:28:04
Done.
| |
| OLD | NEW |