Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(26)

Side by Side Diff: ui/gfx/quad_f.cc

Issue 15298013: ui: Inline QuadF::BoundingBox() (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ui/gfx/quad_f.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 "ui/gfx/quad_f.h" 5 #include "ui/gfx/quad_f.h"
6 6
7 #include <cmath>
8 #include <limits> 7 #include <limits>
9 8
10 #include "base/stringprintf.h" 9 #include "base/stringprintf.h"
11 10
12 namespace gfx { 11 namespace gfx {
13 12
14 void QuadF::operator=(const RectF& rect) { 13 void QuadF::operator=(const RectF& rect) {
15 p1_ = PointF(rect.x(), rect.y()); 14 p1_ = PointF(rect.x(), rect.y());
16 p2_ = PointF(rect.right(), rect.y()); 15 p2_ = PointF(rect.right(), rect.y());
17 p3_ = PointF(rect.right(), rect.bottom()); 16 p3_ = PointF(rect.right(), rect.bottom());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
85 // Use the barycentric coordinates to test if |point| is inside the 84 // Use the barycentric coordinates to test if |point| is inside the
86 // triangle (r1, r2, r2). 85 // triangle (r1, r2, r2).
87 return (v >= 0) && (w >= 0) && (u >= 0); 86 return (v >= 0) && (w >= 0) && (u >= 0);
88 } 87 }
89 88
90 bool QuadF::Contains(const PointF& point) const { 89 bool QuadF::Contains(const PointF& point) const {
91 return PointIsInTriangle(point, p1_, p2_, p3_) 90 return PointIsInTriangle(point, p1_, p2_, p3_)
92 || PointIsInTriangle(point, p1_, p3_, p4_); 91 || PointIsInTriangle(point, p1_, p3_, p4_);
93 } 92 }
94 93
95 RectF QuadF::BoundingBox() const {
96 float rl = std::min(std::min(p1_.x(), p2_.x()), std::min(p3_.x(), p4_.x()));
97 float rr = std::max(std::max(p1_.x(), p2_.x()), std::max(p3_.x(), p4_.x()));
98 float rt = std::min(std::min(p1_.y(), p2_.y()), std::min(p3_.y(), p4_.y()));
99 float rb = std::max(std::max(p1_.y(), p2_.y()), std::max(p3_.y(), p4_.y()));
100 return RectF(rl, rt, rr - rl, rb - rt);
101 }
102
103 void QuadF::Scale(float x_scale, float y_scale) { 94 void QuadF::Scale(float x_scale, float y_scale) {
104 p1_.Scale(x_scale, y_scale); 95 p1_.Scale(x_scale, y_scale);
105 p2_.Scale(x_scale, y_scale); 96 p2_.Scale(x_scale, y_scale);
106 p3_.Scale(x_scale, y_scale); 97 p3_.Scale(x_scale, y_scale);
107 p4_.Scale(x_scale, y_scale); 98 p4_.Scale(x_scale, y_scale);
108 } 99 }
109 100
110 void QuadF::operator+=(const Vector2dF& rhs) { 101 void QuadF::operator+=(const Vector2dF& rhs) {
111 p1_ += rhs; 102 p1_ += rhs;
112 p2_ += rhs; 103 p2_ += rhs;
(...skipping 14 matching lines...) Expand all
127 return result; 118 return result;
128 } 119 }
129 120
130 QuadF operator-(const QuadF& lhs, const Vector2dF& rhs) { 121 QuadF operator-(const QuadF& lhs, const Vector2dF& rhs) {
131 QuadF result = lhs; 122 QuadF result = lhs;
132 result -= rhs; 123 result -= rhs;
133 return result; 124 return result;
134 } 125 }
135 126
136 } // namespace gfx 127 } // namespace gfx
OLDNEW
« no previous file with comments | « ui/gfx/quad_f.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698