Skip to content

Commit

Permalink
fix(color): update factory fn args for mem-mapped colors
Browse files Browse the repository at this point in the history
- add support for opt offset/stride (was already supported by class ctors)
- update shared `ensureArgs()` helper
  • Loading branch information
postspectacular committed Jul 25, 2019
1 parent 6d246f8 commit eae671e
Show file tree
Hide file tree
Showing 8 changed files with 19 additions and 19 deletions.
4 changes: 2 additions & 2 deletions packages/color/src/hcya.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Color, ColorMode } from "./api";
import { AColor } from "./internal/acolor";
import { ensureArgs } from "./internal/ensure-args";

export function hcya(col: Color): HCYA;
export function hcya(col: Color, offset?: number, stride?: number): HCYA;
export function hcya(h?: number, c?: number, y?: number, a?: number): HCYA;
export function hcya(...args: any[]) {
return new HCYA(ensureArgs(args));
return new HCYA(...ensureArgs(args));
}

export class HCYA extends AColor<HCYA> implements IVector<HCYA> {
Expand Down
4 changes: 2 additions & 2 deletions packages/color/src/hsia.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Color, ColorMode } from "./api";
import { AColor } from "./internal/acolor";
import { ensureArgs } from "./internal/ensure-args";

export function hsia(col: Color): HSIA;
export function hsia(col: Color, offset?: number, stride?: number): HSIA;
export function hsia(h?: number, s?: number, i?: number, a?: number): HSIA;
export function hsia(...args: any[]) {
return new HSIA(ensureArgs(args));
return new HSIA(...ensureArgs(args));
}

export class HSIA extends AColor<HSIA> implements IVector<HSIA> {
Expand Down
4 changes: 2 additions & 2 deletions packages/color/src/hsla.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Color, ColorMode } from "./api";
import { AColor } from "./internal/acolor";
import { ensureArgs } from "./internal/ensure-args";

export function hsla(col: Color): HSLA;
export function hsla(col: Color, offset?: number, stride?: number): HSLA;
export function hsla(h?: number, s?: number, l?: number, a?: number): HSLA;
export function hsla(...args: any[]) {
return new HSLA(ensureArgs(args));
return new HSLA(...ensureArgs(args));
}

export class HSLA extends AColor<HSLA> implements IVector<HSLA> {
Expand Down
4 changes: 2 additions & 2 deletions packages/color/src/hsva.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Color, ColorMode } from "./api";
import { AColor } from "./internal/acolor";
import { ensureArgs } from "./internal/ensure-args";

export function hsva(col: Color): HSVA;
export function hsva(col: Color, offset?: number, stride?: number): HSVA;
export function hsva(h?: number, s?: number, v?: number, a?: number): HSVA;
export function hsva(...args: any[]) {
return new HSVA(ensureArgs(args));
return new HSVA(...ensureArgs(args));
}

export class HSVA extends AColor<HSVA> implements IVector<HSVA> {
Expand Down
10 changes: 5 additions & 5 deletions packages/color/src/internal/ensure-args.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,14 +2,14 @@ export const ensureArgs = (args: any[]) => {
if (typeof args[0] === "number") {
switch (args.length) {
case 1:
return args.push(0, 0, 1), args;
return args.push(0, 0, 1), [args];
case 2:
return args.push(0, 1), args;
return args.push(0, 1), [args];
case 3:
return args.push(1), args;
return args.push(1), [args];
default:
return args;
return [args];
}
}
return args[0];
return args;
};
4 changes: 2 additions & 2 deletions packages/color/src/rgba.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Color, ColorMode } from "./api";
import { AColor } from "./internal/acolor";
import { ensureArgs } from "./internal/ensure-args";

export function rgba(col: Color): RGBA;
export function rgba(col: Color, offset?: number, stride?: number): RGBA;
export function rgba(r?: number, g?: number, b?: number, a?: number): RGBA;
export function rgba(...args: any[]) {
return new RGBA(ensureArgs(args));
return new RGBA(...ensureArgs(args));
}

export class RGBA extends AColor<RGBA> implements IVector<RGBA> {
Expand Down
4 changes: 2 additions & 2 deletions packages/color/src/xyza.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Color, ColorMode } from "./api";
import { AColor } from "./internal/acolor";
import { ensureArgs } from "./internal/ensure-args";

export function xyza(col: Color): XYZA;
export function xyza(col: Color, offset?: number, stride?: number): XYZA;
export function xyza(x?: number, y?: number, z?: number, a?: number): XYZA;
export function xyza(...args: any[]) {
return new XYZA(ensureArgs(args));
return new XYZA(...ensureArgs(args));
}

export class XYZA extends AColor<XYZA> implements IVector<XYZA> {
Expand Down
4 changes: 2 additions & 2 deletions packages/color/src/ycbcr.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,10 +3,10 @@ import { Color, ColorMode } from "./api";
import { AColor } from "./internal/acolor";
import { ensureArgs } from "./internal/ensure-args";

export function ycbcra(col: Color): YCbCrA;
export function ycbcra(col: Color, offset?: number, stride?: number): YCbCrA;
export function ycbcra(y: number, b: number, r: number, a?: number): YCbCrA;
export function ycbcra(...args: any[]) {
return new YCbCrA(ensureArgs(args));
return new YCbCrA(...ensureArgs(args));
}

export class YCbCrA extends AColor<YCbCrA> implements IVector<YCbCrA> {
Expand Down

0 comments on commit eae671e

Please sign in to comment.