Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add Color.toCssHexString and unit tests #8987

Merged
merged 4 commits into from
Jun 24, 2020
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGES.md
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@

##### Breaking Changes :mega:

- Added `Color.toCssHexString` for getting the CSS hex string equivalent for a color.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should go under the Additions section instead of the Breaking Changes section

- Updated `WallGeometry` to respect the order of positions passed in, instead of making the positions respect a counter clockwise winding order. This will only effect the look of walls with an image material. If this changed the way your wall is drawing, reverse the order of the positions.

##### Additions :tada:
Expand Down
21 changes: 21 additions & 0 deletions Source/Core/Color.js
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,27 @@ Color.prototype.toCssColorString = function () {
return "rgba(" + red + "," + green + "," + blue + "," + this.alpha + ")";
};

/**
* Creates a string containing CSS hex string color value for this color.
hpinkos marked this conversation as resolved.
Show resolved Hide resolved
*
* @returns {String} The CSS hex string equivalent of this color.
*/
Color.prototype.toCssHexString = function () {
var r = Color.floatToByte(this.red).toString(16);
if (r.length < 2) {
r = "0" + r;
}
var g = Color.floatToByte(this.green).toString(16);
if (g.length < 2) {
g = "0" + g;
}
var b = Color.floatToByte(this.blue).toString(16);
if (b.length < 2) {
b = "0" + b;
}
return "#" + r + g + b;
};

/**
* Converts this color to an array of red, green, blue, and alpha values
* that are in the range of 0 to 255.
Expand Down
9 changes: 9 additions & 0 deletions Specs/Core/ColorSpec.js
Original file line number Diff line number Diff line change
Expand Up @@ -160,6 +160,15 @@ describe("Core/Color", function () {
);
});

it("toCssHexString produces expected output", function () {
expect(Color.WHITE.toCssHexString()).toEqual("#ffffff");
expect(Color.RED.toCssHexString()).toEqual("#ff0000");
expect(Color.BLUE.toCssHexString()).toEqual("#0000ff");
expect(Color.LIME.toCssHexString()).toEqual("#00ff00");
expect(new Color(0.0, 0.0, 0.0, 1.0).toCssHexString()).toEqual("#000000");
expect(new Color(0.1, 0.2, 0.3, 0.4).toCssHexString()).toEqual("#19334c");
});

it("fromCssColorString supports transparent", function () {
expect(Color.fromCssColorString("transparent")).toEqual(
new Color(0.0, 0.0, 0.0, 0.0)
Expand Down