Skip to content

Commit 2f30588

Browse files
committed
1.45
1 parent 2c3baa2 commit 2f30588

File tree

18 files changed

+825
-24
lines changed

18 files changed

+825
-24
lines changed

common/build.gradle

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,9 @@ repositories {
1111
mavenCentral()
1212
}
1313
dependencies {
14-
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.7.2'
15-
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.7.2'
14+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.8.2'
15+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.8.2'
16+
implementation 'org.jetbrains:annotations:23.0.0'
1617
}
1718

1819
test {
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
package dev.felnull.fnjl;
22

33
public class FNJLBuildIn {
4-
protected static final String VERSION = "1.44";
4+
protected static final String VERSION = "1.45";
55
}

common/src/main/java/dev/felnull/fnjl/math/FNVec2d.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,10 @@ public void setY(double y) {
2727
this.y = y;
2828
}
2929

30+
public double distance(FNVec2d vec) {
31+
return Math.sqrt(Math.pow(x - vec.getX(), 2) + Math.pow(y - vec.getY(), 2));
32+
}
33+
3034
public double distance(FNVec2i vec) {
3135
return Math.sqrt(Math.pow(x - vec.getX(), 2) + Math.pow(y - vec.getY(), 2));
3236
}
Lines changed: 115 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,115 @@
1+
package dev.felnull.fnjl.math;
2+
3+
import dev.felnull.fnjl.tuple.FNQuadruple;
4+
import dev.felnull.fnjl.util.FNMath;
5+
6+
import java.util.Objects;
7+
8+
public class FNVec3d {
9+
private double x;
10+
private double y;
11+
private double z;
12+
13+
public FNVec3d(double x, double y, double z) {
14+
this.x = x;
15+
this.y = y;
16+
this.z = z;
17+
}
18+
19+
public double getX() {
20+
return x;
21+
}
22+
23+
public double getY() {
24+
return y;
25+
}
26+
27+
public double getZ() {
28+
return z;
29+
}
30+
31+
public double distance(FNVec3d vec) {
32+
return Math.sqrt(Math.pow(x - vec.getX(), 2) + Math.pow(y - vec.getY(), 2) + Math.pow(z - vec.getZ(), 2));
33+
}
34+
35+
public FNVec3d add(FNVec3d vec) {
36+
this.x += vec.getX();
37+
this.y += vec.getY();
38+
this.z += vec.getZ();
39+
return this;
40+
}
41+
42+
public FNVec3d sub(FNVec3d vec) {
43+
this.x -= vec.getX();
44+
this.y -= vec.getY();
45+
this.z -= vec.getZ();
46+
return this;
47+
}
48+
49+
public FNVec3d radians() {
50+
this.x = Math.toRadians(x);
51+
this.y = Math.toRadians(y);
52+
this.z = Math.toRadians(z);
53+
return this;
54+
}
55+
56+
public FNVec3d degrees() {
57+
this.x = Math.toDegrees(x);
58+
this.y = Math.toDegrees(y);
59+
this.z = Math.toDegrees(z);
60+
return this;
61+
}
62+
63+
public FNVec3d normalized() {
64+
normalize();
65+
return this;
66+
}
67+
68+
public boolean normalize() {
69+
double f = this.x * this.x + this.y * this.y + this.z * this.z;
70+
if (f < 1.0E-5D) {
71+
return false;
72+
} else {
73+
double g = FNMath.fastInvSqrt(f);
74+
this.x *= g;
75+
this.y *= g;
76+
this.z *= g;
77+
return true;
78+
}
79+
}
80+
81+
@Override
82+
public String toString() {
83+
return "FNVec3d{" +
84+
"x=" + x +
85+
", y=" + y +
86+
", z=" + z +
87+
'}';
88+
}
89+
90+
@Override
91+
public boolean equals(Object o) {
92+
if (this == o) return true;
93+
if (o == null || getClass() != o.getClass()) return false;
94+
FNVec3d fnVec3d = (FNVec3d) o;
95+
return Double.compare(fnVec3d.x, x) == 0 && Double.compare(fnVec3d.y, y) == 0 && Double.compare(fnVec3d.z, z) == 0;
96+
}
97+
98+
@Override
99+
public int hashCode() {
100+
return Objects.hash(x, y, z);
101+
}
102+
103+
public FNVec3f convertFloat() {
104+
return new FNVec3f((float) x, (float) y, (float) z);
105+
}
106+
107+
public FNVec3i convertInt() {
108+
return new FNVec3i((int) x, (int) y, (int) z);
109+
}
110+
111+
public FNVec4d toQuaternion() {
112+
FNQuadruple<Double, Double, Double, Double> q = FNMath.toQuaternion(x, y, z);
113+
return new FNVec4d(q.getLeft(), q.getLeftCenter(), q.getRightCenter(), q.getRight());
114+
}
115+
}
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
package dev.felnull.fnjl.math;
2+
3+
import dev.felnull.fnjl.tuple.FNQuadruple;
4+
import dev.felnull.fnjl.util.FNMath;
5+
import org.jetbrains.annotations.NotNull;
6+
7+
import java.util.Objects;
8+
9+
public class FNVec3f {
10+
private float x;
11+
private float y;
12+
private float z;
13+
14+
public FNVec3f(float x, float y, float z) {
15+
this.x = x;
16+
this.y = y;
17+
this.z = z;
18+
}
19+
20+
public float getX() {
21+
return x;
22+
}
23+
24+
public float getY() {
25+
return y;
26+
}
27+
28+
public float getZ() {
29+
return z;
30+
}
31+
32+
public double distance(@NotNull FNVec3f vec) {
33+
return Math.sqrt(Math.pow(x - vec.getX(), 2) + Math.pow(y - vec.getY(), 2) + Math.pow(z - vec.getZ(), 2));
34+
}
35+
36+
37+
public FNVec3f add(@NotNull FNVec3f vec) {
38+
this.x += vec.getX();
39+
this.y += vec.getY();
40+
this.z += vec.getZ();
41+
return this;
42+
}
43+
44+
public FNVec3f sub(@NotNull FNVec3f vec) {
45+
this.x -= vec.getX();
46+
this.y -= vec.getY();
47+
this.z -= vec.getZ();
48+
return this;
49+
}
50+
51+
public FNVec3f radians() {
52+
this.x = (float) Math.toRadians(x);
53+
this.y = (float) Math.toRadians(y);
54+
this.z = (float) Math.toRadians(z);
55+
return this;
56+
}
57+
58+
public FNVec3f degrees() {
59+
this.x = (float) Math.toDegrees(x);
60+
this.y = (float) Math.toDegrees(y);
61+
this.z = (float) Math.toDegrees(z);
62+
return this;
63+
}
64+
65+
@Override
66+
public boolean equals(Object o) {
67+
if (this == o) return true;
68+
if (o == null || getClass() != o.getClass()) return false;
69+
FNVec3f fnVec3f = (FNVec3f) o;
70+
return Float.compare(fnVec3f.x, x) == 0 && Float.compare(fnVec3f.y, y) == 0 && Float.compare(fnVec3f.z, z) == 0;
71+
}
72+
73+
@Override
74+
public int hashCode() {
75+
return Objects.hash(x, y, z);
76+
}
77+
78+
@Override
79+
public String toString() {
80+
return "FNVec3f{" +
81+
"x=" + x +
82+
", y=" + y +
83+
", z=" + z +
84+
'}';
85+
}
86+
87+
public FNVec3d convertDouble() {
88+
return new FNVec3d(x, y, z);
89+
}
90+
91+
public FNVec3i convertInt() {
92+
return new FNVec3i((int) x, (int) y, (int) z);
93+
}
94+
95+
public FNVec4f toQuaternion() {
96+
FNQuadruple<Double, Double, Double, Double> q = FNMath.toQuaternion(x, y, z);
97+
double qx = q.getLeft();
98+
double qy = q.getLeftCenter();
99+
double qz = q.getRightCenter();
100+
double qw = q.getRight();
101+
return new FNVec4f((float) qx, (float) qy, (float) qz, (float) qw);
102+
}
103+
}
Lines changed: 78 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,78 @@
1+
package dev.felnull.fnjl.math;
2+
3+
import org.jetbrains.annotations.NotNull;
4+
5+
import java.util.Objects;
6+
7+
public class FNVec3i {
8+
private int x;
9+
private int y;
10+
private int z;
11+
12+
public FNVec3i(int x, int y, int z) {
13+
this.x = x;
14+
this.y = y;
15+
this.z = z;
16+
}
17+
18+
public int getX() {
19+
return x;
20+
}
21+
22+
public int getY() {
23+
return y;
24+
}
25+
26+
public int getZ() {
27+
return z;
28+
}
29+
30+
public double distance(@NotNull FNVec3i vec) {
31+
return Math.sqrt(Math.pow(x - vec.getX(), 2) + Math.pow(y - vec.getY(), 2) + Math.pow(z - vec.getZ(), 2));
32+
}
33+
34+
public FNVec3i add(@NotNull FNVec3i vec) {
35+
this.x += vec.getX();
36+
this.y += vec.getY();
37+
this.z += vec.getZ();
38+
return this;
39+
}
40+
41+
public FNVec3i sub(@NotNull FNVec3i vec) {
42+
this.x -= vec.getX();
43+
this.y -= vec.getY();
44+
this.z -= vec.getZ();
45+
return this;
46+
}
47+
48+
@Override
49+
public String toString() {
50+
return "FNVec3i{" +
51+
"x=" + x +
52+
", y=" + y +
53+
", z=" + z +
54+
'}';
55+
}
56+
57+
@Override
58+
public boolean equals(Object o) {
59+
if (this == o) return true;
60+
if (o == null || getClass() != o.getClass()) return false;
61+
FNVec3i fnVec3i = (FNVec3i) o;
62+
return x == fnVec3i.x && y == fnVec3i.y && z == fnVec3i.z;
63+
}
64+
65+
@Override
66+
public int hashCode() {
67+
return Objects.hash(x, y, z);
68+
}
69+
70+
public FNVec3d convertDouble() {
71+
return new FNVec3d(x, y, z);
72+
}
73+
74+
public FNVec3f convertFloat() {
75+
return new FNVec3f((float) x, (float) y, (float) z);
76+
}
77+
78+
}

0 commit comments

Comments
 (0)