summaryrefslogtreecommitdiff
path: root/include
diff options
context:
space:
mode:
authorDane Springmeyer <dane@mapbox.com>2015-05-08 15:19:41 -0700
committerDane Springmeyer <dane@mapbox.com>2015-05-08 15:19:41 -0700
commit768c259495200ff3214dd4eb1284aaa49a7a814c (patch)
tree57253e67be6051d469d47d3daa40bd6d968ffb39 /include
parent5ef362bbc45e7b553f5d21a5368e09dd243a8a0c (diff)
downloadqtlocation-mapboxgl-768c259495200ff3214dd4eb1284aaa49a7a814c.tar.gz
fix division by zero conditions
Diffstat (limited to 'include')
-rw-r--r--include/mbgl/util/math.hpp6
1 files changed, 5 insertions, 1 deletions
diff --git a/include/mbgl/util/math.hpp b/include/mbgl/util/math.hpp
index 6dea628e93..5fcf3dce80 100644
--- a/include/mbgl/util/math.hpp
+++ b/include/mbgl/util/math.hpp
@@ -100,7 +100,11 @@ inline T mag(const S& a) {
template <typename S>
inline S unit(const S& a) {
- return a * (1 / mag(a));
+ auto magnitude = mag(a);
+ if (magnitude == 0) {
+ return a;
+ }
+ return a * (1 / magnitude);
}
template <typename T>