Repository navigation
Expand file tree
/
Copy pathVector2F.java
More file actions
120 lines (74 loc) · 2.39 KB
/
Copy pathVector2F.java
File metadata and controls
120 lines (74 loc) · 2.39 KB
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
import org.lwjgl.util.vector.Vector2f;
import java.util.Objects;
public class Vector2F {
private float x;
private float y;
public Vector2F(float x, float y) {
this.x = x;
this.y = y;
}
public float length() {
return (float) Math.sqrt((x * x) + (y * y));
}
public float dotProd(Vector2F other) {
return (this.x * other.getX()) + (this.y * other.getY());
}
public Vector2F normalize() {
double len = this.length();
x /= len;
y /= len;
return this;
}
public Vector2F rotate(float angle) {
double rad = Math.toRadians(angle);
double cos = Math.cos(rad);
double sin = Math.sin(rad);
return new Vector2F((float) (x * cos - y * sin), (float) (x * sin + y * cos));
}
public Vector2F add(Vector2F other) {
return new Vector2F(this.x + other.getX(), this.y + other.getY());
}
public Vector2F add(float other) {
return new Vector2F(this.x + other, this.y + other);
}
public Vector2F sub(Vector2F other) {
return new Vector2F(this.x - other.getX(), this.y - other.getY());
}
public Vector2F sub(float other) {
return new Vector2F(this.x - other, this.y - other);
}
public Vector2F mult(Vector2F other) {
return new Vector2F(this.x * other.getX(), this.y * other.getY());
}
public Vector2F mult(float other) {
return new Vector2F(this.x * other, this.y * other);
}
public Vector2F div(Vector2F other) {
return new Vector2F(this.x / other.getX(), this.y / other.getY());
}
public Vector2F div(float other) {
return new Vector2F(this.x / other, this.y / other);
}
public float getX() {
return x;
}
public void setX(float x) {
this.x = x;
}
public float getY() {
return y;
}
public void setY(float y) {
this.y = y;
}
public String toString() {
return "(" + x + "," + y + ")";
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
if (o == null || getClass() != o.getClass()) return false;
Vector2F vector2F = (Vector2F) o;
return this.x == vector2F.x && this.y == vector2F.y;
}
}