mirror of
https://github.com/Minestom/Minestom.git
synced 2025-01-02 14:38:26 +01:00
Move classes & some methods
This commit is contained in:
parent
0b37195d23
commit
4414baf89b
@ -0,0 +1,83 @@
|
||||
package net.minestom.server.utils.coordinate;
|
||||
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a 3D point.
|
||||
* <p>
|
||||
* Can either be a {@link Pos} or {@link Vec}.
|
||||
* Interface will become {@code sealed} in the future.
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
public interface Point {
|
||||
|
||||
/**
|
||||
* Gets the X coordinate.
|
||||
*
|
||||
* @return the X coordinate
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
double x();
|
||||
|
||||
/**
|
||||
* Gets the Y coordinate.
|
||||
*
|
||||
* @return the Y coordinate
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
double y();
|
||||
|
||||
/**
|
||||
* Gets the Z coordinate.
|
||||
*
|
||||
* @return the Z coordinate
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
double z();
|
||||
|
||||
/**
|
||||
* Gets the distance between this point and another. The value of this
|
||||
* method is not cached and uses a costly square-root function, so do not
|
||||
* repeatedly call this method to get the vector's magnitude. NaN will be
|
||||
* returned if the inner result of the sqrt() function overflows, which
|
||||
* will be caused if the distance is too long.
|
||||
*
|
||||
* @param point the other point
|
||||
* @return the distance
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
default double distance(@NotNull Point point) {
|
||||
return Math.sqrt(MathUtils.square(x() - point.x()) +
|
||||
MathUtils.square(y() - point.y()) +
|
||||
MathUtils.square(z() - point.z()));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the squared distance between this point and another.
|
||||
*
|
||||
* @param point the other point
|
||||
* @return the squared distance
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
default double distanceSquared(@NotNull Point point) {
|
||||
return MathUtils.square(x() - point.x()) +
|
||||
MathUtils.square(y() - point.y()) +
|
||||
MathUtils.square(z() - point.z());
|
||||
}
|
||||
|
||||
/**
|
||||
* Converts all coordinates to integers.
|
||||
*
|
||||
* @return a new point representing a block position
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
default @NotNull Point asBlockPosition() {
|
||||
final int castedY = (int) y();
|
||||
return new Vec((int) Math.floor(x()),
|
||||
(y() == castedY) ? castedY : castedY + 1,
|
||||
(int) Math.floor(z()));
|
||||
}
|
||||
}
|
@ -1,4 +1,4 @@
|
||||
package net.minestom.server.utils.incubator;
|
||||
package net.minestom.server.utils.coordinate;
|
||||
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
@ -1,4 +1,4 @@
|
||||
package net.minestom.server.utils.incubator;
|
||||
package net.minestom.server.utils.coordinate;
|
||||
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
@ -207,36 +207,6 @@ public final class Vec implements Point {
|
||||
return new Vec(x / length, y / length, z / length);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the distance between this vector and another. The value of this
|
||||
* method is not cached and uses a costly square-root function, so do not
|
||||
* repeatedly call this method to get the vector's magnitude. NaN will be
|
||||
* returned if the inner result of the sqrt() function overflows, which
|
||||
* will be caused if the distance is too long.
|
||||
*
|
||||
* @param vec the other vector
|
||||
* @return the distance
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public double distance(@NotNull Vec vec) {
|
||||
return Math.sqrt(MathUtils.square(x - vec.x) +
|
||||
MathUtils.square(y - vec.y) +
|
||||
MathUtils.square(z - vec.z));
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the squared distance between this vector and another.
|
||||
*
|
||||
* @param vec the other vector
|
||||
* @return the squared distance
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
public double distanceSquared(@NotNull Vec vec) {
|
||||
return MathUtils.square(x - vec.x) +
|
||||
MathUtils.square(y - vec.y) +
|
||||
MathUtils.square(z - vec.z);
|
||||
}
|
||||
|
||||
/**
|
||||
* Gets the angle between this vector and another in radians.
|
||||
*
|
@ -1,52 +0,0 @@
|
||||
package net.minestom.server.utils.incubator;
|
||||
|
||||
import org.jetbrains.annotations.ApiStatus;
|
||||
import org.jetbrains.annotations.Contract;
|
||||
import org.jetbrains.annotations.NotNull;
|
||||
|
||||
/**
|
||||
* Represents a 3D point.
|
||||
* <p>
|
||||
* Can either be a {@link Pos} or {@link Vec}.
|
||||
* Interface will become {@code sealed} in the future.
|
||||
*/
|
||||
@ApiStatus.NonExtendable
|
||||
public interface Point {
|
||||
|
||||
/**
|
||||
* Gets the X coordinate.
|
||||
*
|
||||
* @return the X coordinate
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
double x();
|
||||
|
||||
/**
|
||||
* Gets the Y coordinate.
|
||||
*
|
||||
* @return the Y coordinate
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
double y();
|
||||
|
||||
/**
|
||||
* Gets the Z coordinate.
|
||||
*
|
||||
* @return the Z coordinate
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
double z();
|
||||
|
||||
/**
|
||||
* Converts all coordinates to integers.
|
||||
*
|
||||
* @return a new point representing a block position
|
||||
*/
|
||||
@Contract(pure = true)
|
||||
default @NotNull Point asBlockPosition() {
|
||||
final int castedY = (int) y();
|
||||
return new Vec((int) Math.floor(x()),
|
||||
(y() == castedY) ? castedY : castedY + 1,
|
||||
(int) Math.floor(z()));
|
||||
}
|
||||
}
|
@ -36,7 +36,7 @@ import net.minestom.server.monitoring.TickMonitor;
|
||||
import net.minestom.server.utils.MathUtils;
|
||||
import net.minestom.server.utils.Position;
|
||||
import net.minestom.server.utils.Vector;
|
||||
import net.minestom.server.utils.incubator.Vec;
|
||||
import net.minestom.server.utils.coordinate.Vec;
|
||||
import net.minestom.server.utils.time.TimeUnit;
|
||||
import net.minestom.server.world.DimensionType;
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user