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

Unified Diff: ui/gfx/box_f.cc

Issue 25518002: Add BoxF::ExpandTo (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: . Created 7 years, 3 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 side-by-side diff with in-line comments
Download patch
Index: ui/gfx/box_f.cc
diff --git a/ui/gfx/box_f.cc b/ui/gfx/box_f.cc
index efb579671457c9d78d3dbac1630207559ebd3d2a..cc6a1eef2314c3e443e9fea744673de39cc616d6 100644
--- a/ui/gfx/box_f.cc
+++ b/ui/gfx/box_f.cc
@@ -24,6 +24,20 @@ bool BoxF::IsEmpty() const {
(height_ == 0 && depth_ == 0);
}
+void BoxF::ExpandTo(const Point3F& min, const Point3F& max) {
+ float min_x = std::min(x(), min.x());
danakj 2013/10/01 14:23:44 DCHECK() that min <= max please.
+ float min_y = std::min(y(), min.y());
+ float min_z = std::min(z(), min.z());
+ float max_x = std::max(right(), max.x());
+ float max_y = std::max(bottom(), max.y());
+ float max_z = std::max(front(), max.z());
+
+ origin_.SetPoint(min_x, min_y, min_z);
+ width_ = max_x - min_x;
+ height_ = max_y - min_y;
+ depth_ = max_z - min_z;
+}
+
void BoxF::Union(const BoxF& box) {
if (IsEmpty()) {
*this = box;
@@ -32,17 +46,11 @@ void BoxF::Union(const BoxF& box) {
if (box.IsEmpty())
return;
- float min_x = std::min(x(), box.x());
- float min_y = std::min(y(), box.y());
- float min_z = std::min(z(), box.z());
- float max_x = std::max(right(), box.right());
- float max_y = std::max(bottom(), box.bottom());
- float max_z = std::max(front(), box.front());
+ ExpandTo(box.origin(), gfx::Point3F(box.right(), box.bottom(), box.front()));
danakj 2013/10/01 14:23:44 What happens if |box| is entirely left/above |this
+}
- origin_.SetPoint(min_x, min_y, min_z);
- width_ = max_x - min_x;
- height_ = max_y - min_y;
- depth_ = max_z - min_z;
+void BoxF::ExpandTo(const Point3F& point) {
+ ExpandTo(point, point);
}
BoxF UnionBoxes(const BoxF& a, const BoxF& b) {

Powered by Google App Engine
This is Rietveld 408576698