Skip to content

Commit

Permalink
js implementation works
Browse files Browse the repository at this point in the history
  • Loading branch information
Metroxe committed Oct 23, 2019
1 parent 1f66f75 commit 102109e
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 15 deletions.
10 changes: 5 additions & 5 deletions src/converters/determineInput.ts
Original file line number Diff line number Diff line change
Expand Up @@ -37,16 +37,16 @@ function determineInput(input: any): InputType {
return InputType.COLOUR_CHISEL;
}

// code
if (typeof input === "string") {
return InputType.CODE;
}

// array
if (Array.isArray(input)) {
return InputType.ARRAY;
}

// code
if (typeof input === "string") {
return InputType.CODE;
}

return InputType.INCOMPATIBLE;
}

Expand Down
14 changes: 4 additions & 10 deletions src/converters/rgbToHSL.ts
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@ function rgbToHSL([_r, _g, _b]: [number, number, number]): [number, number, numb
g /= 255;
b /= 255;

var max = Math.max(r, g, b), min = Math.min(r, g, b);
var h, s, l = (max + min) / 2;
const max = Math.max(r, g, b), min = Math.min(r, g, b);
let h, s, l = (max + min) / 2;

if (max == min) {
h = s = 0; // achromatic
Expand All @@ -34,16 +34,10 @@ function rgbStringToHSL(_rgb: string): [number, number, number] {

for (let s in str) {
let r = str[s];
if (r.indexOf("%") > -1) {
rgb[s] = Math.round(parseInt(r.substr(0, r.length - 1)) / 100 * 255);
}
rgb[s] = Math.round(parseInt(r));
}

const r = rgb[0] / 255,
g = rgb[1] / 255,
b = rgb[2] / 255;

return rgbToHSL([r, g, b]);
return rgbToHSL(rgb);
}

export default rgbToHSL;
Expand Down
38 changes: 38 additions & 0 deletions test/longPathing.test.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import {expect} from "chai";
import ColourChisel from "../src";

describe("test making a path with exponential amount of paths", () => {
const hueIncrement = 1;
const saturationIncrement = 0.1;
const luminanceIncrement = 0.1;
const points: [number, number, number][] = [];
let cc: ColourChisel;

it("create long array of points", () => {
let h: number;
let s: number;
let l: number;
// hue
for (h = 0; h <= 360; h += hueIncrement) {
// saturation
for (s = 0; s <= 1; s += saturationIncrement) {
// luminance
for (l = 0; l <= 1; l += luminanceIncrement) {
points.push([h + 0, s + 0, l + 0]) // to stop reference
}
}
}
expect(points.length).to.be.equal(Math.round((h / hueIncrement) * (s / saturationIncrement) * (l / luminanceIncrement)));
});

it("create ColourChisel Object", () => {
cc = new ColourChisel(points);
});

it("check hues match", () => {
const hsls = cc.hsl();
hsls.forEach((h, i) => {
expect(h).to.be.deep.equal(points[i]);
})
})
});

0 comments on commit 102109e

Please sign in to comment.