Skip to content

Commit

Permalink
RVec3Arg: add 3 methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Dec 6, 2024
1 parent 720e065 commit fe6604f
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/RVec3.java
Original file line number Diff line number Diff line change
Expand Up @@ -272,6 +272,47 @@ public Object getZ() {
return result;
}

/**
* Test whether the squared length is within 1e-12 (single-precision) or
* 1e-24 (double-precision) of zero. The vector is unaffected.
*
* @return {@code true} if nearly zero, otherwise {@code false}
*/
@Override
public boolean isNearZero() {
double tolerance = Jolt.isDoublePrecision() ? 1e-24 : 1e-12;
boolean result = isNearZero(tolerance);
return result;
}

/**
* Test whether the squared length is within the specified tolerance of
* zero. The vector is unaffected.
*
* @param tolerance the desired tolerance (≥0)
* @return {@code true} if nearly zero, otherwise {@code false}
*/
@Override
public boolean isNearZero(double tolerance) {
double lengthSq = lengthSq();
if (lengthSq <= tolerance) {
return true;
} else {
return false;
}
}

/**
* Return the squared length. The vector is unaffected.
*
* @return the squared length
*/
@Override
public double lengthSq() {
double result = xx * xx + yy * yy + zz * zz;
return result;
}

/**
* Copy the components to an array. The vector is unaffected.
*
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,6 +67,30 @@ public interface RVec3Arg {
*/
Object getZ();

/**
* Test whether the squared length is within 1e-12 (single-precision) or
* 1e-24 (double-precision) of zero. The vector is unaffected.
*
* @return {@code true} if nearly zero, otherwise {@code false}
*/
boolean isNearZero();

/**
* Test whether the squared length is within the specified tolerance of
* zero. The vector is unaffected.
*
* @param tolerance the desired tolerance (&gel0)
* @return {@code true} if nearly zero, otherwise {@code false}
*/
boolean isNearZero(double tolerance);

/**
* Return the squared length. The vector is unaffected.
*
* @return the squared length
*/
double lengthSq();

/**
* Copy the components to an array. The vector is unaffected.
*
Expand Down

0 comments on commit fe6604f

Please sign in to comment.