Bug 1167882 - Add utility functions MaxScaleRatio() and MinScaleRatio() to Units.h. r=kats

This commit is contained in:
Botond Ballo 2015-05-27 16:53:01 -04:00
parent 5bc1639df7
commit 1950fdd9b7

View File

@ -576,6 +576,21 @@ gfx::MarginTyped<dst> operator/(const gfx::MarginTyped<src>& aMargin, const gfx:
aMargin.left / aScale.xScale);
}
// Calculate the max or min or the ratios of the widths and heights of two
// sizes, returning a scale factor in the correct units.
template<class src, class dst>
gfx::ScaleFactor<src, dst> MaxScaleRatio(const gfx::SizeTyped<dst>& aDestSize, const gfx::SizeTyped<src>& aSrcSize) {
return gfx::ScaleFactor<src, dst>(std::max(aDestSize.width / aSrcSize.width,
aDestSize.height / aSrcSize.height));
}
template<class src, class dst>
gfx::ScaleFactor<src, dst> MinScaleRatio(const gfx::SizeTyped<dst>& aDestSize, const gfx::SizeTyped<src>& aSrcSize) {
return gfx::ScaleFactor<src, dst>(std::min(aDestSize.width / aSrcSize.width,
aDestSize.height / aSrcSize.height));
}
}
#endif