From 0cc77571f49e51949f6943335011d917fbdeab45 Mon Sep 17 00:00:00 2001
From: "@pauloddr"
Date: Mon, 23 Sep 2019 19:57:41 +0000
Subject: [PATCH] Color: rename setStyleName() to setColorName()
---
docs/api/en/math/Color.html | 2 +-
src/math/Color.d.ts | 12 ++++++++++++
src/math/Color.js | 4 ++--
test/unit/src/math/Color.tests.js | 9 +++++++--
4 files changed, 22 insertions(+), 5 deletions(-)
diff --git a/docs/api/en/math/Color.html b/docs/api/en/math/Color.html
index b04a760f58..57ec28c70b 100644
--- a/docs/api/en/math/Color.html
+++ b/docs/api/en/math/Color.html
@@ -302,7 +302,7 @@ var color = new THREE.Color( 1, 0, 0 );
Note that for X11 color names, multiple words such as Dark Orange become the string 'darkorange' (all lowercase).
- [method:Color setStyleName]( [param:String style] )
+ [method:Color setColorName]( [param:String style] )
[page:String style] — color name ( from [link:https://en.wikipedia.org/wiki/X11_color_names#Color_name_chart X11 color names] ).
diff --git a/src/math/Color.d.ts b/src/math/Color.d.ts
index 94b3a712ac..17fb3c895d 100644
--- a/src/math/Color.d.ts
+++ b/src/math/Color.d.ts
@@ -68,6 +68,13 @@ export class Color {
*/
setStyle( style: string ): Color;
+ /**
+ * Sets this color from a color name.
+ * Faster than {@link Color#setStyle .setStyle()} method if you don't need the other CSS-style formats.
+ * @param style Color name in X11 format.
+ */
+ setColorName( style: string ): Color;
+
/**
* Clones this color.
*/
@@ -183,4 +190,9 @@ export class Color {
*/
toArray( xyz: ArrayLike, offset?: number ): ArrayLike;
+ /**
+ * List of X11 color names.
+ */
+ static NAMES: Record;
+
}
diff --git a/src/math/Color.js b/src/math/Color.js
index a7f9f2c3e5..fe5eafb982 100644
--- a/src/math/Color.js
+++ b/src/math/Color.js
@@ -261,7 +261,7 @@ Object.assign( Color.prototype, {
if ( style && style.length > 0 ) {
- return this.setStyleName( style );
+ return this.setColorName( style );
}
@@ -269,7 +269,7 @@ Object.assign( Color.prototype, {
},
- setStyleName: function ( style ) {
+ setColorName: function ( style ) {
// color keywords
var hex = _colorKeywords[ style ];
diff --git a/test/unit/src/math/Color.tests.js b/test/unit/src/math/Color.tests.js
index f54dd66382..5e0593895e 100644
--- a/test/unit/src/math/Color.tests.js
+++ b/test/unit/src/math/Color.tests.js
@@ -144,12 +144,17 @@ export default QUnit.module( 'Maths', () => {
assert.ok( a.g == 0xAB / 255, "Green: " + a.g );
assert.ok( a.b == 0xC1 / 255, "Blue: " + a.b );
+ a.setStyle( "aliceblue" );
+ assert.ok( a.r == 0xF0 / 255, "Red: " + a.r );
+ assert.ok( a.g == 0xF8 / 255, "Green: " + a.g );
+ assert.ok( a.b == 0xFF / 255, "Blue: " + a.b );
+
} );
- QUnit.test( "setStyleName", ( assert ) => {
+ QUnit.test( "setColorName", ( assert ) => {
var c = new Color();
- var res = c.setStyleName( "aliceblue" );
+ var res = c.setColorName( "aliceblue" );
assert.ok( c.getHex() == 0xF0F8FF, "Hex: " + c.getHex() );
assert.ok( c == res, "Returns Self" );
--
GitLab