summaryrefslogtreecommitdiff
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
parentf1c3cfb7e2d46a4563d680bcab888fa01b2ca160 (diff)
downloadqtlocation-mapboxgl-a37ae27aed97af00a12cb5123264f47bd1fe3427.tar.gz
[core] fix rendering 180° line joins
m---------mapbox-gl-js0
-rw-r--r--src/mbgl/programs/line_program.hpp2
-rw-r--r--src/mbgl/renderer/line_bucket.cpp16
3 files changed, 13 insertions, 5 deletions
diff --git a/mapbox-gl-js b/mapbox-gl-js
-Subproject 878008895104b67861ce73f65809f7f6f0ed726
+Subproject 2663093c9d7f0cba6235131fb9b9f30328a7660
diff --git a/src/mbgl/programs/line_program.hpp b/src/mbgl/programs/line_program.hpp
index 9b97cc47a9..4c2f76f402 100644
--- a/src/mbgl/programs/line_program.hpp
+++ b/src/mbgl/programs/line_program.hpp
@@ -49,7 +49,7 @@ struct LineAttributes : gl::Attributes<
static_cast<int16_t>((p.y * 2) | t.y)
},
{
- // add 128 to store an byte in an unsigned byte
+ // add 128 to store a byte in an unsigned byte
static_cast<uint8_t>(::round(extrudeScale * e.x) + 128),
static_cast<uint8_t>(::round(extrudeScale * e.y) + 128),
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) /