/* We might be close to the north pole. This would be bad,
             * numerically. So perform a 180 degree rotation around the
             * x-axis, project that point, and swap the entries of the
             * result.
             */
public void projectTo(final ComplexProjective1 cp)
        throws IllegalArgumentException {
        /* Check if the point lies on the sphere. */
        if (Math.abs(normSquared() - 1.0) > EPSILON) {
            throw new IllegalArgumentException("Norm must be 1.0. " +
                                               "Norm is " + norm() + ". ");
        }
        /* Check if the point lies above or below the xy-plane. */
        if (z > 0.0) {
            /* We might be close to the north pole. This would be bad,
             * numerically. So perform a 180 degree rotation around the
             * x-axis, project that point, and swap the entries of the
             * result.
             */
            /* Dummy variables */
            final double dummyRe;
            final double dummyIm;
            /* Rotate by 180 degree around the x-axis. */
            y = -y;
            z = -z;
            /* Project that point. Now, z < -EPSILON. */
            belowXYProjectTo(cp);
            /* Rotate back. */
            y = -y;
            z = -z;
            /* Swap the entries of the result.
             *
             * TODO: Maybe Complex2 should have a final method that swaps the
             * entries. This might speed up dereferencing the fields of cp,
             * because dereferencing fiels of other objects might be slower
             * than dereferencing fields of the same object. But actually, I
             * don't know if that is true or if it matters. */
            dummyRe = cp.aRe;
            dummyIm = cp.aIm;
            cp.aRe = cp.bRe;
            cp.aIm = cp.bIm;
            cp.bRe = dummyRe;
            cp.bIm = dummyIm;
        } else {
            /* Point lies below xy-plane so we use */
            belowXYProjectTo(cp);
        }
    }
/* Check if the point lies above or below the xy-plane. */
if (z > 0.0) {
/* We might be close to the north pole. This would be bad,
* numerically. So perform a 180 degree rotation around the
* x-axis, project that point, and swap the entries of the
* result.
*/
/* Dummy variables */
final double dummyRe;
public void projectTo(final ComplexProjective1 cp)
throws IllegalArgumentException {
/* Check if the point lies on the sphere. */
if (Math.abs(normSquared() - 1.0) > EPSILON) {
throw new IllegalArgumentException("Norm must be 1.0. " +
"Norm is " + norm() + ". ");
}
/* Check if the point lies above or below the xy-plane. */
if (z > 0.0) {
/* We might be close to the north pole. This would be bad,
* numerically. So perform a 180 degree rotation around the
* x-axis, project that point, and swap the entries of the
* result.
*/
/* Dummy variables */
final double dummyRe;
final double dummyIm;
/* Rotate by 180 degree around the x-axis. */
y = -y;
z = -z;
/* Project that point. Now, z < -EPSILON. */
belowXYProjectTo(cp);
/* Rotate back. */
y = -y;
public void projectTo(final ComplexProjective1 cp)
throws IllegalArgumentException {
/* Check if the point lies on the sphere. */
if (Math.abs(normSquared() - 1.0) > EPSILON) {
throw new IllegalArgumentException("Norm must be 1.0. " +
"Norm is " + norm() + ". ");
}
/* Check if the point lies above or below the xy-plane. */
if (z > 0.0) {
/* We might be close to the north pole. This would be bad,
* numerically. So perform a 180 degree rotation around the
* x-axis, project that point, and swap the entries of the
* result.
*/
/* Dummy variables */
final double dummyRe;
final double dummyIm;
/* Rotate by 180 degree around the x-axis. */
y = -y;
z = -z;
/* Project that point. Now, z < -EPSILON. */
belowXYProjectTo(cp);
/* Rotate back. */
y = -y;
z = -z;
/* Swap the entries of the result.
*
* TODO: Maybe Complex2 should have a final method that swaps the
* entries. This might speed up dereferencing the fields of cp,
* because dereferencing fiels of other objects might be slower
* than dereferencing fields of the same object. But actually, I
* don't know if that is true or if it matters. */
dummyRe = cp.aRe;
dummyIm = cp.aIm;