| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/box_f.h" | 5 #include "ui/gfx/box_f.h" |
| 6 | 6 |
| 7 #include <algorithm> | 7 #include <algorithm> |
| 8 | 8 |
| 9 #include "base/logging.h" |
| 9 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| 10 | 11 |
| 11 namespace gfx { | 12 namespace gfx { |
| 12 | 13 |
| 13 std::string BoxF::ToString() const { | 14 std::string BoxF::ToString() const { |
| 14 return base::StringPrintf("%s %fx%fx%f", | 15 return base::StringPrintf("%s %fx%fx%f", |
| 15 origin().ToString().c_str(), | 16 origin().ToString().c_str(), |
| 16 width_, | 17 width_, |
| 17 height_, | 18 height_, |
| 18 depth_); | 19 depth_); |
| 19 } | 20 } |
| 20 | 21 |
| 21 bool BoxF::IsEmpty() const { | 22 bool BoxF::IsEmpty() const { |
| 22 return (width_ == 0 && height_ == 0) || | 23 return (width_ == 0 && height_ == 0) || |
| 23 (width_ == 0 && depth_ == 0) || | 24 (width_ == 0 && depth_ == 0) || |
| 24 (height_ == 0 && depth_ == 0); | 25 (height_ == 0 && depth_ == 0); |
| 25 } | 26 } |
| 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 |
| 27 void BoxF::Union(const BoxF& box) { | 46 void BoxF::Union(const BoxF& box) { |
| 28 if (IsEmpty()) { | 47 if (IsEmpty()) { |
| 29 *this = box; | 48 *this = box; |
| 30 return; | 49 return; |
| 31 } | 50 } |
| 32 if (box.IsEmpty()) | 51 if (box.IsEmpty()) |
| 33 return; | 52 return; |
| 34 | 53 |
| 35 float min_x = std::min(x(), box.x()); | 54 ExpandTo(box.origin(), gfx::Point3F(box.right(), box.bottom(), box.front())); |
| 36 float min_y = std::min(y(), box.y()); | 55 } |
| 37 float min_z = std::min(z(), box.z()); | |
| 38 float max_x = std::max(right(), box.right()); | |
| 39 float max_y = std::max(bottom(), box.bottom()); | |
| 40 float max_z = std::max(front(), box.front()); | |
| 41 | 56 |
| 42 origin_.SetPoint(min_x, min_y, min_z); | 57 void BoxF::ExpandTo(const Point3F& point) { |
| 43 width_ = max_x - min_x; | 58 ExpandTo(point, point); |
| 44 height_ = max_y - min_y; | |
| 45 depth_ = max_z - min_z; | |
| 46 } | 59 } |
| 47 | 60 |
| 48 BoxF UnionBoxes(const BoxF& a, const BoxF& b) { | 61 BoxF UnionBoxes(const BoxF& a, const BoxF& b) { |
| 49 BoxF result = a; | 62 BoxF result = a; |
| 50 result.Union(b); | 63 result.Union(b); |
| 51 return result; | 64 return result; |
| 52 } | 65 } |
| 53 | 66 |
| 54 } // namespace gfx | 67 } // namespace gfx |
| OLD | NEW |