From e29b701e5d02303b9861de6b92a757565108f2ea Mon Sep 17 00:00:00 2001 From: stephengold Date: Thu, 26 Sep 2024 12:46:08 -0700 Subject: [PATCH] RVec3: add 4 public static methods --- .../com/github/stephengold/joltjni/RVec3.java | 59 +++++++++++++++++++ 1 file changed, 59 insertions(+) diff --git a/src/main/java/com/github/stephengold/joltjni/RVec3.java b/src/main/java/com/github/stephengold/joltjni/RVec3.java index 60766b7f..27f9e067 100644 --- a/src/main/java/com/github/stephengold/joltjni/RVec3.java +++ b/src/main/java/com/github/stephengold/joltjni/RVec3.java @@ -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. * @@ -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. * @@ -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 -})