Interface Point
This interface has three main implementations:
Vec- Double-precision coordinates (x, y, z)Pos- Double-precision coordinates with view angles (yaw, pitch)BlockVec- Integer block-aligned coordinates
Coordinate Scale:
- Block: Individual voxel position (1 block)
- Section: 16 blocks (
SECTION_SIZE) - Chunk: Same as a section in X and Z axis (
SECTION_SIZE) - Region: 512 blocks or 32 sections (
REGION_SIZE)
Coordinate Conventions:
- Three
doublevalues represent global coordinates - Three
doublevalues following twofloatvalues represent global position coordinates - Three
intvalues represent global block coordinates
Directionality:
- X increases towards East, decreases towards West
- Y increases upwards, decreases downwards
- Z increases towards South, decreases towards North
Avoid relying on Object.equals(Object) for direct Point comparison, as different implementations
may represent the same 3D coordinates but be different instances. Use samePoint(Point)
or samePoint(Point, double) instead. You can also ensure both points are of the same implementation, but this is fragile.
Usage: Prefer accepting Point in method parameters when only
coordinate access (x/y/z) is needed. This avoids forcing callers to convert
between specific implementations.
All implementations are immutable and subject to become value types. Type conversions are also explicit to avoid precision loss.
-
Field Summary
FieldsModifier and TypeFieldDescriptionstatic final doubleThe smallest difference between two double values to consider them equal if applicable.static final intRepresents the size of a region (32 sections) or (512 blocks).static final intRepresents the size of a section (16 blocks). -
Method Summary
Modifier and TypeMethodDescriptionabs()Represents this point with all coordinates as their absolute values.add(double value) Creates a new point by adding the provided value to this point coordinates for all XYZ.add(double x, double y, double z) Creates a new point by adding the provided values to this point coordinates.Creates a new point by adding another point coordinates to this point coordinates.default doubleGets the angle between this point and another in radians.default BlockVecConverts this point to aBlockVec.default PosasPos()Converts this point to aPos.default VecasVec()Converts this point to aVec.default intblockX()Gets the floored value of the X componentdefault intblockY()Gets the floored value of the Y componentdefault intblockZ()Gets the floored value of the Z componentdefault intchunkX()The chunk X coordinate ofblockX(), also known as the section XsectionX()default intchunkZ()The chunk Z coordinate ofblockZ(), also known as the section ZsectionZ()Calculates the cross product of this point with another.default doubledistance(double x, double y, double z) Gets the distance between this point and the provided coordinates.default doubleGets the distance between this point and another.default doubledistanceSquared(double x, double y, double z) Gets the squared distance between this point and the provided coordinates.default doubledistanceSquared(Point point) Gets the squared distance between this point and another.div(double value) Creates a new point by dividing the provided value to this point coordinates for all XYZ.div(double x, double y, double z) Creates a new point by dividing the provided values to this point coordinates.Creates a new point by dividing another point coordinates to this point coordinates.default doubleCalculates the dot product of this point with another.default booleanReturns if a point is normalizeddefault booleanisZero()default doublelength()Gets the magnitude of the point, defined as sqrt(x^2+y^2+z^2).default doubleGets the magnitude of the point squared.Calculates a linear interpolation between this point with another point (x/y/z).max(double value) Gets a point representing the maximum values between this point and the provided value for all coordinates.max(double x, double y, double z) Gets a point representing the maximum values between this point and the provided coordinates (x/y/z).Gets a point representing the maximum values between this point and the provided one (x/y/z).min(double value) Gets a point representing the minimum values between this point and the provided value for all coordinates.min(double x, double y, double z) Gets a point representing the minimum values between this point and the provided coordinates (x/y/z).Gets a point representing the minimum values between this point and the provided one (x/y/z).mul(double value) Creates a new point by multiplying the provided value to this point coordinates for all XYZ.mul(double x, double y, double z) Creates a new point by multiplying the provided values to this point coordinates.Creates a new point by multiplying another point coordinates to this point coordinates.neg()Represents this point with all coordinates negated.Converts this point to a unit point (a point with length of 1).default intregionX()The region x coordinate ofblockX(), determined byREGION_SIZEdefault intregionZ()The region z coordinate ofblockZ(), determined byREGION_SIZEdefault PointCreates a new point relative to this point based on the provided block face.default booleansameBlock(int blockX, int blockY, int blockZ) default booleanChecks if two points are in the same block.default booleanChecks if two points are in the same chunk.default booleansamePoint(double x, double y, double z) Checks if two points have similar (x/y/z).default booleansamePoint(double x, double y, double z, double epsilon) Checks it two points have similar (x/y/z) coordinates within a given epsilon.default booleanChecks if two points have similar (x/y/z).default booleanChecks it two points have similar (x/y/z) coordinates within a given epsilon.default intsection()Deprecated.default intsectionX()The section x coordinate ofblockX(), determined bySECTION_SIZEdefault intsectionY()The section y coordinate ofblockY(), determined bySECTION_SIZEdefault intsectionZ()The section z coordinate ofblockZ(), determined bySECTION_SIZEdefault booleansimilarPoint(double x, double y, double z) Checks it two points have similar (x/y/z) coordinates withinEPSILON.default booleansimilarPoint(Point point) Checks it two points have similar (x/y/z) coordinates withinEPSILON.sub(double value) Creates a new point by subtracting the provided value to this point coordinates for all XYZ.sub(double x, double y, double z) Creates a new point by subtracting the provided values to this point coordinates.Creates a new point by subtracting another point coordinates to this point coordinates.withX(double x) Creates a point with the specified X coordinate.withX(DoubleUnaryOperator operator) Creates a point with a modified X coordinate based on its value.withY(double y) Creates a point with the specified Y coordinate.withY(DoubleUnaryOperator operator) Creates a point with a modified Y coordinate based on its value.withZ(double z) Creates a point with the specified Z coordinate.withZ(DoubleUnaryOperator operator) Creates a point with a modified Z coordinate based on its value.doublex()Gets the X coordinate.doubley()Gets the Y coordinate.doublez()Gets the Z coordinate.
-
Field Details
-
EPSILON
static final double EPSILONThe smallest difference between two double values to consider them equal if applicable.- See Also:
-
SECTION_SIZE
static final int SECTION_SIZERepresents the size of a section (16 blocks).Also known as chunk in X and Z axis.
- See Also:
-
REGION_SIZE
static final int REGION_SIZERepresents the size of a region (32 sections) or (512 blocks). Used in Anvil (.mca) region files.Regions do not normally have a Y component.
- See Also:
-
-
Method Details
-
x
-
y
-
z
-
blockX
-
blockY
-
blockZ
-
sectionX
The section x coordinate ofblockX(), determined bySECTION_SIZE- Returns:
- the section x coordinate
-
sectionY
The section y coordinate ofblockY(), determined bySECTION_SIZE- Returns:
- the section y coordinate
-
sectionZ
The section z coordinate ofblockZ(), determined bySECTION_SIZE- Returns:
- the section z coordinate
-
chunkX
The chunk X coordinate ofblockX(), also known as the section XsectionX()- Returns:
- the chunk X coordinate
-
chunkZ
The chunk Z coordinate ofblockZ(), also known as the section ZsectionZ()- Returns:
- the chunk Z coordinate
-
regionX
The region x coordinate ofblockX(), determined byREGION_SIZE- Returns:
- the region x coordinate
-
regionZ
The region z coordinate ofblockZ(), determined byREGION_SIZE- Returns:
- the region z coordinate
-
section
Deprecated.usesectionY()instead. -
withX
Creates a point with a modified X coordinate based on its value.- Parameters:
operator- the operator providing the current X coordinate and returning the new- Returns:
- a new point
-
withX
-
withY
Creates a point with a modified Y coordinate based on its value.- Parameters:
operator- the operator providing the current Y coordinate and returning the new- Returns:
- a new point
-
withY
-
withZ
Creates a point with a modified Z coordinate based on its value.- Parameters:
operator- the operator providing the current Z coordinate and returning the new- Returns:
- a new point
-
withZ
-
add
-
add
-
add
-
sub
-
sub
-
sub
-
mul
-
mul
-
mul
-
div
Creates a new point by dividing the provided values to this point coordinates.Warning: division by zero will not error.
- Parameters:
x- the x to dividey- the y to dividez- the z to divide- Returns:
- the new point
-
div
-
div
-
relative
-
distanceSquared
-
distanceSquared
-
distance
-
distance
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 point'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.- Parameters:
point- the other point- Returns:
- the distance
-
samePoint
-
samePoint
-
samePoint
Checks it two points have similar (x/y/z) coordinates within a given epsilon.- Parameters:
x- the x coordinate to comparey- the y coordinate to comparez- the z coordinate to compareepsilon- the maximum difference allowed between the two points (exclusive)- Returns:
- true if the two positions are similar within the epsilon
- Throws:
IllegalArgumentException- if epsilon is less than or equal to 0
-
samePoint
Checks it two points have similar (x/y/z) coordinates within a given epsilon.- Parameters:
point- the point to compareepsilon- the maximum difference allowed between the two points (exclusive)- Returns:
- true if the two positions are similar within the epsilon
- Throws:
IllegalArgumentException- if epsilon is less than or equal to 0
-
similarPoint
-
similarPoint
-
isZero
-
sameChunk
-
sameBlock
- Parameters:
blockX- the block xblockY- the block yblockZ- the block z- Returns:
- true if 'this' is in the same block as the provided coordinates
-
sameBlock
-
lengthSquared
-
length
Gets the magnitude of the point, defined as sqrt(x^2+y^2+z^2). 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 point's magnitude. NaN will be returned if the inner result of the sqrt() function overflows, which will be caused if the length is too long.- Returns:
- the magnitude
-
isNormalized
-
angle
-
dot
-
neg
-
abs
-
min
-
min
-
min
-
max
-
max
-
max
-
normalize
-
cross
-
lerp
-
asPos
-
asVec
-
asBlockVec
-
sectionY()instead.