Remove math.h from fx_coordinates.h.
Move code in fx_coordinates.h that require math.h to fx_coordinates.cpp.
While doing this, only instantiate the template specializations that are
actually in use, and switch from sqrt() to FXSYS_sqrt2().
Change-Id: If3a938ad06b29b85c9eec5fb8f3f4c1d4d606f5a
Reviewed-on: https://pdfium-review.googlesource.com/c/pdfium/+/83893
Commit-Queue: Lei Zhang <thestig@chromium.org>
Reviewed-by: Tom Sepez <tsepez@chromium.org>
diff --git a/core/fxcrt/fx_coordinates.cpp b/core/fxcrt/fx_coordinates.cpp
index 66ee9dc..ba5d92f 100644
--- a/core/fxcrt/fx_coordinates.cpp
+++ b/core/fxcrt/fx_coordinates.cpp
@@ -6,6 +6,8 @@
#include "core/fxcrt/fx_coordinates.h"
+#include <math.h>
+
#include <utility>
#include "build/build_config.h"
@@ -60,6 +62,21 @@
} // namespace
+template <>
+float CFX_VTemplate<float>::Length() const {
+ return FXSYS_sqrt2(x, y);
+}
+
+template <>
+void CFX_VTemplate<float>::Normalize() {
+ float fLen = Length();
+ if (fLen < 0.0001f)
+ return;
+
+ x /= fLen;
+ y /= fLen;
+}
+
bool FX_RECT::Valid() const {
FX_SAFE_INT32 w = right;
FX_SAFE_INT32 h = bottom;
diff --git a/core/fxcrt/fx_coordinates.h b/core/fxcrt/fx_coordinates.h
index f31cad8..abffc7f 100644
--- a/core/fxcrt/fx_coordinates.h
+++ b/core/fxcrt/fx_coordinates.h
@@ -7,7 +7,6 @@
#ifndef CORE_FXCRT_FX_COORDINATES_H_
#define CORE_FXCRT_FX_COORDINATES_H_
-#include <math.h>
#include <stdint.h>
#include <algorithm>
@@ -149,15 +148,8 @@
const CFX_PTemplate<BaseType>& point2)
: CFX_PTemplate<BaseType>(point2.x - point1.x, point2.y - point1.y) {}
- float Length() const { return sqrt(x * x + y * y); }
- void Normalize() {
- float fLen = Length();
- if (fLen < 0.0001f)
- return;
-
- x /= fLen;
- y /= fLen;
- }
+ float Length() const;
+ void Normalize();
};
using CFX_Vector = CFX_VTemplate<int32_t>;
using CFX_VectorF = CFX_VTemplate<float>;