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

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

Issue 109433013: Move geometric types to a separate, more lightweight target. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years 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
OLDNEW
(Empty)
1 // Copyright 2013 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 #include "ui/gfx/box_f.h"
6
7 #include <algorithm>
8
9 #include "base/logging.h"
10 #include "base/strings/stringprintf.h"
11
12 namespace gfx {
13
14 std::string BoxF::ToString() const {
15 return base::StringPrintf("%s %fx%fx%f",
16 origin().ToString().c_str(),
17 width_,
18 height_,
19 depth_);
20 }
21
22 bool BoxF::IsEmpty() const {
23 return (width_ == 0 && height_ == 0) ||
24 (width_ == 0 && depth_ == 0) ||
25 (height_ == 0 && depth_ == 0);
26 }
27
28 void BoxF::ExpandTo(const Point3F& min, const Point3F& max) {
29 DCHECK_LE(min.x(), max.x());
30 DCHECK_LE(min.y(), max.y());
31 DCHECK_LE(min.z(), max.z());
32
33 float min_x = std::min(x(), min.x());
34 float min_y = std::min(y(), min.y());
35 float min_z = std::min(z(), min.z());
36 float max_x = std::max(right(), max.x());
37 float max_y = std::max(bottom(), max.y());
38 float max_z = std::max(front(), max.z());
39
40 origin_.SetPoint(min_x, min_y, min_z);
41 width_ = max_x - min_x;
42 height_ = max_y - min_y;
43 depth_ = max_z - min_z;
44 }
45
46 void BoxF::Union(const BoxF& box) {
47 if (IsEmpty()) {
48 *this = box;
49 return;
50 }
51 if (box.IsEmpty())
52 return;
53 ExpandTo(box);
54 }
55
56 void BoxF::ExpandTo(const Point3F& point) {
57 ExpandTo(point, point);
58 }
59
60 void BoxF::ExpandTo(const BoxF& box) {
61 ExpandTo(box.origin(), gfx::Point3F(box.right(), box.bottom(), box.front()));
62 }
63
64 BoxF UnionBoxes(const BoxF& a, const BoxF& b) {
65 BoxF result = a;
66 result.Union(b);
67 return result;
68 }
69
70 } // namespace gfx
OLDNEW
« ui/aura/aura.gyp ('K') | « ui/gfx/box_f.h ('k') | ui/gfx/box_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698