Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix(adjustHue): account for potential negative hue value #438

Merged
merged 4 commits into from May 18, 2019
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/color/adjustHue.js
Expand Up @@ -32,7 +32,7 @@ function adjustHue(degree: number | string, color: string): string {
const hslColor = parseToHsl(color)
return toColorString({
...hslColor,
hue: (hslColor.hue + parseFloat(degree)) % 360,
hue: hslColor.hue + parseFloat(degree),
})
}

Expand Down
4 changes: 2 additions & 2 deletions src/internalHelpers/_hslToRgb.js
Expand Up @@ -22,9 +22,9 @@ function hslToRgb(
}

// formular from https://en.wikipedia.org/wiki/HSL_and_HSV
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Typo here we should fix as part of this.

const huePrime = hue % 360 / 60
const huePrime = (((hue % 360) + 360) % 360) / 60 // Corrected for potential negative hue
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Instead of an inline comment, might be worth putting a note in the docs on how we handle the potential negative hue.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I fixed the typo and removed the comment. I'll try looking into the docs later, when I have a bit more time.

const chroma = (1 - Math.abs(2 * lightness - 1)) * saturation
const secondComponent = chroma * (1 - Math.abs(huePrime % 2 - 1))
const secondComponent = chroma * (1 - Math.abs((huePrime % 2) - 1))

let red = 0
let green = 0
Expand Down