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 "base/strings/stringprintf.h" 8 9 namespace gfx { 10 11 std::string BoxF::ToString() const { 12 return base::StringPrintf("%s %fx%fx%f", 13 origin().ToString().c_str(), 14 width_, 15 height_, 16 depth_); 17 } 18 19 bool BoxF::IsEmpty() const { 20 return (width_ == 0 && height_ == 0) || 21 (width_ == 0 && depth_ == 0) || 22 (height_ == 0 && depth_ == 0); 23 } 24 25 void BoxF::Union(const BoxF& box) { 26 if (IsEmpty()) { 27 *this = box; 28 return; 29 } 30 if (box.IsEmpty()) 31 return; 32 33 float min_x = std::min(x(), box.x()); 34 float min_y = std::min(y(), box.y()); 35 float min_z = std::min(z(), box.z()); 36 float max_x = std::max(right(), box.right()); 37 float max_y = std::max(bottom(), box.bottom()); 38 float max_z = std::max(front(), box.front()); 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 BoxF UnionBoxes(const BoxF& a, const BoxF& b) { 47 BoxF result = a; 48 result.Union(b); 49 return result; 50 } 51 52 } // namespace gfx 53