Skip to content

Commit

Permalink
Add Quaternion.mul(scalar) (#316)
Browse files Browse the repository at this point in the history
  • Loading branch information
httpdigest committed Aug 10, 2022
1 parent 8cc09c2 commit 313e839
Show file tree
Hide file tree
Showing 4 changed files with 68 additions and 0 deletions.
21 changes: 21 additions & 0 deletions src/org/joml/Quaterniond.java
Original file line number Diff line number Diff line change
Expand Up @@ -796,6 +796,27 @@ public Quaterniond mul(double qx, double qy, double qz, double qw, Quaterniond d
Math.fma(w, qw, Math.fma(-x, qx, Math.fma(-y, qy, -z * qz))));
}

/**
* Multiply this quaternion by the given scalar.
* <p>
* This method multiplies all of the four components by the specified scalar.
*
* @param f
* the factor to multiply all components by
* @return this
*/
public Quaterniond mul(double f) {
return mul(f, this);
}

public Quaterniond mul(double f, Quaterniond dest) {
dest.x = x * f;
dest.y = y * f;
dest.z = z * f;
dest.w = w * f;
return dest;
}

/**
* Pre-multiply this quaternion by <code>q</code>.
* <p>
Expand Down
13 changes: 13 additions & 0 deletions src/org/joml/Quaterniondc.java
Original file line number Diff line number Diff line change
Expand Up @@ -232,6 +232,19 @@ public interface Quaterniondc {
*/
Quaterniond mul(double qx, double qy, double qz, double qw, Quaterniond dest);

/**
* Multiply this quaternion by the given scalar and store the result in <code>dest</code>.
* <p>
* This method multiplies all of the four components by the specified scalar.
*
* @param f
* the factor to multiply all components by
* @param dest
* will hold the result
* @return dest
*/
Quaterniond mul(double f, Quaterniond dest);

/**
* Pre-multiply this quaternion by <code>q</code> and store the result in <code>dest</code>.
* <p>
Expand Down
21 changes: 21 additions & 0 deletions src/org/joml/Quaternionf.java
Original file line number Diff line number Diff line change
Expand Up @@ -996,6 +996,27 @@ public Quaternionf mul(float qx, float qy, float qz, float qw, Quaternionf dest)
Math.fma(w, qw, Math.fma(-x, qx, Math.fma(-y, qy, -z * qz))));
}

/**
* Multiply this quaternion by the given scalar.
* <p>
* This method multiplies all of the four components by the specified scalar.
*
* @param f
* the factor to multiply all components by
* @return this
*/
public Quaternionf mul(float f) {
return mul(f, this);
}

public Quaternionf mul(float f, Quaternionf dest) {
dest.x = x * f;
dest.y = y * f;
dest.z = z * f;
dest.w = w * f;
return dest;
}

/**
* Pre-multiply this quaternion by <code>q</code>.
* <p>
Expand Down
13 changes: 13 additions & 0 deletions src/org/joml/Quaternionfc.java
Original file line number Diff line number Diff line change
Expand Up @@ -320,6 +320,19 @@ public interface Quaternionfc {
*/
Quaternionf mul(float qx, float qy, float qz, float qw, Quaternionf dest);

/**
* Multiply this quaternion by the given scalar and store the result in <code>dest</code>.
* <p>
* This method multiplies all of the four components by the specified scalar.
*
* @param f
* the factor to multiply all components by
* @param dest
* will hold the result
* @return dest
*/
Quaternionf mul(float f, Quaternionf dest);

/**
* Pre-multiply this quaternion by <code>q</code> and store the result in <code>dest</code>.
* <p>
Expand Down

0 comments on commit 313e839

Please sign in to comment.