Skip to content

Commit

Permalink
RVec3: add 4 public static methods
Browse files Browse the repository at this point in the history
  • Loading branch information
stephengold committed Sep 26, 2024
1 parent 3e87366 commit e29b701
Showing 1 changed file with 59 additions and 0 deletions.
59 changes: 59 additions & 0 deletions src/main/java/com/github/stephengold/joltjni/RVec3.java
Original file line number Diff line number Diff line change
Expand Up @@ -118,6 +118,20 @@ public RVec3 addLocal(double addX, double addY, double addZ) {
return this;
}

/**
* Divide the left argument by the right argument. (native operator: binary
* {@code /=})
*
* @param left the accumulating vector (not null, modified)
* @param right the denominator (not null, unaffected)
*/
public static void divideEquals(RVec3 left, double right) {
double xx = left.xx() / right;
double yy = left.yy() / right;
double zz = left.zz() / right;
left.set(xx, yy, zz);
}

/**
* Test whether all 3 components are finite.
*
Expand All @@ -131,6 +145,34 @@ public boolean isFinite() {
}
}

/**
* Add the right argument to the left argument. (native operator: binary
* {@code +=})
*
* @param left the accumulating vector (not null, modified)
* @param right the vector to add (not null, unaffected)
*/
public static void plusEquals(RVec3 left, RVec3Arg right) {
double xx = left.xx() + right.xx();
double yy = left.yy() + right.yy();
double zz = left.zz() + right.zz();
left.set(xx, yy, zz);
}

/**
* Add the right argument to the left argument. (native operator: binary
* {@code +=})
*
* @param left the accumulating vector (not null, modified)
* @param right the vector to add (not null, unaffected)
*/
public static void plusEquals(RVec3 left, Vec3Arg right) {
double xx = left.xx() + right.getX();
double yy = left.yy() + right.getY();
double zz = left.zz() + right.getZ();
left.set(xx, yy, zz);
}

/**
* Set all 3 components to specified values.
*
Expand All @@ -144,6 +186,23 @@ public void set(double x, double y, double z) {
this.zz = z;
}

/**
* Return the component-wise difference of the specified vectors. (native
* operator: binary {@code -})
*
* @param left the base vector (not null, unaffected)
* @param right the offset to subtract (not null, unaffected)
* @return a new vector
*/
public static RVec3 subtract(RVec3Arg left, RVec3Arg right) {
double xx = left.xx() - right.xx();
double yy = left.yy() - right.yy();
double zz = left.zz() - right.zz();
RVec3 result = new RVec3(xx, yy, zz);

return result;
}

/**
* Return the component-wise difference of the specified vectors. (native
* operator: binary {@code -})
Expand Down

0 comments on commit e29b701

Please sign in to comment.