forked from color-js/color.js
-
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Make color space optional in
getAll()
+ colorSpace.equals()
impro…
…vements (color-js#413) * `colorSpace.equals()` improvements - JSDoc - Handle comparison with id * `getAll()`: Make color space optional This is to set the stage for option 3 here: color-js#388 (comment) but also implements a performance improvement when the color passed *happens* to be in the same color space as the one specified. * Update types for getAll --------- Co-authored-by: Jonny Gerig Meyer <[email protected]>
- Loading branch information
1 parent
a8bc6fd
commit 64780c3
Showing
4 changed files
with
18 additions
and
9 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,12 +1,17 @@ | ||
import ColorSpace from "./space.js"; | ||
|
||
/** | ||
* Get the coordinates of a color in another color space | ||
* | ||
* @param {string | ColorSpace} space | ||
* @returns {number[]} | ||
* Get the coordinates of a color in any color space | ||
* @param {Color} color | ||
* @param {string | ColorSpace} [space = color.space] The color space to convert to. Defaults to the color's current space | ||
* @returns {number[]} The color coordinates in the given color space | ||
*/ | ||
export default function getAll (color, space) { | ||
if (!space || color.space.equals(space)) { | ||
// No conversion needed | ||
return color.coords.slice(); | ||
} | ||
|
||
space = ColorSpace.get(space); | ||
return space.from(color); | ||
} |
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