summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer
diff options
context:
space:
mode:
authorKonstantin Käfer <mail@kkaefer.com>2017-01-19 16:36:19 +0100
committerKonstantin Käfer <mail@kkaefer.com>2017-01-23 17:02:40 +0100
commita37ae27aed97af00a12cb5123264f47bd1fe3427 (patch)
tree78fefe5b4d14dd74efcc23ff2a1a34199cf34131 /src/mbgl/renderer
parentf1c3cfb7e2d46a4563d680bcab888fa01b2ca160 (diff)
downloadqtlocation-mapboxgl-a37ae27aed97af00a12cb5123264f47bd1fe3427.tar.gz
[core] fix rendering 180° line joins
Diffstat (limited to 'src/mbgl/renderer')
-rw-r--r--src/mbgl/renderer/line_bucket.cpp16
1 files changed, 12 insertions, 4 deletions
diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp
index 007060bd1b..6921b364d8 100644
--- a/src/mbgl/renderer/line_bucket.cpp
+++ b/src/mbgl/renderer/line_bucket.cpp
@@ -139,7 +139,14 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) {
// Determine the normal of the join extrusion. It is the angle bisector
// of the segments between the previous line and the next line.
- Point<double> joinNormal = util::unit(*prevNormal + *nextNormal);
+ // In the case of 180° angles, the prev and next normals cancel each other out:
+ // prevNormal + nextNormal = (0, 0), its magnitude is 0, so the unit vector would be
+ // undefined. In that case, we're keeping the joinNormal at (0, 0), so that the cosHalfAngle
+ // below will also become 0 and miterLength will become Infinity.
+ Point<double> joinNormal = *prevNormal + *nextNormal;
+ if (joinNormal.x != 0 || joinNormal.y != 0) {
+ joinNormal = util::unit(joinNormal);
+ }
/* joinNormal prevNormal
* ↖ ↑
@@ -155,7 +162,8 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) {
// Find the cosine of the angle between the next and join normals
// using dot product. The inverse of that is the miter length.
const double cosHalfAngle = joinNormal.x * nextNormal->x + joinNormal.y * nextNormal->y;
- const double miterLength = cosHalfAngle != 0 ? 1 / cosHalfAngle: 1;
+ const double miterLength =
+ cosHalfAngle != 0 ? 1 / cosHalfAngle : std::numeric_limits<double>::infinity();
const bool isSharpCorner = cosHalfAngle < COS_HALF_SHARP_CORNER && prevCoordinate && nextCoordinate;
@@ -189,7 +197,7 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) {
if (currentJoin == LineJoinType::Bevel) {
// The maximum extrude length is 128 / 63 = 2 times the width of the line
- // so if miterLength >= 2 we need to draw a different type of bevel where.
+ // so if miterLength >= 2 we need to draw a different type of bevel here.
if (miterLength > 2) {
currentJoin = LineJoinType::FlipBevel;
}
@@ -216,7 +224,7 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) {
if (miterLength > 100) {
// Almost parallel lines
- joinNormal = *nextNormal;
+ joinNormal = *nextNormal * -1.0;
} else {
const double direction = prevNormal->x * nextNormal->y - prevNormal->y * nextNormal->x > 0 ? -1 : 1;
const double bevelLength = miterLength * util::mag(*prevNormal + *nextNormal) /