add vector 3 capability

This commit is contained in:
Edouard DUPIN 2022-02-19 15:02:29 +01:00
parent 84f92a1841
commit 3c2cf9ca2b

View File

@ -151,20 +151,33 @@ public record Vector3i(
/** /**
* Return the distance between the ends of this and another vector * Return the distance between the ends of this and another vector
* This is symantically treating the vector like a point * This is semantically treating the vector like a point
* @param obj The other vector to compare distance * @param obj The other vector to compare distance
* @return the distance of the 2 points * @return the distance of the 2 points
*/ */
@CheckReturnValue @CheckReturnValue
public int distance(final Vector3i obj) { public float distance(final Vector3i obj) {
return (int) Math.sqrt(distance2(obj)); return FMath.sqrt(distance2(obj));
}
/**
* Return the distance between the ends of this and another vector
* This is semantically treating the vector like a point
* @param xxx X position.
* @param yyy Y position.
* @param zzz Z position.
* @return the distance of the 2 points
*/
@CheckReturnValue
public float distance(final int xxx, final int yyy, final int zzz) {
return FMath.sqrt(distance2(xxx, yyy, zzz));
} }
/** /**
* Return the distance squared between the ends of this and another vector * Return the distance squared between the ends of this and another vector
* This is symantically treating the vector like a point * This is semantically treating the vector like a point
* @param obj The other vector to compare distance * @param obj The other vector to compare distance
* @return the square distance of the 2 points * @return The square distance of the 2 points.
*/ */
@CheckReturnValue @CheckReturnValue
public int distance2(final Vector3i obj) { public int distance2(final Vector3i obj) {
@ -174,6 +187,22 @@ public record Vector3i(
return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ; return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
} }
/**
* Return the distance squared between the ends of this and another vector
* This is semantically treating the vector like a point
* @param xxx X position.
* @param yyy Y position.
* @param zzz Z position.
* @return The square distance of the 2 points.
*/
@CheckReturnValue
public int distance2(final int xxx, final int yyy, final int zzz) {
final int deltaX = xxx - this.x;
final int deltaY = yyy - this.y;
final int deltaZ = zzz - this.z;
return deltaX * deltaX + deltaY * deltaY + deltaZ * deltaZ;
}
/** /**
* Return the dot product * Return the dot product
* @param obj The other vector in the dot product * @param obj The other vector in the dot product