From 768c259495200ff3214dd4eb1284aaa49a7a814c Mon Sep 17 00:00:00 2001 From: Dane Springmeyer Date: Fri, 8 May 2015 15:19:41 -0700 Subject: fix division by zero conditions --- include/mbgl/util/math.hpp | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) (limited to 'include') 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 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 -- cgit v1.2.1