Quellcode durchsuchen

Vector2, Vector3, Quaternion: add clone()

customisations
alemart vor 10 Monaten
Ursprung
Commit
438b5871da

+ 10
- 0
docs/api/quaternion.md Datei anzeigen

@@ -42,6 +42,16 @@ Compute the magnitude of the quaternion.
42 42
 
43 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 55
 ### equals
46 56
 
47 57
 `quaternion.equals(q: Quaternion): boolean`

+ 10
- 0
docs/api/vector2.md Datei anzeigen

@@ -72,6 +72,16 @@ Compute a unit vector pointing to `v` from `this`.
72 72
 
73 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 85
 ### equals
76 86
 
77 87
 `vector.equals(v: Vector2): boolean`

+ 10
- 0
docs/api/vector3.md Datei anzeigen

@@ -78,6 +78,16 @@ Compute a unit vector pointing to `v` from `this`.
78 78
 
79 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 91
 ### cross
82 92
 
83 93
 `vector.cross(v: Vector3): Vector3`

+ 9
- 0
src/geometry/quaternion.ts Datei anzeigen

@@ -121,6 +121,15 @@ export class Quaternion
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 133
      * Check if this and q have the same coordinates
125 134
      * @param q a quaternion
126 135
      * @returns true if this and q have the same coordinates

+ 10
- 11
src/geometry/vector2.ts Datei anzeigen

@@ -132,7 +132,16 @@ export class Vector2
132 132
      */
133 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,16 +167,6 @@ export class Vector2
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 170
      * Set the coordinates of this vector
172 171
      * @param x x-coordinate
173 172
      * @param y y-coordinate

+ 10
- 11
src/geometry/vector3.ts Datei anzeigen

@@ -144,7 +144,7 @@ export class Vector3
144 144
      */
145 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,6 +162,15 @@ export class Vector3
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 174
      * Check if this and v have the same coordinates
166 175
      * @param v a vector
167 176
      * @returns true if this and v have the same coordinates
@@ -185,16 +194,6 @@ export class Vector3
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 197
      * Set the coordinates of this vector
199 198
      * @param x x-coordinate
200 199
      * @param y y-coordinate

+ 3
- 3
src/trackers/pointer-tracker/pointer-tracker.ts Datei anzeigen

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

Laden…
Abbrechen
Speichern