OLD | NEW |
1 // Copyright 2010 The Chromium Authors. All rights reserved. | 1 // Copyright 2010 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 #ifndef CC_GEOMETRY_H_ | 5 #ifndef CC_GEOMETRY_H_ |
6 #define CC_GEOMETRY_H_ | 6 #define CC_GEOMETRY_H_ |
7 | 7 |
8 #include "ui/gfx/size.h" | 8 #include "ui/gfx/rect.h" |
| 9 #include "ui/gfx/rect_f.h" |
| 10 #include "ui/gfx/vector2d.h" |
9 #include "ui/gfx/vector2d_f.h" | 11 #include "ui/gfx/vector2d_f.h" |
10 #include <cmath> | |
11 | 12 |
12 namespace cc { | 13 namespace cc { |
13 | 14 |
14 inline gfx::Size ClampSizeFromAbove(gfx::Size s, gfx::Size other) { | 15 inline gfx::Size ClampSizeFromAbove(gfx::Size s, gfx::Size other) { |
15 return gfx::Size(s.width() < other.width() ? s.width() : other.width(), | 16 return gfx::Size(s.width() < other.width() ? s.width() : other.width(), |
16 s.height() < other.height() ? s.height() : other.height()); | 17 s.height() < other.height() ? s.height() : other.height()); |
17 } | 18 } |
18 | 19 |
| 20 inline gfx::Vector2dF ClampFromAbove(gfx::Vector2dF s, gfx::Vector2dF max) { |
| 21 return gfx::Vector2dF(s.x() < max.x() ? s.x() : max.x(), |
| 22 s.y() < max.y() ? s.y() : max.y()); |
| 23 } |
| 24 |
| 25 inline gfx::Vector2dF ClampFromBelow(gfx::Vector2dF s, gfx::Vector2dF min) { |
| 26 return gfx::Vector2dF(s.x() > min.x() ? s.x() : min.x(), |
| 27 s.y() > min.y() ? s.y() : min.y()); |
| 28 } |
| 29 |
| 30 inline gfx::Vector2d ClampFromAbove(gfx::Vector2d s, gfx::Vector2d max) { |
| 31 return gfx::Vector2d(s.x() < max.x() ? s.x() : max.x(), |
| 32 s.y() < max.y() ? s.y() : max.y()); |
| 33 } |
| 34 |
| 35 inline gfx::Vector2d ClampFromBelow(gfx::Vector2d s, gfx::Vector2d min) { |
| 36 return gfx::Vector2d(s.x() > min.x() ? s.x() : min.x(), |
| 37 s.y() > min.y() ? s.y() : min.y()); |
| 38 } |
| 39 |
| 40 inline gfx::PointF ClampFromAbove(gfx::PointF s, gfx::PointF max) { |
| 41 return gfx::PointF(s.x() < max.x() ? s.x() : max.x(), |
| 42 s.y() < max.y() ? s.y() : max.y()); |
| 43 } |
| 44 |
| 45 inline gfx::PointF ClampFromBelow(gfx::PointF s, gfx::PointF min) { |
| 46 return gfx::PointF(s.x() > min.x() ? s.x() : min.x(), |
| 47 s.y() > min.y() ? s.y() : min.y()); |
| 48 } |
| 49 |
| 50 inline gfx::Point ClampFromAbove(gfx::Point s, gfx::Point max) { |
| 51 return gfx::Point(s.x() < max.x() ? s.x() : max.x(), |
| 52 s.y() < max.y() ? s.y() : max.y()); |
| 53 } |
| 54 |
| 55 inline gfx::Point ClampFromBelow(gfx::Point s, gfx::Point min) { |
| 56 return gfx::Point(s.x() > min.x() ? s.x() : min.x(), |
| 57 s.y() > min.y() ? s.y() : min.y()); |
| 58 } |
| 59 |
| 60 inline gfx::Point BottomRight(gfx::Rect rect) { |
| 61 return gfx::Point(rect.right(), rect.bottom()); |
| 62 } |
| 63 |
| 64 inline gfx::PointF BottomRight(gfx::RectF rect) { |
| 65 return gfx::PointF(rect.right(), rect.bottom()); |
| 66 } |
| 67 |
| 68 // Return a vector that is |v| scaled by the given scale factors along each |
| 69 // axis. |
| 70 inline gfx::Vector2dF ScaleVector2d(gfx::Vector2dF v, float x_scale, float y_sca
le) { |
| 71 gfx::Vector2dF scaled = v; |
| 72 scaled.Scale(x_scale, y_scale); |
| 73 return scaled; |
| 74 } |
| 75 |
| 76 // Return a vector that is |v| scaled by the given scale factor. |
| 77 inline gfx::Vector2dF ScaleVector2d(gfx::Vector2dF v, float scale) { |
| 78 return ScaleVector2d(v, scale, scale); |
| 79 } |
| 80 |
19 } // namespace cc | 81 } // namespace cc |
20 | 82 |
21 #endif // CC_GEOMETRY_H_ | 83 #endif // CC_GEOMETRY_H_ |
OLD | NEW |