kapa76 / jmonkeyengine

Automatically exported from code.google.com/p/jmonkeyengine
0 stars 0 forks source link

Quaternion class mult(Quaternion q, Quaternion res) is not safe for res == this, while the javadoc says it is #559

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
From the function definition we can see that, while the documentation says      
"It IS safe for this and res to be the same object" this is NOT the case!

/**
     * <code>mult</code> multiplies this quaternion by a parameter quaternion.
     * The result is returned as a new quaternion. It should be noted that
     * quaternion multiplication is not commutative so q * p != p * q.
     *
     * It IS safe for q and res to be the same object.
     * It IS safe for this and res to be the same object.
     *
     * @param q
     *            the quaternion to multiply this quaternion by.
     * @param res
     *            the quaternion to store the result in.
     * @return the new quaternion.
     */
    public Quaternion mult(Quaternion q, Quaternion res) {
        if (res == null) {
            res = new Quaternion();
        }
        float qw = q.w, qx = q.x, qy = q.y, qz = q.z;
        res.x = x * qw + y * qz - z * qy + w * qx;
        res.y = -x * qz + y * qw + z * qx + w * qy;
        res.z = x * qy - y * qx + z * qw + w * qz;
        res.w = -x * qx - y * qy - z * qz + w * qw;
        return res;
    }

Original issue reported on code.google.com by m...@jespersmith.nl on 14 Dec 2012 at 6:25

GoogleCodeExporter commented 9 years ago
Javadoc has been fixed

Original comment by remy.bou...@gmail.com on 18 Dec 2012 at 4:38