mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-08 01:17:47 +01:00
Remove duplicate method, trust escape analysis to prevent unnecessary allocations
This commit is contained in:
parent
5f2b06ffe7
commit
5a01c041cf
@ -1,80 +1,86 @@
|
||||
package net.minestom.server.utils.incubator;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
public interface Vec {
|
||||
|
||||
Vec ZERO = new VecImpl();
|
||||
|
||||
static @NotNull Vec of(double x, double y, double z) {
|
||||
@Contract(pure = true)
|
||||
static @NotNull Vec vec(double x, double y, double z) {
|
||||
return new VecImpl(x, y, z);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
static @NotNull Vec x(double x) {
|
||||
return vec(x, 0, 0);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
static @NotNull Vec y(double y) {
|
||||
return vec(0, y, 0);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
static @NotNull Vec z(double z) {
|
||||
return vec(0, 0, z);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
static @NotNull Vec xz(double x, double z) {
|
||||
return vec(x, 0, z);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
@NotNull Vec with(double x, double y, double z);
|
||||
|
||||
default @NotNull Vec with(@NotNull Vec vec) {
|
||||
return with(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
default @NotNull Vec add(double x, double y, double z) {
|
||||
return with(x() + x, y() + y, z() + z);
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
default @NotNull Vec add(@NotNull Vec vec) {
|
||||
return add(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
default @NotNull Vec sub(double x, double y, double z) {
|
||||
return with(x() - x, y() - y, z() - z);
|
||||
return with(x() + vec.x(), y() + vec.y(), z() + vec.z());
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
default @NotNull Vec sub(@NotNull Vec vec) {
|
||||
return sub(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
default @NotNull Vec mul(double x, double y, double z) {
|
||||
return with(x() * x, y() * y, z() * z);
|
||||
return with(x() - vec.x(), y() - vec.y(), z() - vec.z());
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
default @NotNull Vec mul(@NotNull Vec vec) {
|
||||
return mul(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
default @NotNull Vec div(double x, double y, double z) {
|
||||
return with(x() / x, y() / y, z() / z);
|
||||
return with(x() * vec.x(), y() * vec.y(), z() * vec.z());
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
default @NotNull Vec div(@NotNull Vec vec) {
|
||||
return div(vec.x(), vec.y(), vec.z());
|
||||
return with(x() / vec.x(), y() / vec.y(), z() / vec.z());
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
default @NotNull Vec neg() {
|
||||
return with(-x(), -y(), -z());
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
default @NotNull Vec abs() {
|
||||
return with(Math.abs(x()), Math.abs(y()), Math.abs(z()));
|
||||
}
|
||||
|
||||
default @NotNull Vec min(double x, double y, double z) {
|
||||
return with(Math.min(x(), x), Math.min(y(), y), Math.min(z(), z));
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
default @NotNull Vec min(@NotNull Vec vec) {
|
||||
return min(vec.x(), vec.y(), vec.z());
|
||||
}
|
||||
|
||||
default @NotNull Vec max(double x, double y, double z) {
|
||||
return with(Math.max(x(), x), Math.max(y(), y), Math.max(z(), z));
|
||||
return with(Math.min(x(), vec.x()), Math.min(y(), vec.y()), Math.min(z(), vec.z()));
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
default @NotNull Vec max(@NotNull Vec vec) {
|
||||
return max(vec.x(), vec.y(), vec.z());
|
||||
return with(Math.max(x(), vec.x()), Math.max(y(), vec.y()), Math.max(z(), vec.z()));
|
||||
}
|
||||
|
||||
@Contract(pure = true)
|
||||
double x();
|
||||
|
||||
@Contract(pure = true)
|
||||
double y();
|
||||
|
||||
@Contract(pure = true)
|
||||
double z();
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user