Skip to content

Commit

Permalink
feat: extract-default-precision-and-steps1 (#5)
Browse files Browse the repository at this point in the history
  • Loading branch information
vojtechsimetka authored Jul 20, 2023
1 parent 38bf2b0 commit a2bdd79
Showing 1 changed file with 10 additions and 7 deletions.
17 changes: 10 additions & 7 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,15 @@ export interface HSL {
l: number
}

interface HUE {
export interface HUE {
p: number
q: number
t: number
}

const DEFAULT_MAX_STEPS = 100
const DEFAULT_TARGET_PRECISION = 0.01

export function hexToRgb(hex: string): RGB {
const bigint = parseInt(hex.substring(1), 16)
const r = (bigint >> 16) & 255
Expand Down Expand Up @@ -119,17 +122,17 @@ export function calculateLuminance(rgbOrHex: RGB | string) {
export function getClosestColor(
hex: string,
targetLuminance: number,
targetPrecision = 0.01,
maxSteps = 100
targetPrecision = DEFAULT_TARGET_PRECISION,
maxSteps = DEFAULT_MAX_STEPS
) {
return getClosestColorBisection(hex, targetLuminance, targetPrecision, maxSteps)
}

export function getClosestColorNewton(
hex: string,
targetLuminance: number,
targetPrecision = 0.01,
maxSteps = 100
targetPrecision = DEFAULT_TARGET_PRECISION,
maxSteps = DEFAULT_MAX_STEPS
) {
// // Just a shortcut for all colors these are 0 and 100 luminance
if (targetLuminance <= 0) return '#000000'
Expand Down Expand Up @@ -171,8 +174,8 @@ export function getClosestColorNewton(
export function getClosestColorBisection(
hex: string,
targetLuminance: number,
targetPrecision = 0.01,
maxSteps = 100
targetPrecision = DEFAULT_TARGET_PRECISION,
maxSteps = DEFAULT_MAX_STEPS
) {
// Just a shortcut for all colors these are 0 and 100 luminance
if (targetLuminance <= 0) return '#000000'
Expand Down

0 comments on commit a2bdd79

Please sign in to comment.