Evercoder / Evercoder/culori

using `clampChroma` within a conversion sequence results in invalid values

Open
#129 18 comments 0 reactions 0 assignees View on GitHub
Dominant language
JavaScript
Stars
1.2k
Forks
38
PR merge metrics
No merged PRs in 30d

Description

# Issue

Using `clampChroma` within a conversion sequence results in a color object with invalid values.

# Expected

Post-`clampChroma` conversions result in color objects with valid values as defined by [culorijs.org/color-spaces](https://culorijs.org/color-spaces).

# Example

```ts
import {rgb, oklch, clampChroma} from "culori"

const max = {l:1, c:0.322, h:360}

rgb(
clampChroma(
oklch({
l: (max.l * 0.5),
c: (max.c * 0.5),
h: (max.h * 0.5),
})
)
)
```

# Result

### `oklch` > `clampChroma` > `rgb`
`r` has a negative value, which is outside of the `rgb` color-space's documented `{min:0, max:1}` range.

```js
{mode:'rgb', r:-0.00015269415291914584, g:0.4633768089712706, b:0.40462053745496246}
```

# Other Values

### `oklch`
```js
{mode:'oklch', l:0.5, c:0.161, h:180}
```

### `oklch` > `clampChroma`
```js
{mode:'oklch', l:0.5074222643221025, c:0.09214221649333439, h:179.92987163513519}
```

### `oklch` > `rgb`
```js
{mode:'rgb', r:-1.1275082865428603, g:0.4943967336505179, b:0.40272542671134454}
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.