Przeglądaj źródła

Iterable vectors (#22548)

* Add iterators to vectors

* Provide documentation

* Update translated documentation

Copy English documentation where applicable. Some languages did not
contain the math directory, which is where the English vector
documentation is located.
B3epBo0p 3 lat temu
rodzic
commit
fbdb7453b9

+ 4 - 0
docs/api/en/math/Vector2.html

@@ -36,6 +36,10 @@
 			vectors, complex numbers and so on,	however these are the most common uses in three.js.
 		</p>
 
+		<p>
+			Iterating through a Vector2 instance will yield its components (x, y) in the corresponding order.
+		</p>
+
 		<h2>Code Example</h2>
 
 		<code>

+ 4 - 0
docs/api/en/math/Vector3.html

@@ -35,6 +35,10 @@
 		vectors and so on, however these are the most common uses in three.js.
 		</p>
 
+		<p>
+		Iterating through a Vector3 instance will yield its components (x, y, z) in the corresponding order.
+		</p>
+
 
 		<h2>Code Example</h2>
 

+ 3 - 0
docs/api/en/math/Vector4.html

@@ -34,6 +34,9 @@
 		There are other things a 4D vector can be used to represent, however these are the most common uses in three.js.
 		</p>
 
+		<p>
+		Iterating through a Vector4 instance will yield its components (x, y, z, w) in the corresponding order.
+		</p>
 
 		<h2>Code Example</h2>
 

+ 4 - 0
docs/api/zh/math/Vector2.html

@@ -33,6 +33,10 @@
 			其他的一些事物也可以使用二维向量进行表示,比如说动量矢量、复数等等;但以上这些是它在three.js中的常用用途。
 		</p>
 
+		<p>
+			Iterating through a Vector2 instance will yield its components (x, y) in the corresponding order.
+		</p>
+		
 		<h2>代码示例</h2>
 
 		<code>

+ 3 - 0
docs/api/zh/math/Vector3.html

@@ -46,6 +46,9 @@
 		const d = a.distanceTo( b );
 		</code>
 
+		<p>
+			Iterating through a Vector3 instance will yield its components (x, y, z) in the corresponding order.
+		</p>
 
 		<h2>构造函数</h2>
 

+ 3 - 0
docs/api/zh/math/Vector4.html

@@ -45,6 +45,9 @@
 		const d = a.dot( b );
 		</code>
 
+		<p>
+			Iterating through a Vector4 instance will yield its components (x, y, z, w) in the corresponding order.
+		</p>
 
 		<h2>构造函数</h2>
 

+ 7 - 0
src/math/Vector2.js

@@ -470,6 +470,13 @@ class Vector2 {
 
 	}
 
+	*[ Symbol.iterator ]() {
+
+		yield this.x;
+		yield this.y;
+
+	}
+
 }
 
 Vector2.prototype.isVector2 = true;

+ 8 - 0
src/math/Vector3.js

@@ -727,6 +727,14 @@ class Vector3 {
 
 	}
 
+	*[ Symbol.iterator ]() {
+
+		yield this.x;
+		yield this.y;
+		yield this.z;
+
+	}
+
 }
 
 Vector3.prototype.isVector3 = true;

+ 9 - 0
src/math/Vector4.js

@@ -648,6 +648,15 @@ class Vector4 {
 
 	}
 
+	*[ Symbol.iterator ]() {
+
+		yield this.x;
+		yield this.y;
+		yield this.z;
+		yield this.w;
+
+	}
+
 }
 
 Vector4.prototype.isVector4 = true;