Bug 1321412 - Add Min() and Max() functions to BaseSize. r=kats
authorBotond Ballo <botond@mozilla.com>
Wed, 23 Nov 2016 19:27:27 -0500
changeset 325902 313fe04267d6e44bb4b5219502d2fd5177b4d8a4
parent 325901 68aaa196ae5acc81212e2da847e82cc516a3b16b
child 325903 592f556e7644341b398894b052b587cac16f5fd6
push id31080
push usercbook@mozilla.com
push dateThu, 15 Dec 2016 13:16:19 +0000
treeherdermozilla-central@f14683f7fad5 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewerskats
bugs1321412
milestone53.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1321412 - Add Min() and Max() functions to BaseSize. r=kats MozReview-Commit-ID: 6GTzkpwwDNu
gfx/2d/BaseSize.h
--- a/gfx/2d/BaseSize.h
+++ b/gfx/2d/BaseSize.h
@@ -1,16 +1,17 @@
 /* -*- Mode: C++; tab-width: 2; indent-tabs-mode: nil; c-basic-offset: 2 -*-
  * This Source Code Form is subject to the terms of the Mozilla Public
  * License, v. 2.0. If a copy of the MPL was not distributed with this
  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
 
 #ifndef MOZILLA_GFX_BASESIZE_H_
 #define MOZILLA_GFX_BASESIZE_H_
 
+#include <algorithm>
 #include "mozilla/Attributes.h"
 
 namespace mozilla {
 namespace gfx {
 
 /**
  * Do not use this class directly. Subclass it, pass that subclass as the
  * Sub parameter, and only use that subclass. This allows methods to safely
@@ -87,14 +88,24 @@ struct BaseSize {
   }
 
   Sub operator*(const Sub& aSize) const {
     return Sub(width * aSize.width, height * aSize.height);
   }
   Sub operator/(const Sub& aSize) const {
     return Sub(width / aSize.width, height / aSize.height);
   }
+
+  friend Sub Min(const Sub& aA, const Sub& aB) {
+    return Sub(std::min(aA.width, aB.width),
+               std::min(aA.height, aB.height));
+  }
+
+  friend Sub Max(const Sub& aA, const Sub& aB) {
+    return Sub(std::max(aA.width, aB.width),
+               std::max(aA.height, aB.height));
+  }
 };
 
 } // namespace gfx
 } // namespace mozilla
 
 #endif /* MOZILLA_GFX_BASESIZE_H_ */