Pārlūkot izejas kodu

Vector2, Vector3, Quaternion: add clone()

customisations
alemart 10 mēnešus atpakaļ
vecāks
revīzija
438b5871da

+ 10
- 0
docs/api/quaternion.md Parādīt failu

42
 
42
 
43
 The magnitude of the quaternion.
43
 The magnitude of the quaternion.
44
 
44
 
45
+### clone
46
+
47
+`quaternion.clone(): Quaternion`
48
+
49
+Clone the quaternion.
50
+
51
+**Returns**
52
+
53
+A new quaternion object with the same coordinates as `this`.
54
+
45
 ### equals
55
 ### equals
46
 
56
 
47
 `quaternion.equals(q: Quaternion): boolean`
57
 `quaternion.equals(q: Quaternion): boolean`

+ 10
- 0
docs/api/vector2.md Parādīt failu

72
 
72
 
73
 A new unit vector pointing to `v` from `this`.
73
 A new unit vector pointing to `v` from `this`.
74
 
74
 
75
+### clone
76
+
77
+`vector.clone(): Vector2`
78
+
79
+Clone the vector.
80
+
81
+**Returns**
82
+
83
+A new vector object with the same coordinates as `this`.
84
+
75
 ### equals
85
 ### equals
76
 
86
 
77
 `vector.equals(v: Vector2): boolean`
87
 `vector.equals(v: Vector2): boolean`

+ 10
- 0
docs/api/vector3.md Parādīt failu

78
 
78
 
79
 A new unit vector pointing to `v` from `this`.
79
 A new unit vector pointing to `v` from `this`.
80
 
80
 
81
+### clone
82
+
83
+`vector.clone(): Vector3`
84
+
85
+Clone the vector.
86
+
87
+**Returns**
88
+
89
+A new vector object with the same coordinates as `this`.
90
+
81
 ### cross
91
 ### cross
82
 
92
 
83
 `vector.cross(v: Vector3): Vector3`
93
 `vector.cross(v: Vector3): Vector3`

+ 9
- 0
src/geometry/quaternion.ts Parādīt failu

121
     }
121
     }
122
 
122
 
123
     /**
123
     /**
124
+     * Clone this quaternion
125
+     * @returns a clone of this quaternion
126
+     */
127
+    clone(): Quaternion
128
+    {
129
+        return new Quaternion(this._x, this._y, this._z, this._w);
130
+    }
131
+
132
+    /**
124
      * Check if this and q have the same coordinates
133
      * Check if this and q have the same coordinates
125
      * @param q a quaternion
134
      * @param q a quaternion
126
      * @returns true if this and q have the same coordinates
135
      * @returns true if this and q have the same coordinates

+ 10
- 11
src/geometry/vector2.ts Parādīt failu

132
      */
132
      */
133
     directionTo(v: Vector2): Vector2
133
     directionTo(v: Vector2): Vector2
134
     {
134
     {
135
-        return v._clone()._subtract(this)._normalize();
135
+        return v.clone()._subtract(this)._normalize();
136
+    }
137
+
138
+    /**
139
+     * Clone this vector
140
+     * @returns a clone of this vector
141
+     */
142
+    clone(): Vector2
143
+    {
144
+        return new Vector2(this._x, this._y);
136
     }
145
     }
137
 
146
 
138
     /**
147
     /**
158
     }
167
     }
159
 
168
 
160
     /**
169
     /**
161
-     * Clone this vector
162
-     * @returns a clone of this vector
163
-     * @internal
164
-     */
165
-    _clone(): Vector2
166
-    {
167
-        return new Vector2(this._x, this._y);
168
-    }
169
-
170
-    /**
171
      * Set the coordinates of this vector
170
      * Set the coordinates of this vector
172
      * @param x x-coordinate
171
      * @param x x-coordinate
173
      * @param y y-coordinate
172
      * @param y y-coordinate

+ 10
- 11
src/geometry/vector3.ts Parādīt failu

144
      */
144
      */
145
     directionTo(v: Vector3): Vector3
145
     directionTo(v: Vector3): Vector3
146
     {
146
     {
147
-        return v._clone()._subtract(this)._normalize();
147
+        return v.clone()._subtract(this)._normalize();
148
     }
148
     }
149
 
149
 
150
     /**
150
     /**
162
     }
162
     }
163
 
163
 
164
     /**
164
     /**
165
+     * Clone this vector
166
+     * @returns a clone of this vector
167
+     */
168
+    clone(): Vector3
169
+    {
170
+        return new Vector3(this._x, this._y, this._z);
171
+    }
172
+
173
+    /**
165
      * Check if this and v have the same coordinates
174
      * Check if this and v have the same coordinates
166
      * @param v a vector
175
      * @param v a vector
167
      * @returns true if this and v have the same coordinates
176
      * @returns true if this and v have the same coordinates
185
     }
194
     }
186
 
195
 
187
     /**
196
     /**
188
-     * Clone this vector
189
-     * @returns a clone of this vector
190
-     * @internal
191
-     */
192
-    _clone(): Vector3
193
-    {
194
-        return new Vector3(this._x, this._y, this._z);
195
-    }
196
-
197
-    /**
198
      * Set the coordinates of this vector
197
      * Set the coordinates of this vector
199
      * @param x x-coordinate
198
      * @param x x-coordinate
200
      * @param y y-coordinate
199
      * @param y y-coordinate

+ 3
- 3
src/trackers/pointer-tracker/pointer-tracker.ts Parādīt failu

285
 
285
 
286
             // determine the position delta
286
             // determine the position delta
287
             const deltaPosition = !previous ? Vector2.ZERO :
287
             const deltaPosition = !previous ? Vector2.ZERO :
288
-                                  position._clone()._subtract(previous.position);
288
+                                  position.clone()._subtract(previous.position);
289
 
289
 
290
             // determine the initial position
290
             // determine the initial position
291
             const initialPosition = previous ? previous.initialPosition :
291
             const initialPosition = previous ? previous.initialPosition :
292
-                                    Object.freeze(position._clone());
292
+                                    Object.freeze(position.clone());
293
 
293
 
294
             // determine the velocity
294
             // determine the velocity
295
-            const velocity = deltaPosition._clone()._scale(inverseDeltaTime);
295
+            const velocity = deltaPosition.clone()._scale(inverseDeltaTime);
296
 
296
 
297
             // determine the elapsed time since the tracking began
297
             // determine the elapsed time since the tracking began
298
             const elapsedTime = previous ? previous.elapsedTime + deltaTime : 0;
298
             const elapsedTime = previous ? previous.elapsedTime + deltaTime : 0;

Notiek ielāde…
Atcelt
Saglabāt