-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(color): add RGBA/HSLA wrapper types, update convert
- Loading branch information
1 parent
404ac54
commit 610699a
Showing
6 changed files
with
176 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,54 @@ | ||
import { EPS } from "@thi.ng/math/api"; | ||
import { IVector, Vec } from "@thi.ng/vectors3/api"; | ||
import { eqDelta4 } from "@thi.ng/vectors3/eqdelta"; | ||
import { declareIndices } from "@thi.ng/vectors3/internal/accessors"; | ||
import { AVec } from "@thi.ng/vectors3/internal/avec"; | ||
import { ColorMode, IColor } from "./api"; | ||
|
||
export class HSLA extends AVec implements | ||
IColor, | ||
IVector<HSLA> { | ||
|
||
h: number; | ||
s: number; | ||
l: number; | ||
a: number; | ||
[id: number]: number; | ||
|
||
constructor(buf?: Vec, i = 0, s = 1) { | ||
super(buf || [0, 0, 0, 0], i, s); | ||
} | ||
|
||
*[Symbol.iterator]() { | ||
yield this[0]; | ||
yield this[1]; | ||
yield this[2]; | ||
yield this[3]; | ||
} | ||
|
||
get mode() { | ||
return ColorMode.HSLA; | ||
} | ||
|
||
get length() { | ||
return 4; | ||
} | ||
|
||
copy() { | ||
return new HSLA([this[0], this[1], this[2], this[3]]); | ||
} | ||
|
||
copyView() { | ||
return new HSLA(this.buf, this.offset, this.stride); | ||
} | ||
|
||
empty() { | ||
return new HSLA(); | ||
} | ||
|
||
eqDelta(o: HSLA, eps = EPS): boolean { | ||
return eqDelta4(this, o, eps); | ||
} | ||
} | ||
|
||
declareIndices(HSLA.prototype, ["h", "s", "v", "a"]); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
import { EPS } from "@thi.ng/math/api"; | ||
import { IVector, Vec } from "@thi.ng/vectors3/api"; | ||
import { eqDelta4 } from "@thi.ng/vectors3/eqdelta"; | ||
import { declareIndices } from "@thi.ng/vectors3/internal/accessors"; | ||
import { AVec } from "@thi.ng/vectors3/internal/avec"; | ||
import { ColorMode, IColor } from "./api"; | ||
|
||
export class RGBA extends AVec implements | ||
IColor, | ||
IVector<RGBA> { | ||
|
||
r: number; | ||
g: number; | ||
b: number; | ||
a: number; | ||
[id: number]: number; | ||
|
||
constructor(buf?: Vec, offset = 0, stride = 1) { | ||
super(buf || [0, 0, 0, 0], offset, stride); | ||
} | ||
|
||
*[Symbol.iterator]() { | ||
yield* [this.r, this.g, this.b, this.a]; | ||
} | ||
|
||
get mode() { | ||
return ColorMode.RGBA; | ||
} | ||
|
||
get length() { | ||
return 4; | ||
} | ||
|
||
copy() { | ||
return new RGBA([this.r, this.g, this.b, this.a]); | ||
} | ||
|
||
copyView() { | ||
return new RGBA(this.buf, this.offset, this.stride); | ||
} | ||
|
||
empty() { | ||
return new RGBA(); | ||
} | ||
|
||
eqDelta(o: RGBA, eps = EPS): boolean { | ||
return eqDelta4(this, o, eps); | ||
} | ||
} | ||
|
||
declareIndices(RGBA.prototype, ["r", "g", "b", "a"]); |