summaryrefslogtreecommitdiff
path: root/core/fxcrt/fx_coordinates.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'core/fxcrt/fx_coordinates.cpp')
-rw-r--r--core/fxcrt/fx_coordinates.cpp11
1 files changed, 11 insertions, 0 deletions
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index 0b6aed44cc..752591d3ed 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -157,6 +157,17 @@ FX_RECT CFX_FloatRect::GetClosestRect() const {
return rect;
}
+CFX_FloatRect CFX_FloatRect::GetCenterSquare() const {
+ float fWidth = right - left;
+ float fHeight = top - bottom;
+ float fHalfWidth = (fWidth > fHeight) ? fHeight / 2 : fWidth / 2;
+
+ float fCenterX = (left + right) / 2.0f;
+ float fCenterY = (top + bottom) / 2.0f;
+ return CFX_FloatRect(fCenterX - fHalfWidth, fCenterY - fHalfWidth,
+ fCenterX + fHalfWidth, fCenterY + fHalfWidth);
+}
+
bool CFX_FloatRect::Contains(const CFX_PointF& point) const {
CFX_FloatRect n1(*this);
n1.Normalize();