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
This commit is contained in:
Moonchild 2023-10-30 16:25:29 +01:00 committed by roytam1
commit d4cdecec81

View file

@ -6,6 +6,7 @@
#ifndef MOZILLA_GFX_BASESIZE_H_
#define MOZILLA_GFX_BASESIZE_H_
#include <algorithm>
#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