|
21 | 21 | * SOFTWARE.
|
22 | 22 | */
|
23 | 23 |
|
24 |
| -import { Kilometers, Radians, linearDistance } from '../main'; |
| 24 | +import { Radians, linearDistance } from '../main'; |
25 | 25 | import { Matrix } from './Matrix';
|
26 | 26 | import { Vector } from './Vector';
|
27 | 27 |
|
@@ -125,36 +125,36 @@ export class Vector3D<T extends number = number> {
|
125 | 125 | }
|
126 | 126 |
|
127 | 127 | // / Return a copy of this [Vector3D] scaled by [n];
|
128 |
| - scale(n: number): Vector3D { |
129 |
| - return new Vector3D(this.x * n, this.y * n, this.z * n); |
| 128 | + scale(n: number): Vector3D<T> { |
| 129 | + return new Vector3D<T>(this.x * n as T, this.y * n as T, this.z * n as T); |
130 | 130 | }
|
131 | 131 |
|
132 | 132 | // / Return a copy of this [Vector3D] with the elements negated.
|
133 |
| - negate(): Vector3D<Kilometers> { |
134 |
| - return this.scale(-1) as Vector3D<Kilometers>; |
| 133 | + negate(): Vector3D<T> { |
| 134 | + return this.scale(-1); |
135 | 135 | }
|
136 | 136 |
|
137 | 137 | /**
|
138 | 138 | * Return the Euclidean distance between this and another Vector3D.
|
139 | 139 | * @param v The other Vector3D.
|
140 | 140 | * @returns The distance between this and the other Vector3D.
|
141 | 141 | */
|
142 |
| - distance(v: Vector3D): number { |
| 142 | + distance(v: Vector3D<T>): T { |
143 | 143 | return linearDistance(this, v);
|
144 | 144 | }
|
145 | 145 |
|
146 | 146 | /**
|
147 | 147 | * Convert this to a unit Vector3D.
|
148 | 148 | * @returns A unit Vector3D.
|
149 | 149 | */
|
150 |
| - normalize(): Vector3D { |
| 150 | + normalize(): Vector3D<T> { |
151 | 151 | const m = this.magnitude();
|
152 | 152 |
|
153 | 153 | if (m === 0) {
|
154 |
| - return Vector3D.origin; |
| 154 | + return Vector3D.origin as Vector3D<T>; |
155 | 155 | }
|
156 | 156 |
|
157 |
| - return new Vector3D(this.x / m, this.y / m, this.z / m); |
| 157 | + return new Vector3D<T>(this.x / m as T, this.y / m as T, this.z / m as T); |
158 | 158 | }
|
159 | 159 |
|
160 | 160 | // Calculate the dot product of this and another [Vector3D].
|
@@ -259,7 +259,7 @@ export class Vector3D<T extends number = number> {
|
259 | 259 | }
|
260 | 260 |
|
261 | 261 | // / Return the unit vector that bisects this and another [Vector3D].
|
262 |
| - bisect(v: Vector3D): Vector3D { |
| 262 | + bisect(v: Vector3D<T>): Vector3D<T> { |
263 | 263 | return this.scale(v.magnitude()).add(v.scale(this.magnitude())).normalize();
|
264 | 264 | }
|
265 | 265 |
|
|
0 commit comments