diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/mbgl/renderer/line_bucket.cpp | 2 | ||||
-rw-r--r-- | src/mbgl/text/collision.cpp | 26 | ||||
-rw-r--r-- | src/mbgl/text/placement.cpp | 3 |
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; |