فهرست منبع

Remove optionalTarget

WestLangley 7 سال پیش
والد
کامیت
135826280d
3فایلهای تغییر یافته به همراه62 افزوده شده و 28 حذف شده
  1. 2 3
      docs/api/math/Color.html
  2. 37 13
      examples/js/math/ColorConverter.js
  3. 23 12
      src/math/Color.js

+ 2 - 3
docs/api/math/Color.html

@@ -162,10 +162,9 @@ var color = new THREE.Color( 1, 0, 0 );
 		<h3>[method:String getHexString]()</h3>
 		<div>Returns the hexadecimal value of this color as a string (for example, 'FFFFFF').</div>
 
-		<h3>[method:Object getHSL]( [param:Object optionalTarget] )</h3>
+		<h3>[method:Object getHSL]( [param:Object target] )</h3>
 		<div>
-			[page:Object optionalTarget] — (optional) if specified, adds h, s and l keys to the object (if not already present)
-			and sets the results there. Otherwise, a new Object will be created. <br /><br />
+			[page:Object target] — the result will be copied into this Object. Adds h, s and l keys to the object (if not already present).<br /><br />
 
 			Convert this Color's [page:.r r], [page:.g g] and [page:.b b] values to [link:https://en.wikipedia.org/wiki/HSL_and_HSV HSL]
 			format and returns an object of the form:

+ 37 - 13
examples/js/math/ColorConverter.js

@@ -17,20 +17,33 @@ THREE.ColorConverter = {
 
 	},
 
-	getHSV: function( color ) {
+	getHSV: function() {
 
-		var hsl = color.getHSL();
+		var hsl = {};
 
-		// based on https://gist.github.com/xpansive/1337890#file-index-js
-		hsl.s *= ( hsl.l < 0.5 ) ? hsl.l : ( 1 - hsl.l );
+		return function getHSV( color, target ) {
+
+			if ( target === undefined ) {
+
+				console.warn( 'THREE.ColorConverter: .getHSV() target is now required' );
+				target = { h: 0, s: 0, l: 0 };
+
+			}
+
+			color.getHSL( hsl );
+
+			// based on https://gist.github.com/xpansive/1337890#file-index-js
+			hsl.s *= ( hsl.l < 0.5 ) ? hsl.l : ( 1 - hsl.l );
+
+			target.h = hsl.h;
+			target.s = 2 * hsl.s / ( hsl.l + hsl.s );
+			target.v = hsl.l + hsl.s;
+
+			return target;
 
-		return {
-			h: hsl.h,
-			s: 2 * hsl.s / ( hsl.l + hsl.s ),
-			v: hsl.l + hsl.s
 		};
 
-	},
+	}(),
 
 	// where c, m, y, k is between 0 and 1
 	
@@ -44,19 +57,30 @@ THREE.ColorConverter = {
 
 	},
 
-	getCMYK: function ( color ) {
+	getCMYK: function ( color, target ) {
+
+		if ( target === undefined ) {
+
+			console.warn( 'THREE.ColorConverter: .getCMYK() target is now required' );
+			target = { c: 0, m: 0, y: 0, k:0 };
+
+		}
 
 		var r = color.r;
 		var g = color.g;
 		var b = color.b;
+
 		var k = 1 - Math.max( r, g, b );
 		var c = ( 1 - r - k ) / ( 1 - k );
 		var m = ( 1 - g - k ) / ( 1 - k );
 		var y = ( 1 - b - k ) / ( 1 - k );
 
-		return {
-			c: c, m: m, y: y, k: k
-		};
+		target.c = c;
+		target.m = m;
+		target.y = y;
+		target.k = k;
+
+		return target;
 
 	}
 

+ 23 - 12
src/math/Color.js

@@ -347,11 +347,16 @@ Object.assign( Color.prototype, {
 
 	},
 
-	getHSL: function ( optionalTarget ) {
+	getHSL: function ( target ) {
 
 		// h,s,l ranges are in 0.0 - 1.0
 
-		var hsl = optionalTarget || { h: 0, s: 0, l: 0 };
+		if ( target === undefined ) {
+
+			console.warn( 'THREE.Color: .getHSL() target is now required' );
+			target = { h: 0, s: 0, l: 0 };
+
+		}
 
 		var r = this.r, g = this.g, b = this.b;
 
@@ -384,11 +389,11 @@ Object.assign( Color.prototype, {
 
 		}
 
-		hsl.h = hue;
-		hsl.s = saturation;
-		hsl.l = lightness;
+		target.h = hue;
+		target.s = saturation;
+		target.l = lightness;
 
-		return hsl;
+		return target;
 
 	},
 
@@ -398,17 +403,23 @@ Object.assign( Color.prototype, {
 
 	},
 
-	offsetHSL: function ( h, s, l ) {
+	offsetHSL: function () {
 
-		var hsl = this.getHSL();
+		var hsl = {};
 
-		hsl.h += h; hsl.s += s; hsl.l += l;
+		return function ( h, s, l ) {
 
-		this.setHSL( hsl.h, hsl.s, hsl.l );
+			this.getHSL( hsl );
 
-		return this;
+			hsl.h += h; hsl.s += s; hsl.l += l;
 
-	},
+			this.setHSL( hsl.h, hsl.s, hsl.l );
+
+			return this;
+
+		};
+
+	}(),
 
 	add: function ( color ) {