From 469186a47d6ac939acbd80754ed9be5c085bdc22 Mon Sep 17 00:00:00 2001 From: Dan Sinclair Date: Thu, 13 Jul 2017 13:39:34 -0400 Subject: Move CPWL_Utils::GetCenterSquare to CFX_FloatRect This method is working on the FloatRect content so move it to CFX_FloatRect. Change-Id: I60aabf6e3b86aa9acc59f86cff69347ec5fe5033 Reviewed-on: https://pdfium-review.googlesource.com/7712 Commit-Queue: dsinclair Reviewed-by: Tom Sepez --- core/fxcrt/fx_coordinates.cpp | 11 +++++++++++ 1 file changed, 11 insertions(+) (limited to 'core/fxcrt/fx_coordinates.cpp') 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(); -- cgit v1.2.3