summaryrefslogtreecommitdiff
path: root/src/mbgl/renderer
diff options
context:
space:
mode:
authorJohn Firebaugh <john.firebaugh@gmail.com>2017-03-13 13:25:02 -0700
committerJohn Firebaugh <john.firebaugh@gmail.com>2017-03-14 09:31:59 -0700
commitbd05bcfe9fcce512d29820b70a646972d2a14767 (patch)
tree8aa91c4b59ee305895729b09b8e92809fa205958 /src/mbgl/renderer
parent30c848b9d8558d3bd669252c27b5ca6a6c7abb8c (diff)
downloadqtlocation-mapboxgl-bd05bcfe9fcce512d29820b70a646972d2a14767.tar.gz
[core] Never join coincident start/end points of LineStrings
Diffstat (limited to 'src/mbgl/renderer')
-rw-r--r--src/mbgl/renderer/line_bucket.cpp24
-rw-r--r--src/mbgl/renderer/line_bucket.hpp2
2 files changed, 9 insertions, 17 deletions
diff --git a/src/mbgl/renderer/line_bucket.cpp b/src/mbgl/renderer/line_bucket.cpp
index 50a70c0fd4..c4028f4b31 100644
--- a/src/mbgl/renderer/line_bucket.cpp
+++ b/src/mbgl/renderer/line_bucket.cpp
@@ -28,7 +28,7 @@ LineBucket::LineBucket(const BucketParameters& parameters,
void LineBucket::addFeature(const GeometryTileFeature& feature,
const GeometryCollection& geometryCollection) {
for (auto& line : geometryCollection) {
- addGeometry(line);
+ addGeometry(line, feature.getType());
}
for (auto& pair : paintPropertyBinders) {
@@ -61,18 +61,18 @@ const float LINE_DISTANCE_SCALE = 1.0 / 2.0;
// The maximum line distance, in tile units, that fits in the buffer.
const float MAX_LINE_DISTANCE = std::pow(2, LINE_DISTANCE_BUFFER_BITS) / LINE_DISTANCE_SCALE;
-void LineBucket::addGeometry(const GeometryCoordinates& coordinates) {
+void LineBucket::addGeometry(const GeometryCoordinates& coordinates, FeatureType type) {
const std::size_t len = [&coordinates] {
std::size_t l = coordinates.size();
// If the line has duplicate vertices at the end, adjust length to remove them.
- while (l > 2 && coordinates[l - 1] == coordinates[l - 2]) {
+ while (l >= 2 && coordinates[l - 1] == coordinates[l - 2]) {
l--;
}
return l;
}();
- if (len < 2) {
- // fprintf(stderr, "a line must have at least two vertices\n");
+ // Ignore invalid geometry.
+ if (len < (type == FeatureType::Polygon ? 3 : 2)) {
return;
}
@@ -81,16 +81,8 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) {
const double sharpCornerOffset = SHARP_CORNER_OFFSET * (float(util::EXTENT) / (util::tileSize * overscaling));
const GeometryCoordinate firstCoordinate = coordinates.front();
- const GeometryCoordinate lastCoordinate = coordinates[len - 1];
- const bool closed = firstCoordinate == lastCoordinate;
-
- if (len == 2 && closed) {
- // fprintf(stderr, "a line may not have coincident points\n");
- return;
- }
-
const LineCapType beginCap = layout.get<LineCap>();
- const LineCapType endCap = closed ? LineCapType::Butt : LineCapType(layout.get<LineCap>());
+ const LineCapType endCap = type == FeatureType::Polygon ? LineCapType::Butt : LineCapType(layout.get<LineCap>());
double distance = 0;
bool startOfLine = true;
@@ -103,7 +95,7 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) {
// the last three vertices added
e1 = e2 = e3 = -1;
- if (closed) {
+ if (type == FeatureType::Polygon) {
currentCoordinate = coordinates[len - 2];
nextNormal = util::perp(util::unit(convertPoint<double>(firstCoordinate - *currentCoordinate)));
}
@@ -112,7 +104,7 @@ void LineBucket::addGeometry(const GeometryCoordinates& coordinates) {
std::vector<TriangleElement> triangleStore;
for (std::size_t i = 0; i < len; ++i) {
- if (closed && i == len - 1) {
+ if (type == FeatureType::Polygon && i == len - 1) {
// if the line is closed, we treat the last vertex like the first
nextCoordinate = coordinates[1];
} else if (i + 1 < len) {
diff --git a/src/mbgl/renderer/line_bucket.hpp b/src/mbgl/renderer/line_bucket.hpp
index 78293d75f9..67a88229d2 100644
--- a/src/mbgl/renderer/line_bucket.hpp
+++ b/src/mbgl/renderer/line_bucket.hpp
@@ -41,7 +41,7 @@ public:
std::unordered_map<std::string, LineProgram::PaintPropertyBinders> paintPropertyBinders;
private:
- void addGeometry(const GeometryCoordinates& line);
+ void addGeometry(const GeometryCoordinates&, FeatureType);
struct TriangleElement {
TriangleElement(uint16_t a_, uint16_t b_, uint16_t c_) : a(a_), b(b_), c(c_) {}