Skip to content

Commit

Permalink
Cleanups, comments [ci skip]
Browse files Browse the repository at this point in the history
  • Loading branch information
Lauren Budorick committed Mar 8, 2018
1 parent a3be215 commit 356f32f
Show file tree
Hide file tree
Showing 10 changed files with 67 additions and 26 deletions.
File renamed without changes.
1 change: 0 additions & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,6 @@
"@mapbox/mapbox-gl-supported": "^1.3.0",
"@mapbox/point-geometry": "^0.1.0",
"@mapbox/shelf-pack": "^3.1.0",
"@mapbox/tilebelt": "^1.0.1",
"@mapbox/tiny-sdf": "^1.1.0",
"@mapbox/unitbezier": "^0.0.0",
"@mapbox/vector-tile": "^1.3.1",
Expand Down
27 changes: 25 additions & 2 deletions src/data/bucket/line_bucket.js
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ class LineBucket implements Bucket {
const indexArray = this.indexArray;

if (distancesForScaling) {
// Scale line from tile units to [0, 2^15)
// For gradient lines, scale distance from tile units to [0, 2^15)
distance = scaleDistance(distance, distancesForScaling);
}

Expand Down Expand Up @@ -500,7 +500,7 @@ class LineBucket implements Bucket {
* This adds a pie slice triangle near a join to simulate round joins
*
* @param currentVertex the line vertex to add buffer vertices for
* @param distance the distance from the beggining of the line to the vertex
* @param distance the distance from the beginning of the line to the vertex
* @param extrude the offset of the new vertex from the currentVertex
* @param lineTurnsLeft whether the line is turning left or right at this angle
* @private
Expand Down Expand Up @@ -532,10 +532,33 @@ class LineBucket implements Bucket {
}
}

/**
* Knowing the ratio of the full linestring covered by this tiled feature, as well
* as the total distance (in tile units) of this tiled feature, and the distance
* (in tile units) of the current vertex, we can determine the relative distance
* of this vertex along the full linestring feature and scale it to [0, 2^15)
*
* @param {number} tileDistance the distance from the beginning of the tiled line to this vertex
* @param {Object} stats
* @param {number} stats.start the ratio (0-1) along a full original linestring feature of the start of this tiled line feature
* @param {number} stats.end the ratio (0-1) along a full original linestring feature of the end of this tiled line feature
* @param {number} stats.tileTotal the total distance, in tile units, of this tiled line feature
*
* @private
*/
function scaleDistance(tileDistance: number, stats: Object) {
return ((tileDistance / stats.tileTotal) * (stats.end - stats.start) + stats.start) * (MAX_LINE_DISTANCE - 1);
}

/**
* Calculate the total distance, in tile units, of this tiled line feature
*
* @param {Array<Point>} vertices the full geometry of this tiled line feature
* @param {number} first the index in the vertices array representing the first vertex we should consider
* @param {number} len the count of vertices we should consider from `first`
*
* @private
*/
function calculateFullDistance(vertices: Array<Point>, first: number, len: number) {
let currentVertex, nextVertex;
let total = 0;
Expand Down
4 changes: 2 additions & 2 deletions src/style/properties.js
Original file line number Diff line number Diff line change
Expand Up @@ -620,7 +620,7 @@ class CrossFadedProperty<T> implements Property<T, ?CrossFaded<T>> {

/**
* An implementation of `Property` for `heatmap-color` and `line-gradient`. Interpolation is a no-op, and
* evaluation returns a value in order to indicate its presence, but the real
* evaluation returns a boolean value in order to indicate its presence, but the real
* evaluation happens in StyleLayer classes.
*
* @private
Expand All @@ -633,7 +633,7 @@ class ColorRampProperty implements Property<Color, boolean> {
}

possiblyEvaluate(value: PropertyValue<Color, boolean>, parameters: EvaluationParameters): boolean {
return !!value.expression.evaluate(parameters); // ?
return !!value.expression.evaluate(parameters);
}

interpolate(): boolean { return false; }
Expand Down
Binary file removed test/integration/tiles/2-1-1-gradient.vector.pbf
Binary file not shown.
Binary file removed test/integration/tiles/2-1-2-gradient.vector.pbf
Binary file not shown.
Binary file removed test/integration/tiles/2-2-1-gradient.vector.pbf
Binary file not shown.
Binary file removed test/integration/tiles/2-2-2-gradient.vector.pbf
Binary file not shown.
21 changes: 20 additions & 1 deletion test/unit/style-spec/fixture/layers.input.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,11 @@
"geojson": {
"type": "geojson",
"data": {}
},
"lineMetrics": {
"type": "geojson",
"data": {},
"lineMetrics": true
}
},
"layers": [
Expand Down Expand Up @@ -119,7 +124,7 @@
}
},
{
"id": "line-gradient-good",
"id": "line-gradient-missing-lineMetrics",
"type": "line",
"source": "geojson",
"source-layer": "source-layer",
Expand All @@ -131,6 +136,20 @@
0, "#000000"
]
}
},
{
"id": "line-gradient-good",
"type": "line",
"source": "lineMetrics",
"source-layer": "source-layer",
"paint": {
"line-gradient": [
"interpolate",
["linear"],
["line-progress"],
0, "#000000"
]
}
}
]
}
40 changes: 20 additions & 20 deletions test/unit/style-spec/fixture/layers.output.json
Original file line number Diff line number Diff line change
@@ -1,74 +1,74 @@
[
{
"message": "layers[0]: either \"type\" or \"ref\" is required",
"line": 18
"line": 23
},
{
"message": "layers[1]: missing required property \"id\"",
"line": 23
"line": 28
},
{
"message": "layers[3]: \"type\" is prohibited for ref layers",
"line": 37
"line": 42
},
{
"message": "layers[3]: \"source\" is prohibited for ref layers",
"line": 38
"line": 43
},
{
"message": "layers[3]: \"source-layer\" is prohibited for ref layers",
"line": 39
"line": 44
},
{
"message": "layers[3]: \"filter\" is prohibited for ref layers",
"line": 40
"line": 45
},
{
"message": "layers[3]: \"layout\" is prohibited for ref layers",
"line": 41
"line": 46
},
{
"message": "layers[4]: ref layer \"not-found\" not found",
"line": 45
"line": 50
},
{
"message": "layers[5]: ref cannot reference another ref layer",
"line": 49
"line": 54
},
{
"message": "layers[6]: missing required property \"source\"",
"line": 51
"line": 56
},
{
"message": "layers[7]: source \"not-found\" not found",
"line": 58
"line": 63
},
{
"message": "layers[8]: layer \"vector-raster-mismatch\" requires a vector source",
"line": 63
"line": 68
},
{
"message": "layers[9]: layer \"raster-vector-mismatch\" requires a raster source",
"line": 68
"line": 73
},
{
"message": "layers[11]: duplicate layer id \"duplicate\", previously used at line 72",
"line": 78
"message": "layers[11]: duplicate layer id \"duplicate\", previously used at line 77",
"line": 83
},
{
"message": "layers[12].type: expected one of [fill, line, symbol, circle, heatmap, fill-extrusion, raster, hillshade, background], \"invalid\" found",
"line": 85
"line": 90
},
{
"message": "layers[13]: layer \"missing-source-layer\" must specify a \"source-layer\"",
"line": 95
"line": 100
},
{
"message": "layers[15]: layer \"line-gradient-bad\" specifies a line-gradient, which requires a GeoJSON source with `lineMetrics` enabled.",
"line": 107
"line": 112
},
{
"message": "layers[16]: layer \"line-gradient-good\" specifies a line-gradient, which requires a GeoJSON source with `lineMetrics` enabled.",
"line": 121
"message": "layers[16]: layer \"line-gradient-missing-lineMetrics\" specifies a line-gradient, which requires a GeoJSON source with `lineMetrics` enabled.",
"line": 126
}
]

0 comments on commit 356f32f

Please sign in to comment.