summaryrefslogtreecommitdiffstats
path: root/src/main/java/net/minecraft/server/Vec3D.java
blob: 2122b93f331ac6f614187e29e57305d4d5955570 (plain)
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
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
package net.minecraft.server;

public class Vec3D {

    private static final ThreadLocal d = new Vec3DPoolThreadLocal();
    public double a;
    public double b;
    public double c;
    public Vec3D next; // CraftBukkit

    public static Vec3D a(double d0, double d1, double d2) {
        return new Vec3D(d0, d1, d2);
    }

    public static Vec3DPool a() {
        return (Vec3DPool) d.get();
    }

    protected Vec3D(double d0, double d1, double d2) {
        if (d0 == -0.0D) {
            d0 = 0.0D;
        }

        if (d1 == -0.0D) {
            d1 = 0.0D;
        }

        if (d2 == -0.0D) {
            d2 = 0.0D;
        }

        this.a = d0;
        this.b = d1;
        this.c = d2;
    }

    protected Vec3D b(double d0, double d1, double d2) {
        this.a = d0;
        this.b = d1;
        this.c = d2;
        return this;
    }

    public Vec3D b() {
        double d0 = (double) MathHelper.sqrt(this.a * this.a + this.b * this.b + this.c * this.c);

        return d0 < 1.0E-4D ? a().create(0.0D, 0.0D, 0.0D) : a().create(this.a / d0, this.b / d0, this.c / d0);
    }

    public double b(Vec3D vec3d) {
        return this.a * vec3d.a + this.b * vec3d.b + this.c * vec3d.c;
    }

    public Vec3D add(double d0, double d1, double d2) {
        return a().create(this.a + d0, this.b + d1, this.c + d2);
    }

    public double d(Vec3D vec3d) {
        double d0 = vec3d.a - this.a;
        double d1 = vec3d.b - this.b;
        double d2 = vec3d.c - this.c;

        return (double) MathHelper.sqrt(d0 * d0 + d1 * d1 + d2 * d2);
    }

    public double distanceSquared(Vec3D vec3d) {
        double d0 = vec3d.a - this.a;
        double d1 = vec3d.b - this.b;
        double d2 = vec3d.c - this.c;

        return d0 * d0 + d1 * d1 + d2 * d2;
    }

    public double d(double d0, double d1, double d2) {
        double d3 = d0 - this.a;
        double d4 = d1 - this.b;
        double d5 = d2 - this.c;

        return d3 * d3 + d4 * d4 + d5 * d5;
    }

    public double c() {
        return (double) MathHelper.sqrt(this.a * this.a + this.b * this.b + this.c * this.c);
    }

    public Vec3D b(Vec3D vec3d, double d0) {
        double d1 = vec3d.a - this.a;
        double d2 = vec3d.b - this.b;
        double d3 = vec3d.c - this.c;

        if (d1 * d1 < 1.0000000116860974E-7D) {
            return null;
        } else {
            double d4 = (d0 - this.a) / d1;

            return d4 >= 0.0D && d4 <= 1.0D ? a().create(this.a + d1 * d4, this.b + d2 * d4, this.c + d3 * d4) : null;
        }
    }

    public Vec3D c(Vec3D vec3d, double d0) {
        double d1 = vec3d.a - this.a;
        double d2 = vec3d.b - this.b;
        double d3 = vec3d.c - this.c;

        if (d2 * d2 < 1.0000000116860974E-7D) {
            return null;
        } else {
            double d4 = (d0 - this.b) / d2;

            return d4 >= 0.0D && d4 <= 1.0D ? a().create(this.a + d1 * d4, this.b + d2 * d4, this.c + d3 * d4) : null;
        }
    }

    public Vec3D d(Vec3D vec3d, double d0) {
        double d1 = vec3d.a - this.a;
        double d2 = vec3d.b - this.b;
        double d3 = vec3d.c - this.c;

        if (d3 * d3 < 1.0000000116860974E-7D) {
            return null;
        } else {
            double d4 = (d0 - this.c) / d3;

            return d4 >= 0.0D && d4 <= 1.0D ? a().create(this.a + d1 * d4, this.b + d2 * d4, this.c + d3 * d4) : null;
        }
    }

    public String toString() {
        return "(" + this.a + ", " + this.b + ", " + this.c + ")";
    }

    public void a(float f) {
        float f1 = MathHelper.cos(f);
        float f2 = MathHelper.sin(f);
        double d0 = this.a;
        double d1 = this.b * (double) f1 + this.c * (double) f2;
        double d2 = this.c * (double) f1 - this.b * (double) f2;

        this.a = d0;
        this.b = d1;
        this.c = d2;
    }

    public void b(float f) {
        float f1 = MathHelper.cos(f);
        float f2 = MathHelper.sin(f);
        double d0 = this.a * (double) f1 + this.c * (double) f2;
        double d1 = this.b;
        double d2 = this.c * (double) f1 - this.a * (double) f2;

        this.a = d0;
        this.b = d1;
        this.c = d2;
    }
}