All files / ts/extensions extensionsVector3.ts

100% Statements 19/19
100% Branches 6/6
100% Functions 4/4
100% Lines 19/19

Press n or j to go to the next uncovered block, b, p or k for the previous block.

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 341x             1x 1x 1x 1x   1x 3x         1x 2x 2x   2x 1x 2x 1x 2x 1x   2x   1x 1x  
import { IVector3, Vector3 } from "../models/vector3.js"
 
declare module "../models/vector3.js" {
    interface Vector3 extends IVector3 { 
        getNormalize(): IVector3;
    }
}
Vector3.prototype.set = function (vector: IVector3): void {
    this.x = vector.x;
    this.y = vector.y;
    this.z = vector.z;
}
Vector3.prototype.getLength = function (): number {
    return Math.sqrt(
        (this.x * this.x) +
        (this.y * this.y) +
        (this.z * this.z));
}
Vector3.prototype.getNormalize = function (): IVector3 {
    const length = this.getLength();
    const nomalized = new Vector3();
 
    if (this.x != 0)
        nomalized.x = this.x / length;
    if (this.y != 0)
        nomalized.y = this.y / length;
    if (this.z != 0)
        nomalized.z = this.z / length;
 
    return nomalized;
}
Vector3.prototype.getScalar = function (vector: Vector3): number {
    return this.x * vector.x + this.y * vector.y + this.z * vector.z;
}