summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBruno de Oliveira Abinader <bruno@mapbox.com>2019-03-04 09:33:19 +0200
committerBruno de Oliveira Abinader <bruno@mapbox.com>2019-03-06 09:47:05 +0200
commit6a438b1f77ff1e6b2d69037d2df7e4f4dc3b44b8 (patch)
tree947150493683f632dc2ec8ed4d689bbb446f9226
parent362aeadd03e2ad59db6999d2177fd0234bdf3130 (diff)
downloadqtlocation-mapboxgl-upstream/transform-refactor.tar.gz
[core] Added custom util::floorupstream/transform-refactor
-rw-r--r--include/mbgl/math/floor.hpp17
-rw-r--r--src/core-files.json1
-rw-r--r--src/mbgl/util/tile_cover.cpp11
3 files changed, 24 insertions, 5 deletions
diff --git a/include/mbgl/math/floor.hpp b/include/mbgl/math/floor.hpp
new file mode 100644
index 0000000000..692facf5de
--- /dev/null
+++ b/include/mbgl/math/floor.hpp
@@ -0,0 +1,17 @@
+#pragma once
+
+#include <cmath>
+#include <limits>
+#include <type_traits>
+
+namespace mbgl {
+namespace util {
+
+// https://en.cppreference.com/w/cpp/types/numeric_limits/epsilon
+template <typename T, typename = std::enable_if<std::is_floating_point<T>::value>>
+T floor(T a) {
+ return ::fabs(a) <= std::numeric_limits<T>::epsilon() ? 0 : ::floor(a);
+}
+
+} // namespace util
+} // namespace mbgl
diff --git a/src/core-files.json b/src/core-files.json
index 42a30a3ea8..82198f30ef 100644
--- a/src/core-files.json
+++ b/src/core-files.json
@@ -331,6 +331,7 @@
"mbgl/map/map_observer.hpp": "include/mbgl/map/map_observer.hpp",
"mbgl/map/mode.hpp": "include/mbgl/map/mode.hpp",
"mbgl/math/clamp.hpp": "include/mbgl/math/clamp.hpp",
+ "mbgl/math/floor.hpp": "include/mbgl/math/floor.hpp",
"mbgl/math/log2.hpp": "include/mbgl/math/log2.hpp",
"mbgl/math/minmax.hpp": "include/mbgl/math/minmax.hpp",
"mbgl/math/wrap.hpp": "include/mbgl/math/wrap.hpp",
diff --git a/src/mbgl/util/tile_cover.cpp b/src/mbgl/util/tile_cover.cpp
index aa6a581c86..1255c50bba 100644
--- a/src/mbgl/util/tile_cover.cpp
+++ b/src/mbgl/util/tile_cover.cpp
@@ -4,6 +4,7 @@
#include <mbgl/map/transform_state.hpp>
#include <mbgl/util/tile_cover_impl.hpp>
#include <mbgl/util/tile_coordinate.hpp>
+#include <mbgl/math/floor.hpp>
#include <mbgl/math/log2.hpp>
#include <functional>
@@ -35,8 +36,8 @@ struct edge {
// scan-line conversion
static void scanSpans(edge e0, edge e1, int32_t ymin, int32_t ymax, ScanLine scanLine) {
- double y0 = ::fmax(ymin, std::floor(e1.y0));
- double y1 = ::fmin(ymax, std::ceil(e1.y1));
+ double y0 = util::max(double(ymin), util::floor(e1.y0));
+ double y1 = util::min(double(ymax), std::ceil(e1.y1));
// sort edges by x-coordinate
if ((e0.x0 == e1.x0 && e0.y0 == e1.y0) ?
@@ -51,9 +52,9 @@ static void scanSpans(edge e0, edge e1, int32_t ymin, int32_t ymax, ScanLine sca
double d0 = e0.dx > 0; // use y + 1 to compute x0
double d1 = e1.dx < 0; // use y + 1 to compute x1
for (int32_t y = y0; y < y1; y++) {
- double x0 = m0 * ::fmax(0, ::fmin(e0.dy, y + d0 - e0.y0)) + e0.x0;
- double x1 = m1 * ::fmax(0, ::fmin(e1.dy, y + d1 - e1.y0)) + e1.x0;
- scanLine(std::floor(x1), std::ceil(x0), y);
+ double x0 = m0 * util::max(0.0, util::min(e0.dy, y + d0 - e0.y0)) + e0.x0;
+ double x1 = m1 * util::max(0.0, util::min(e1.dy, y + d1 - e1.y0)) + e1.x0;
+ scanLine(util::floor(x1), std::ceil(x0), y);
}
}