Add CFX_FloatRect::ToRoundedFxRect().

Unlike ToFxRect(), which floors the LBRT values. Also fix some nits.

Change-Id: I0680eebb09031807a14402ca30b13558ea5b56d9
Reviewed-on: https://pdfium-review.googlesource.com/20213
Reviewed-by: Ryan Harrison <rharrison@chromium.org>
Commit-Queue: Ryan Harrison <rharrison@chromium.org>
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index fe62d01..561f25d 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -47,10 +47,28 @@
 }
 
 CFX_FloatRect::CFX_FloatRect(const FX_RECT& rect) {
-  left = static_cast<float>(rect.left);
-  top = static_cast<float>(rect.bottom);
-  right = static_cast<float>(rect.right);
-  bottom = static_cast<float>(rect.top);
+  left = rect.left;
+  top = rect.bottom;
+  right = rect.right;
+  bottom = rect.top;
+}
+
+// static
+CFX_FloatRect CFX_FloatRect::GetBBox(const CFX_PointF* pPoints, int nPoints) {
+  if (nPoints == 0)
+    return CFX_FloatRect();
+
+  float min_x = pPoints->x;
+  float max_x = pPoints->x;
+  float min_y = pPoints->y;
+  float max_y = pPoints->y;
+  for (int i = 1; i < nPoints; i++) {
+    min_x = std::min(min_x, pPoints[i].x);
+    max_x = std::max(max_x, pPoints[i].x);
+    min_y = std::min(min_y, pPoints[i].y);
+    max_y = std::max(max_y, pPoints[i].y);
+  }
+  return CFX_FloatRect(min_x, min_y, max_x, max_y);
 }
 
 void CFX_FloatRect::Normalize() {
@@ -60,6 +78,13 @@
     std::swap(top, bottom);
 }
 
+void CFX_FloatRect::Reset() {
+  left = 0.0f;
+  right = 0.0f;
+  bottom = 0.0f;
+  top = 0.0f;
+}
+
 void CFX_FloatRect::Intersect(const CFX_FloatRect& other_rect) {
   Normalize();
   CFX_FloatRect other = other_rect;
@@ -68,9 +93,8 @@
   bottom = std::max(bottom, other.bottom);
   right = std::min(right, other.right);
   top = std::min(top, other.top);
-  if (left > right || bottom > top) {
-    left = bottom = right = top = 0;
-  }
+  if (left > right || bottom > top)
+    Reset();
 }
 
 void CFX_FloatRect::Union(const CFX_FloatRect& other_rect) {
@@ -168,22 +192,14 @@
   top = center_y + fHalfHeight * fScale;
 }
 
-// static
-CFX_FloatRect CFX_FloatRect::GetBBox(const CFX_PointF* pPoints, int nPoints) {
-  if (nPoints == 0)
-    return CFX_FloatRect();
+FX_RECT CFX_FloatRect::ToFxRect() const {
+  return FX_RECT(static_cast<int>(left), static_cast<int>(top),
+                 static_cast<int>(right), static_cast<int>(bottom));
+}
 
-  float min_x = pPoints->x;
-  float max_x = pPoints->x;
-  float min_y = pPoints->y;
-  float max_y = pPoints->y;
-  for (int i = 1; i < nPoints; i++) {
-    min_x = std::min(min_x, pPoints[i].x);
-    max_x = std::max(max_x, pPoints[i].x);
-    min_y = std::min(min_y, pPoints[i].y);
-    max_y = std::max(max_y, pPoints[i].y);
-  }
-  return CFX_FloatRect(min_x, min_y, max_x, max_y);
+FX_RECT CFX_FloatRect::ToRoundedFxRect() const {
+  return FX_RECT(FXSYS_round(left), FXSYS_round(top), FXSYS_round(right),
+                 FXSYS_round(bottom));
 }
 
 CFX_Matrix CFX_Matrix::GetInverse() const {
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h
index 5da8610..1767e33 100644
--- a/core/fxcrt/fx_coordinates.h
+++ b/core/fxcrt/fx_coordinates.h
@@ -233,14 +233,11 @@
 
   explicit CFX_FloatRect(const FX_RECT& rect);
 
+  static CFX_FloatRect GetBBox(const CFX_PointF* pPoints, int nPoints);
+
   void Normalize();
 
-  void Reset() {
-    left = 0.0f;
-    right = 0.0f;
-    bottom = 0.0f;
-    top = 0.0f;
-  }
+  void Reset();
 
   bool IsEmpty() const { return left >= right || bottom >= top; }
 
@@ -332,12 +329,8 @@
   void Scale(float fScale);
   void ScaleFromCenterPoint(float fScale);
 
-  static CFX_FloatRect GetBBox(const CFX_PointF* pPoints, int nPoints);
-
-  FX_RECT ToFxRect() const {
-    return FX_RECT(static_cast<int32_t>(left), static_cast<int32_t>(top),
-                   static_cast<int32_t>(right), static_cast<int32_t>(bottom));
-  }
+  FX_RECT ToFxRect() const;
+  FX_RECT ToRoundedFxRect() const;
 
   float left;
   float bottom;