mapbox / mapbox/mapbox-gl-js

Values from interpolate-hcl can be negative

Open
#10,054 1 comment 2 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug :lady_beetle:
Dominant language
TypeScript
Stars
12.4k
Forks
2.4k
PR merge metrics
No merged PRs in 30d

Description

**mapbox-gl-js version**: v1.12.0

**browser**: Node, Chrome

### Steps to Trigger Behavior

Create an expression using `interpolate-hcl` between `red` and `white`.

```
const {expression} = require('mapbox-gl/dist/style-spec')
expression.createExpression(['interpolate-hcl', ['linear'], 2 / 9, 0, 'red', 1, 'white'], {type: 'color'}).value.expression
```

Sometimes the values are negative. Perhaps this is due to floating point errors? I'm trying to create a map legend with 10 stops, so often the `label` value is 2/9, 4/9, etc.

### Link to Demonstration
https://jsbin.com/boxanun/edit?html,output

### Expected Behavior
Returned RGB values should be positive, in the range of `0..1`.

### Actual Behavior
RGB values can be negative

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.

Research direction

Start with the expression.createExpression entry point in mapbox-gl/dist/style-spec and reproduce the interpolate-hcl case using the provided Node or Chrome example. Trace the resulting RGB values and verify the behavior against the expected 0..1 range; the issue is done when the reported interpolation no longer returns negative RGB values.

Written by the indexing model from the issue text.

Assessment

Tech stack
javascript, typescript
Domain
frontend
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.