Replace FXSYS_sqrt2() with hypotf()
Replace the FXSYS_sqrt2() with the hypotf() from the <math.h> library
in C++.
Bug: 352359909
Change-Id: I585a3ef5ac87e67d04e39c580b42e94e9c45b626
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/122050
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@google.com>
diff --git a/core/fpdfapi/page/cpdf_textstate.cpp b/core/fpdfapi/page/cpdf_textstate.cpp
index 146202e..74bbab0 100644
--- a/core/fpdfapi/page/cpdf_textstate.cpp
+++ b/core/fpdfapi/page/cpdf_textstate.cpp
@@ -122,7 +122,7 @@
}
float CPDF_TextState::TextData::GetFontSizeH() const {
- return fabs(FXSYS_sqrt2(m_Matrix[0], m_Matrix[2]) * m_FontSize);
+ return fabs(hypotf(m_Matrix[0], m_Matrix[2]) * m_FontSize);
}
bool SetTextRenderingModeFromInt(int iMode, TextRenderingMode* mode) {
diff --git a/core/fpdfapi/render/cpdf_rendershading.cpp b/core/fpdfapi/render/cpdf_rendershading.cpp
index f44b1b8..d56128e 100644
--- a/core/fpdfapi/render/cpdf_rendershading.cpp
+++ b/core/fpdfapi/render/cpdf_rendershading.cpp
@@ -204,7 +204,7 @@
int width = pBitmap->GetWidth();
int height = pBitmap->GetHeight();
- bool bDecreasing = dr < 0 && static_cast<int>(FXSYS_sqrt2(dx, dy)) < -dr;
+ bool bDecreasing = dr < 0 && static_cast<int>(hypotf(dx, dy)) < -dr;
CFX_Matrix matrix = mtObject2Bitmap.GetInverse();
for (int row = 0; row < height; row++) {
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index a05d298..54c3609 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -66,7 +66,7 @@
template <>
float CFX_VTemplate<float>::Length() const {
- return FXSYS_sqrt2(x, y);
+ return hypotf(x, y);
}
template <>
@@ -454,7 +454,7 @@
return (a > 0 ? a : -a);
if (a == 0)
return (b > 0 ? b : -b);
- return FXSYS_sqrt2(a, b);
+ return hypotf(a, b);
}
float CFX_Matrix::GetYUnit() const {
@@ -462,7 +462,7 @@
return (d > 0 ? d : -d);
if (d == 0)
return (c > 0 ? c : -c);
- return FXSYS_sqrt2(c, d);
+ return hypotf(c, d);
}
CFX_FloatRect CFX_Matrix::GetUnitRect() const {
@@ -472,7 +472,7 @@
float CFX_Matrix::TransformXDistance(float dx) const {
float fx = a * dx;
float fy = b * dx;
- return FXSYS_sqrt2(fx, fy);
+ return hypotf(fx, fy);
}
float CFX_Matrix::TransformDistance(float distance) const {
diff --git a/core/fxge/cfx_path.cpp b/core/fxge/cfx_path.cpp
index 6549feb..c19e4ec 100644
--- a/core/fxge/cfx_path.cpp
+++ b/core/fxge/cfx_path.cpp
@@ -136,7 +136,7 @@
}
CFX_PointF diff = end_pos - start_pos;
- float ll = FXSYS_sqrt2(diff.x, diff.y);
+ float ll = hypotf(diff.x, diff.y);
float mx = end_pos.x + hw * diff.x / ll;
float my = end_pos.y + hw * diff.y / ll;
float dx1 = hw * diff.y / ll;
@@ -175,14 +175,14 @@
CFX_PointF start_to_mid = start_pos - mid_pos;
start_k = (mid_pos.y - start_pos.y) / (mid_pos.x - start_pos.x);
start_c = mid_pos.y - (start_k * mid_pos.x);
- start_len = FXSYS_sqrt2(start_to_mid.x, start_to_mid.y);
+ start_len = hypotf(start_to_mid.x, start_to_mid.y);
start_dc = fabsf(half_width * start_len / start_to_mid.x);
}
if (!bEndVert) {
CFX_PointF end_to_mid = end_pos - mid_pos;
end_k = end_to_mid.y / end_to_mid.x;
end_c = mid_pos.y - (end_k * mid_pos.x);
- end_len = FXSYS_sqrt2(end_to_mid.x, end_to_mid.y);
+ end_len = hypotf(end_to_mid.x, end_to_mid.y);
end_dc = fabs(half_width * end_len / end_to_mid.x);
}
if (bStartVert) {
diff --git a/core/fxge/dib/cfx_imagetransformer.cpp b/core/fxge/dib/cfx_imagetransformer.cpp
index 46812b7..bb3cca9 100644
--- a/core/fxge/dib/cfx_imagetransformer.cpp
+++ b/core/fxge/dib/cfx_imagetransformer.cpp
@@ -177,10 +177,8 @@
return;
}
- int stretch_width =
- static_cast<int>(ceil(FXSYS_sqrt2(m_matrix.a, m_matrix.b)));
- int stretch_height =
- static_cast<int>(ceil(FXSYS_sqrt2(m_matrix.c, m_matrix.d)));
+ int stretch_width = static_cast<int>(ceil(hypotf(m_matrix.a, m_matrix.b)));
+ int stretch_height = static_cast<int>(ceil(hypotf(m_matrix.c, m_matrix.d)));
CFX_Matrix stretch_to_dest(1.0f, 0.0f, 0.0f, -1.0f, 0.0f, stretch_height);
stretch_to_dest.Concat(
CFX_Matrix(m_matrix.a / stretch_width, m_matrix.b / stretch_width,
diff --git a/xfa/fxfa/parser/cxfa_radial.cpp b/xfa/fxfa/parser/cxfa_radial.cpp
index 4f4f557..c10f120 100644
--- a/xfa/fxfa/parser/cxfa_radial.cpp
+++ b/xfa/fxfa/parser/cxfa_radial.cpp
@@ -66,7 +66,7 @@
if (!IsToEdge())
std::swap(crStart, crEnd);
- float end_radius = FXSYS_sqrt2(rtFill.Width(), rtFill.Height()) / 2;
+ float end_radius = hypotf(rtFill.Width(), rtFill.Height()) / 2;
CFGAS_GEShading shading(rtFill.Center(), rtFill.Center(), 0, end_radius, true,
true, crStart, crEnd);