From d4cdecec81c4b179513b76e098ae53361612430e Mon Sep 17 00:00:00 2001 From: Moonchild Date: Mon, 30 Oct 2023 16:25:29 +0100 Subject: [PATCH] Add Min() and Max() convenience functions for 2d point types. This will return (min(x1,x2), min(y1,y2)) and equivalent max from 2 passed-in (x1,y1) (x2,y2) points --- gfx/2d/BaseSize.h | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/gfx/2d/BaseSize.h b/gfx/2d/BaseSize.h index 7bcccc6299..f9f3fa4615 100644 --- a/gfx/2d/BaseSize.h +++ b/gfx/2d/BaseSize.h @@ -6,6 +6,7 @@ #ifndef MOZILLA_GFX_BASESIZE_H_ #define MOZILLA_GFX_BASESIZE_H_ +#include #include "mozilla/Attributes.h" namespace mozilla { @@ -92,6 +93,16 @@ struct BaseSize { 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