浏览代码

Color: rename setStyleName() to setColorName()

@pauloddr 5 年之前
父节点
当前提交
0cc77571f4
共有 4 个文件被更改,包括 22 次插入5 次删除
  1. 1 1
      docs/api/en/math/Color.html
  2. 12 0
      src/math/Color.d.ts
  3. 2 2
      src/math/Color.js
  4. 7 2
      test/unit/src/math/Color.tests.js

+ 1 - 1
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).
 		Note that for X11 color names, multiple words such as Dark Orange become the string 'darkorange' (all lowercase).
 		</p>
 		</p>
 
 
-		<h3>[method:Color setStyleName]( [param:String style] ) </h3>
+		<h3>[method:Color setColorName]( [param:String style] ) </h3>
 		<p>
 		<p>
 		[page:String style] — color name ( from [link:https://en.wikipedia.org/wiki/X11_color_names#Color_name_chart X11 color names] ).<br /><br />
 		[page:String style] — color name ( from [link:https://en.wikipedia.org/wiki/X11_color_names#Color_name_chart X11 color names] ).<br /><br />
 
 

+ 12 - 0
src/math/Color.d.ts

@@ -68,6 +68,13 @@ export class Color {
 	 */
 	 */
 	setStyle( style: string ): 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.
 	 * Clones this color.
 	 */
 	 */
@@ -183,4 +190,9 @@ export class Color {
 	 */
 	 */
 	toArray( xyz: ArrayLike<number>, offset?: number ): ArrayLike<number>;
 	toArray( xyz: ArrayLike<number>, offset?: number ): ArrayLike<number>;
 
 
+	/**
+	 * List of X11 color names.
+	 */
+	static NAMES: Record<string, number>;
+
 }
 }

+ 2 - 2
src/math/Color.js

@@ -261,7 +261,7 @@ Object.assign( Color.prototype, {
 
 
 		if ( style && style.length > 0 ) {
 		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
 		// color keywords
 		var hex = _colorKeywords[ style ];
 		var hex = _colorKeywords[ style ];

+ 7 - 2
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.g == 0xAB / 255, "Green: " + a.g );
 			assert.ok( a.b == 0xC1 / 255, "Blue: " + a.b );
 			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 c = new Color();
-			var res = c.setStyleName( "aliceblue" );
+			var res = c.setColorName( "aliceblue" );
 
 
 			assert.ok( c.getHex() == 0xF0F8FF, "Hex: " + c.getHex() );
 			assert.ok( c.getHex() == 0xF0F8FF, "Hex: " + c.getHex() );
 			assert.ok( c == res, "Returns Self" );
 			assert.ok( c == res, "Returns Self" );