summaryrefslogtreecommitdiff
path: root/src
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 /src
parent5ef362bbc45e7b553f5d21a5368e09dd243a8a0c (diff)
downloadqtlocation-mapboxgl-768c259495200ff3214dd4eb1284aaa49a7a814c.tar.gz
fix division by zero conditions
Diffstat (limited to 'src')
-rw-r--r--src/mbgl/renderer/line_bucket.cpp2
-rw-r--r--src/mbgl/text/collision.cpp26
-rw-r--r--src/mbgl/text/placement.cpp3
3 files changed, 22 insertions, 9 deletions
diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp
index 651b4986e4..bbfc02ead1 100644
--- a/src/mbgl/renderer/line_bucket.cpp
+++ b/src/mbgl/renderer/line_bucket.cpp
@@ -143,7 +143,7 @@ void LineBucket::addGeometry(const std::vector<Coordinate>& vertices) {
// Find the cosine of the angle between the next and join normals
// using dot product. The inverse of that is the miter length.
const float cosHalfAngle = joinNormal.x * nextNormal.x + joinNormal.y * nextNormal.y;
- const float miterLength = 1 / cosHalfAngle;
+ const float miterLength = cosHalfAngle != 0 ? 1 / cosHalfAngle: 1;
// The join if a middle vertex, otherwise the cap
const bool middleVertex = prevVertex && nextVertex;
diff --git a/src/mbgl/text/collision.cpp b/src/mbgl/text/collision.cpp
index 422cd0a60a..ba32b87d2f 100644
--- a/src/mbgl/text/collision.cpp
+++ b/src/mbgl/text/collision.cpp
@@ -157,14 +157,24 @@ float Collision::getPlacementScale(const GlyphBoxes &glyphs, float minPlacementS
float padding = std::fmax(pad, placement.padding) * 8.0f;
// Original algorithm:
- float s1 = (ob.tl.x - nb.br.x - padding) /
- (na.x - oa.x); // scale at which new box is to the left of old box
- float s2 = (ob.br.x - nb.tl.x + padding) /
- (na.x - oa.x); // scale at which new box is to the right of old box
- float s3 = (ob.tl.y - nb.br.y - padding) /
- (na.y - oa.y); // scale at which new box is to the top of old box
- float s4 = (ob.br.y - nb.tl.y + padding) /
- (na.y - oa.y); // scale at which new box is to the bottom of old box
+ float sx = (na.x - oa.x);
+ float s1 = 1;
+ float s2 = 1;
+ if (sx != 0) {
+ s1 = (ob.tl.x - nb.br.x - padding) /
+ sx; // scale at which new box is to the left of old box
+ s2 = (ob.br.x - nb.tl.x + padding) /
+ sx; // scale at which new box is to the right of old box
+ }
+ float sy = (na.y - oa.y);
+ float s3 = 1;
+ float s4 = 1;
+ if (sy != 0) {
+ s3 = (ob.tl.y - nb.br.y - padding) /
+ sy; // scale at which new box is to the top of old box
+ s4 = (ob.br.y - nb.tl.y + padding) /
+ sy; // scale at which new box is to the bottom of old box
+ }
if (std::isnan(s1) || std::isnan(s2)) {
s1 = s2 = 1;
diff --git a/src/mbgl/text/placement.cpp b/src/mbgl/text/placement.cpp
index 8a221e16f7..addab58739 100644
--- a/src/mbgl/text/placement.cpp
+++ b/src/mbgl/text/placement.cpp
@@ -53,6 +53,9 @@ void getSegmentGlyphs(std::back_insert_iterator<GlyphInstances> glyphs, Anchor &
while (true) {
const float dist = util::dist<float>(newAnchor, end);
+ if (dist == 0) {
+ break;
+ }
const float scale = offset / dist;
float angle =
-std::atan2(end.x - newAnchor.x, end.y - newAnchor.y) + direction * M_PI / 2.0f;