* Math: Make Euler, Quaternion and Color iterable. * Euler: Honor order in iterator. * Update Euler.html
@@ -13,6 +13,10 @@
Class representing a color.
</p>
+ <p>
+ Iterating through a [name] instance will yield its components (r, g, b) in the corresponding order.
+ </p>
+
<h2>Code Examples</h2>
<p>
@@ -16,6 +16,10 @@
axes in specified amounts per axis, and a specified axis order.
+ Iterating through a [name] instance will yield its components (x, y, z, order) in the corresponding order.
<h2>Code Example</h2>
<code>const a = new THREE.Euler( 0, 1, 1.57, 'XYZ' );
@@ -14,6 +14,10 @@
Quaternions are used in three.js to represent [link:https://en.wikipedia.org/wiki/Quaternions_and_spatial_rotation rotations].
+ Iterating through a [name] instance will yield its components (x, y, z, w) in the corresponding order.
<code>
@@ -37,7 +37,7 @@
- Iterating through a Vector2 instance will yield its components (x, y) in the corresponding order.
+ Iterating through a [name] instance will yield its components (x, y) in the corresponding order.
@@ -36,7 +36,7 @@
- Iterating through a Vector3 instance will yield its components (x, y, z) in the corresponding order.
+ Iterating through a [name] instance will yield its components (x, y, z) in the corresponding order.
@@ -35,7 +35,7 @@
- Iterating through a Vector4 instance will yield its components (x, y, z, w) in the corresponding order.
@@ -594,6 +594,14 @@ class Color {
}
+ *[ Symbol.iterator ]() {
+ yield this.r;
+ yield this.g;
+ yield this.b;
+ }
Color.NAMES = _colorKeywords;
@@ -297,6 +297,15 @@ class Euler {
_onChangeCallback() {}
+ yield this._x;
+ yield this._y;
+ yield this._z;
+ yield this._order;
Euler.prototype.isEuler = true;
@@ -682,6 +682,15 @@ class Quaternion {
+ yield this._w;
Quaternion.prototype.isQuaternion = true;
@@ -651,6 +651,16 @@ export default QUnit.module( 'Maths', () => {
} );
+ QUnit.test( 'iterable', ( assert ) => {
+ var c = new Color( 0.5, 0.75, 1 );
+ var array = [ ...c ];
+ assert.strictEqual( array[ 0 ], 0.5, 'Color is iterable.' );
+ assert.strictEqual( array[ 1 ], 0.75, 'Color is iterable.' );
+ assert.strictEqual( array[ 2 ], 1, 'Color is iterable.' );
+ } );
@@ -413,6 +413,17 @@ export default QUnit.module( 'Maths', () => {
+ var e = new Euler( 0.5, 0.75, 1, 'YZX' );
+ var array = [ ...e ];
+ assert.strictEqual( array[ 0 ], 0.5, 'Euler is iterable.' );
+ assert.strictEqual( array[ 1 ], 0.75, 'Euler is iterable.' );
+ assert.strictEqual( array[ 2 ], 1, 'Euler is iterable.' );
+ assert.strictEqual( array[ 3 ], 'YZX', 'Euler is iterable.' );
@@ -850,6 +850,17 @@ export default QUnit.module( 'Maths', () => {
+ var q = new Quaternion( 0, 0.5, 0.7, 1 );
+ var array = [ ...q ];
+ assert.strictEqual( array[ 0 ], 0, 'Quaternion is iterable.' );
+ assert.strictEqual( array[ 1 ], 0.5, 'Quaternion is iterable.' );
+ assert.strictEqual( array[ 2 ], 0.7, 'Quaternion is iterable.' );
+ assert.strictEqual( array[ 3 ], 1, 'Quaternion is iterable.' );
@@ -686,6 +686,15 @@ export default QUnit.module( 'Maths', () => {
+ var v = new Vector2( 0, 1 );
+ var array = [ ...v ];
+ assert.strictEqual( array[ 0 ], 0, 'Vector2 is iterable.' );
+ assert.strictEqual( array[ 1 ], 1, 'Vector2 is iterable.' );
@@ -1006,6 +1006,16 @@ export default QUnit.module( 'Maths', () => {
+ var v = new Vector3( 0, 0.5, 1 );
+ assert.strictEqual( array[ 0 ], 0, 'Vector3 is iterable.' );
+ assert.strictEqual( array[ 1 ], 0.5, 'Vector3 is iterable.' );
+ assert.strictEqual( array[ 2 ], 1, 'Vector3 is iterable.' );
@@ -717,6 +717,17 @@ export default QUnit.module( 'Maths', () => {
+ var v = new Vector4( 0, 0.3, 0.7, 1 );
+ assert.strictEqual( array[ 0 ], 0, 'Vector4 is iterable.' );
+ assert.strictEqual( array[ 1 ], 0.3, 'Vector4 is iterable.' );
+ assert.strictEqual( array[ 2 ], 0.7, 'Vector4 is iterable.' );
+ assert.strictEqual( array[ 3 ], 1, 'Vector4 is iterable.' );