visgl / visgl/deck.gl

[Bug] Division by zero in `TripsLayer` if 2 consecutive coordinates share the same location

Open
#6,844 2 comments 0 reactions 1 assignee View on GitHub

@Pessimistress is already working on this.

Since Apr 25, 2022.

bug
Dominant language
TypeScript
Stars
14.6k
Forks
2.3k
Avg merge
2d 9h
Merged PRs (30d)
42

Description

Description

Originally reported on Slack, but I'm moving it here for exposure:

The bug is in:

https://github.com/visgl/deck.gl/blob/e32b546539b859933be006069f3301a8e4323b1e/modules/geo-layers/src/trips-layer/trips-layer.js#L42

When 2 consecutive coordinates share the same coordinate, they’ll have vPathLength of zero, so the clipping of the line does not work and the point is colored (due to vTime being calculated from a zero division)

We use tripslayer with additive blending for light-paths and this leads to fireflies along the path.
My hotfix is vTime = instanceTimestamps + (instanceNextTimestamps - instanceTimestamps) * vPathPosition.y / ((vPathLength > 0.0) ? 1.0 : vPathLength); but there might be better ways to fix it.

This line could also probably replaced by a mix(instanceTimestamps, instanceNextTimestamps, (vPathLength > 0.0) ? (vPathPosition.y / vPathLength) : 0.5) to make it more explicit (for human reader and shader compiler alike?)

//Edit: I actually ran into precision issues with the code above. I'm now using this:

highp float pathPositionYInstancePercentage = (vPathLength > 0.0) ? (vPathPosition.y / vPathLength) : 0.5;
vTime = mix(instanceTimestamps, instanceNextTimestamps, pathPositionYInstancePercentage);
Flavors
  • React
  • Python/Jupyter notebook
  • MapboxLayer
  • GoogleMapsOverlay
  • CartoLayer
  • DeckLayer/DeckRenderer for ArcGIS
Expected Behavior

Do not divide by zero and provide a sane vTime

Steps to Reproduce

Create a TripsLayer with the same location repeated twice for waypoints on the path coordinates / positions.

Environment

n/a

Logs

n/a

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.