Skip to content

Commit

Permalink
Merge pull request #1220 from OpenGeoscience/speed-up-tracks
Browse files Browse the repository at this point in the history
perf: Speed up track feature.
  • Loading branch information
manthey authored Jun 15, 2022
2 parents 5bf4fee + cec013a commit 965d40f
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
9 changes: 6 additions & 3 deletions src/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -46,9 +46,12 @@ var util = require('./util');
* divided by the sine of half the angle between segments, then a bevel join
* is used instead. This is a single value that applies to all lines. If a
* function, it is called with `(data)`.
* @property {boolean|function} [uniformLine=false] Boolean indicating if each
* line has a uniform style (uniform stroke color, opacity, and width). Can
* vary by line.
* @property {boolean|string|function} [uniformLine=false] Boolean indicating
* if each line has a uniform style (uniform stroke color, opacity, and
* width). Can vary by line. A value of `'drop'` will modify rendered
* vertex order by dropping duplicates and setting later values to zero
* opacity. This can be faster but makes it so updating the style array
* can no longer be used.
* @property {number|function} [antialiasing] Antialiasing distance in pixels.
* Values must be non-negative. A value greater than 1 will produce a
* visible gradient. This is a single value that applies to all lines.
Expand Down
4 changes: 3 additions & 1 deletion src/trackFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -816,7 +816,9 @@ var trackFeature = function (arg) {
{
track: util.identityFunction,
position: util.identityFunction,
time: (d, i) => (d.t !== undefined ? d.t : i)
time: (d, i) => (d.t !== undefined ? d.t : i),
uniformLine: 'drop',
closed: false
},
arg.style === undefined ? {} : arg.style
);
Expand Down
14 changes: 14 additions & 0 deletions src/webgl/lineFeature.js
Original file line number Diff line number Diff line change
Expand Up @@ -269,6 +269,7 @@ var webgl_lineFeature = function (arg) {
closedVal = closed[i];
firstPosIdx3 = posIdx3;
maxj = lineItem.length + (closedVal === 2 ? 1 : 0);
let skipped = 0;
for (j = 0; j < maxj; j += 1, posIdx3 += 3) {
lidx = j;
if (j === lineItem.length) {
Expand Down Expand Up @@ -329,9 +330,17 @@ var webgl_lineFeature = function (arg) {
}

if (j) {
if (uniform === 'drop' && j > 1 && position[vert[0].pos] === position[vert[1].pos] && position[vert[0].pos + 1] === position[vert[1].pos + 1]) {
skipped += 1;
continue;
}
/* zero out the z position. This can be changed if we handle it in
* the shader. */
for (k = 0; k < orderLen; k += 1, dest += 1, dest3 += 3) {
if (uniform === 'drop' && vert[0].strokeOpacity <= 0 && vert[1].strokeOpacity <= 0) {
strokeOpacityBuf[dest] = -1;
continue;
}
orderk0 = order[k][0];
v1 = vert[orderk0];
v2 = vert[1 - orderk0];
Expand Down Expand Up @@ -370,6 +379,11 @@ var webgl_lineFeature = function (arg) {
}
}
}
if (skipped) {
for (k = 0; k < skipped * orderLen; k += 1, dest += 1, dest3 += 3) {
strokeOpacityBuf[dest] = -1;
}
}
}

if (!onlyStyle) {
Expand Down

0 comments on commit 965d40f

Please sign in to comment.