diff --git a/src/cubehelix.js b/src/cubehelix.js index bc31659..83536dd 100644 --- a/src/cubehelix.js +++ b/src/cubehelix.js @@ -1,6 +1,6 @@ import define, {extend} from "./define.js"; import {Color, rgbConvert, Rgb, darker, brighter} from "./color.js"; -import {deg2rad, rad2deg} from "./math.js"; +import {degrees, radians} from "./math.js"; var A = -0.14861, B = +1.78277, @@ -21,7 +21,7 @@ function cubehelixConvert(o) { bl = b - l, k = (E * (g - l) - C * bl) / D, s = Math.sqrt(k * k + bl * bl) / (E * l * (1 - l)), // NaN if l=0 or l=1 - h = s ? Math.atan2(k, bl) * rad2deg - 120 : NaN; + h = s ? Math.atan2(k, bl) * degrees - 120 : NaN; return new Cubehelix(h < 0 ? h + 360 : h, s, l, o.opacity); } @@ -46,7 +46,7 @@ define(Cubehelix, cubehelix, extend(Color, { return new Cubehelix(this.h, this.s, this.l * k, this.opacity); }, rgb: function() { - var h = isNaN(this.h) ? 0 : (this.h + 120) * deg2rad, + var h = isNaN(this.h) ? 0 : (this.h + 120) * radians, l = +this.l, a = isNaN(this.s) ? 0 : this.s * l * (1 - l), cosh = Math.cos(h), diff --git a/src/lab.js b/src/lab.js index 02545c4..645e1a5 100644 --- a/src/lab.js +++ b/src/lab.js @@ -1,6 +1,6 @@ import define, {extend} from "./define.js"; import {Color, rgbConvert, Rgb} from "./color.js"; -import {deg2rad, rad2deg} from "./math.js"; +import {degrees, radians} from "./math.js"; // https://observablehq.com/@mbostock/lab-and-rgb const K = 18, @@ -85,7 +85,7 @@ function hclConvert(o) { if (o instanceof Hcl) return new Hcl(o.h, o.c, o.l, o.opacity); if (!(o instanceof Lab)) o = labConvert(o); if (o.a === 0 && o.b === 0) return new Hcl(NaN, 0 < o.l && o.l < 100 ? 0 : NaN, o.l, o.opacity); - var h = Math.atan2(o.b, o.a) * rad2deg; + var h = Math.atan2(o.b, o.a) * degrees; return new Hcl(h < 0 ? h + 360 : h, Math.sqrt(o.a * o.a + o.b * o.b), o.l, o.opacity); } @@ -106,7 +106,7 @@ export function Hcl(h, c, l, opacity) { function hcl2lab(o) { if (isNaN(o.h)) return new Lab(o.l, 0, 0, o.opacity); - var h = o.h * deg2rad; + var h = o.h * radians; return new Lab(o.l, Math.cos(h) * o.c, Math.sin(h) * o.c, o.opacity); } diff --git a/src/math.js b/src/math.js index e94b840..66b172e 100644 --- a/src/math.js +++ b/src/math.js @@ -1,2 +1,2 @@ -export var deg2rad = Math.PI / 180; -export var rad2deg = 180 / Math.PI; +export const radians = Math.PI / 180; +export const degrees = 180 / Math.PI;