* 获得向量的单位向量 * 如果向量的模长为0,则返回(0,0) * @returns
()
| 52 | * @returns |
| 53 | */ |
| 54 | normalize(): Vector { |
| 55 | const mag = this.magnitude(); |
| 56 | const x = this.x / mag; |
| 57 | const y = this.y / mag; |
| 58 | |
| 59 | if (Number.isNaN(x) || Number.isNaN(y)) { |
| 60 | return Vector.getZero(); |
| 61 | } |
| 62 | |
| 63 | return new Vector(x, y); |
| 64 | } |
| 65 | |
| 66 | dot(vector: Vector): number { |
| 67 | return this.x * vector.x + this.y * vector.y; |
no test coverage detected