File size: 2,049 Bytes
5f32ba4
4e1da8c
 
 
 
 
 
 
 
 
 
3b7903d
4e1da8c
 
 
 
 
 
cc654e9
ec3121c
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
cc654e9
 
 
ec3121c
 
 
 
4e1da8c
5f32ba4
 
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
class Vector3 {
    x: number;
    y: number;
    z: number;

    constructor(x: number = 0, y: number = 0, z: number = 0) {
        this.x = x;
        this.y = y;
        this.z = z;
    }

    set(x: number, y: number, z: number): Vector3 {
        this.x = x;
        this.y = y;
        this.z = z;

        return this;
    }

    add(v: Vector3): Vector3;
    add(v: number): Vector3;
    add(v: Vector3 | number): Vector3 {
        if (typeof v === "number") {
            this.x += v;
            this.y += v;
            this.z += v;
        } else {
            this.x += v.x;
            this.y += v.y;
            this.z += v.z;
        }

        return this;
    }

    subtract(v: Vector3): Vector3;
    subtract(v: number): Vector3;
    subtract(v: Vector3 | number): Vector3 {
        if (typeof v === "number") {
            this.x -= v;
            this.y -= v;
            this.z -= v;
        } else {
            this.x -= v.x;
            this.y -= v.y;
            this.z -= v.z;
        }

        return this;
    }

    multiply(v: Vector3): Vector3;
    multiply(v: number): Vector3;
    multiply(v: Vector3 | number): Vector3 {
        if (typeof v === "number") {
            this.x *= v;
            this.y *= v;
            this.z *= v;
        } else {
            this.x *= v.x;
            this.y *= v.y;
            this.z *= v.z;
        }

        return this;
    }

    lerp(v: Vector3, t: number): Vector3 {
        this.x += (v.x - this.x) * t;
        this.y += (v.y - this.y) * t;
        this.z += (v.z - this.z) * t;

        return this;
    }

    length(): number {
        return Math.sqrt(this.x * this.x + this.y * this.y + this.z * this.z);
    }

    normalize(): Vector3 {
        const length = this.length();
        this.x /= length;
        this.y /= length;
        this.z /= length;

        return this;
    }

    flat(): number[] {
        return [this.x, this.y, this.z];
    }

    clone(): Vector3 {
        return new Vector3(this.x, this.y, this.z);
    }
}

export { Vector3 };