{"input": "", "context": "/*\n * This file is part of Gaia Sky, which is released under the Mozilla Public License 2.0.\n * See the file LICENSE.md in the project root for full license details.\n */\n\npackage gaiasky.util.math;\n\n/*******************************************************************************\n * Copyright 2011 See AUTHORS file.\n *\n * Licensed under the Apache License, Version 2.0 (the \"License\"); you may not\n * use this file except in compliance with the License. You may obtain a copy of\n * the License at\n *\n * https://www.apache.org/licenses/LICENSE-2.0\n *\n * Unless required by applicable law or agreed to in writing, software\n * distributed under the License is distributed on an \"AS IS\" BASIS, WITHOUT\n * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\n * License for the specific language governing permissions and limitations under\n * the License.\n ******************************************************************************/\n\nimport com.badlogic.gdx.math.Matrix3;\nimport com.badlogic.gdx.math.Matrix4;\nimport com.badlogic.gdx.math.Vector3;\n\nimport java.io.Serializable;\n\n/**\n * Encapsulates a column\n * major 4 by 4 matrix. Like the {@link Vector3d} class it allows the\n * chaining of methods by returning a reference to itself. For example:\n *\n *
\n * Matrix4d mat = new Matrix4d().trn(position).mul(camera.combined);\n *\n *\n * @author badlogicgames@gmail.com\n */\npublic class Matrix4d implements Serializable {\n private static final long serialVersionUID = -2717655254359579617L;\n /**\n * XX: Typically the unrotated X component for scaling, also the cosine of\n * the angle when rotated on the Y and/or Z axis. On Vector3d multiplication\n * this value is multiplied with the source X component and added to the\n * target X component.\n */\n public static final int M00 = 0;\n /**\n * XY: Typically the negative sine of the angle when rotated on the Z axis.\n * On Vector3d multiplication this value is multiplied with the source Y\n * component and added to the target X component.\n */\n public static final int M01 = 4;\n /**\n * XZ: Typically the sine of the angle when rotated on the Y axis. On\n * Vector3d multiplication this value is multiplied with the source Z\n * component and added to the target X component.\n */\n public static final int M02 = 8;\n /**\n * XW: Typically the translation of the X component. On Vector3d\n * multiplication this value is added to the target X component.\n */\n public static final int M03 = 12;\n /**\n * YX: Typically the sine of the angle when rotated on the Z axis. On\n * Vector3d multiplication this value is multiplied with the source X\n * component and added to the target Y component.\n */\n public static final int M10 = 1;\n /**\n * YY: Typically the unrotated Y component for scaling, also the cosine of\n * the angle when rotated on the X and/or Z axis. On Vector3d multiplication\n * this value is multiplied with the source Y component and added to the\n * target Y component.\n */\n public static final int M11 = 5;\n /**\n * YZ: Typically the negative sine of the angle when rotated on the X axis.\n * On Vector3d multiplication this value is multiplied with the source Z\n * component and added to the target Y component.\n */\n public static final int M12 = 9;\n /**\n * YW: Typically the translation of the Y component. On Vector3d\n * multiplication this value is added to the target Y component.\n */\n public static final int M13 = 13;\n /**\n * ZX: Typically the negative sine of the angle when rotated on the Y axis.\n * On Vector3d multiplication this value is multiplied with the source X\n * component and added to the target Z component.\n */\n public static final int M20 = 2;\n /**\n * ZY: Typical the sine of the angle when rotated on the X axis. On Vector3d\n * multiplication this value is multiplied with the source Y component and\n * added to the target Z component.\n */\n public static final int M21 = 6;\n /**\n * ZZ: Typically the unrotated Z component for scaling, also the cosine of\n * the angle when rotated on the X and/or Y axis. On Vector3d multiplication\n * this value is multiplied with the source Z component and added to the\n * target Z component.\n */\n public static final int M22 = 10;\n /**\n * ZW: Typically the translation of the Z component. On Vector3d\n * multiplication this value is added to the target Z component.\n */\n public static final int M23 = 14;\n /**\n * WX: Typically the value zero. On Vector3d multiplication this value is\n * ignored.\n */\n public static final int M30 = 3;\n /**\n * WY: Typically the value zero. On Vector3d multiplication this value is\n * ignored.\n */\n public static final int M31 = 7;\n /**\n * WZ: Typically the value zero. On Vector3d multiplication this value is\n * ignored.\n */\n public static final int M32 = 11;\n /**\n * WW: Typically the value one. On Vector3d multiplication this value is\n * ignored.\n */\n public static final int M33 = 15;\n\n public final static double[] stmp = new double[16];\n public final double[] tmp = new double[16];\n public final double[] val = new double[16];\n\n /** Constructs an identity matrix */\n public Matrix4d() {\n val[M00] = 1f;\n val[M11] = 1f;\n val[M22] = 1f;\n val[M33] = 1f;\n }\n\n /**\n * Constructs a matrix from the given matrix.\n *\n * @param matrix The matrix to copy. (This matrix is not modified)\n */\n public Matrix4d(Matrix4d matrix) {\n this.set(matrix);\n }\n\n /**\n * Constructs a matrix from the given double array. The array must have at\n * least 16 elements; the first 16 will be copied.\n *\n * @param values The double array to copy. Remember that this matrix is in\n * column\n * major order. (The double array is not modified.)\n */\n public Matrix4d(double[] values) {\n this.set(values);\n }\n\n public Matrix4d(float[] values) {\n this.set(values);\n }\n\n /**\n * Constructs a rotation matrix from the given {@link Quaterniond}.\n *\n * @param quaternion The quaternion to be copied. (The quaternion is not modified)\n */\n public Matrix4d(Quaterniond quaternion) {\n this.set(quaternion);\n }\n\n /**\n * Construct a matrix from the given translation, rotation and scale.\n *\n * @param position The translation\n * @param rotation The rotation, must be normalized\n * @param scale The scale\n */\n public Matrix4d(Vector3d position, Quaterniond rotation, Vector3d scale) {\n set(position, rotation, scale);\n }\n\n /**\n * Sets the matrix to the given matrix.\n *\n * @param matrix The matrix that is to be copied. (The given matrix is not\n * modified)\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d set(Matrix4d matrix) {\n return this.set(matrix.val);\n }\n\n public Matrix4d set(Matrix4 matrix) {\n return this.set(matrix.val);\n }\n\n /**\n * Sets the matrix to the given matrix as a double array. The double array\n * must have at least 16 elements; the first 16 will be copied.\n *\n * @param values The matrix, in double form, that is to be copied. Remember\n * that this matrix is in column\n * major order.\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d set(double[] values) {\n System.arraycopy(values, 0, val, 0, val.length);\n return this;\n }\n\n public Matrix4d set(float[] values) {\n for (int i = 0; i < val.length; i++) {\n val[i] = values[i];\n }\n return this;\n }\n\n /**\n * Sets the matrix to a rotation matrix representing the quaternion.\n *\n * @param quaternion The quaternion that is to be used to set this matrix.\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d set(Quaterniond quaternion) {\n return set(quaternion.x, quaternion.y, quaternion.z, quaternion.w);\n }\n\n /**\n * Sets the matrix to a rotation matrix representing the quaternion.\n *\n * @param quaternionX The X component of the quaternion that is to be used to set\n * this matrix.\n * @param quaternionY The Y component of the quaternion that is to be used to set\n * this matrix.\n * @param quaternionZ The Z component of the quaternion that is to be used to set\n * this matrix.\n * @param quaternionW The W component of the quaternion that is to be used to set\n * this matrix.\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d set(double quaternionX, double quaternionY, double quaternionZ, double quaternionW) {\n return set(0f, 0f, 0f, quaternionX, quaternionY, quaternionZ, quaternionW);\n }\n\n /**\n * Set this matrix to the specified translation and rotation.\n *\n * @param position The translation\n * @param orientation The rotation, must be normalized\n *\n * @return This matrix for chaining\n */\n public Matrix4d set(Vector3d position, Quaterniond orientation) {\n return set(position.x, position.y, position.z, orientation.x, orientation.y, orientation.z, orientation.w);\n }\n\n /**\n * Sets the matrix to a rotation matrix representing the translation and\n * quaternion.\n *\n * @param translationX The X component of the translation that is to be used to set\n * this matrix.\n * @param translationY The Y component of the translation that is to be used to set\n * this matrix.\n * @param translationZ The Z component of the translation that is to be used to set\n * this matrix.\n * @param quaternionX The X component of the quaternion that is to be used to set\n * this matrix.\n * @param quaternionY The Y component of the quaternion that is to be used to set\n * this matrix.\n * @param quaternionZ The Z component of the quaternion that is to be used to set\n * this matrix.\n * @param quaternionW The W component of the quaternion that is to be used to set\n * this matrix.\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d set(double translationX, double translationY, double translationZ, double quaternionX, double quaternionY, double quaternionZ, double quaternionW) {\n final double xs = quaternionX * 2f, ys = quaternionY * 2f, zs = quaternionZ * 2f;\n final double wx = quaternionW * xs, wy = quaternionW * ys, wz = quaternionW * zs;\n final double xx = quaternionX * xs, xy = quaternionX * ys, xz = quaternionX * zs;\n final double yy = quaternionY * ys, yz = quaternionY * zs, zz = quaternionZ * zs;\n\n val[M00] = (1.0f - (yy + zz));\n val[M01] = (xy - wz);\n val[M02] = (xz + wy);\n val[M03] = translationX;\n\n val[M10] = (xy + wz);\n val[M11] = (1.0f - (xx + zz));\n val[M12] = (yz - wx);\n val[M13] = translationY;\n\n val[M20] = (xz - wy);\n val[M21] = (yz + wx);\n val[M22] = (1.0f - (xx + yy));\n val[M23] = translationZ;\n\n val[M30] = 0.f;\n val[M31] = 0.f;\n val[M32] = 0.f;\n val[M33] = 1.0f;\n return this;\n }\n\n /**\n * Set this matrix to the specified translation, rotation and scale.\n *\n * @param position The translation\n * @param orientation The rotation, must be normalized\n * @param scale The scale\n *\n * @return This matrix for chaining\n */\n public Matrix4d set(Vector3d position, Quaterniond orientation, Vector3d scale) {\n return set(position.x, position.y, position.z, orientation.x, orientation.y, orientation.z, orientation.w, scale.x, scale.y, scale.z);\n }\n\n /**\n * Sets the matrix to a rotation matrix representing the translation and\n * quaternion.\n *\n * @param translationX The X component of the translation that is to be used to set\n * this matrix.\n * @param translationY The Y component of the translation that is to be used to set\n * this matrix.\n * @param translationZ The Z component of the translation that is to be used to set\n * this matrix.\n * @param quaternionX The X component of the quaternion that is to be used to set\n * this matrix.\n * @param quaternionY The Y component of the quaternion that is to be used to set\n * this matrix.\n * @param quaternionZ The Z component of the quaternion that is to be used to set\n * this matrix.\n * @param quaternionW The W component of the quaternion that is to be used to set\n * this matrix.\n * @param scaleX The X component of the scaling that is to be used to set this\n * matrix.\n * @param scaleY The Y component of the scaling that is to be used to set this\n * matrix.\n * @param scaleZ The Z component of the scaling that is to be used to set this\n * matrix.\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d set(double translationX, double translationY, double translationZ, double quaternionX, double quaternionY, double quaternionZ, double quaternionW, double scaleX, double scaleY, double scaleZ) {\n final double xs = quaternionX * 2f, ys = quaternionY * 2f, zs = quaternionZ * 2f;\n final double wx = quaternionW * xs, wy = quaternionW * ys, wz = quaternionW * zs;\n final double xx = quaternionX * xs, xy = quaternionX * ys, xz = quaternionX * zs;\n final double yy = quaternionY * ys, yz = quaternionY * zs, zz = quaternionZ * zs;\n\n val[M00] = scaleX * (1.0f - (yy + zz));\n val[M01] = scaleY * (xy - wz);\n val[M02] = scaleZ * (xz + wy);\n val[M03] = translationX;\n\n val[M10] = scaleX * (xy + wz);\n val[M11] = scaleY * (1.0f - (xx + zz));\n val[M12] = scaleZ * (yz - wx);\n val[M13] = translationY;\n\n val[M20] = scaleX * (xz - wy);\n val[M21] = scaleY * (yz + wx);\n val[M22] = scaleZ * (1.0f - (xx + yy));\n val[M23] = translationZ;\n\n val[M30] = 0.f;\n val[M31] = 0.f;\n val[M32] = 0.f;\n val[M33] = 1.0f;\n return this;\n }\n\n /**\n * Sets the four columns of the matrix which correspond to the x-, y- and\n * z-axis of the vector space this matrix creates as well as the 4th column\n * representing the translation of any point that is multiplied by this\n * matrix.\n *\n * @param xAxis The x-axis.\n * @param yAxis The y-axis.\n * @param zAxis The z-axis.\n * @param pos The translation vector.\n */\n public Matrix4d set(Vector3d xAxis, Vector3d yAxis, Vector3d zAxis, Vector3d pos) {\n val[M00] = xAxis.x;\n val[M01] = xAxis.y;\n val[M02] = xAxis.z;\n val[M10] = yAxis.x;\n val[M11] = yAxis.y;\n val[M12] = yAxis.z;\n val[M20] = -zAxis.x;\n val[M21] = -zAxis.y;\n val[M22] = -zAxis.z;\n val[M03] = pos.x;\n val[M13] = pos.y;\n val[M23] = pos.z;\n val[M30] = 0;\n val[M31] = 0;\n val[M32] = 0;\n val[M33] = 1;\n return this;\n }\n\n /** @return a copy of this matrix */\n public Matrix4d cpy() {\n return new Matrix4d(this);\n }\n\n /**\n * Adds a translational component to the matrix in the 4th column. The other\n * columns are untouched.\n *\n * @param vector The translation vector to add to the current matrix. (This\n * vector is not modified)\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d trn(Vector3d vector) {\n val[M03] += vector.x;\n val[M13] += vector.y;\n val[M23] += vector.z;\n return this;\n }\n\n /**\n * Adds a translational component to the matrix in the 4th column. The other\n * columns are untouched.\n *\n * @param x The x-component of the translation vector.\n * @param y The y-component of the translation vector.\n * @param z The z-component of the translation vector.\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d trn(double x, double y, double z) {\n val[M03] += x;\n val[M13] += y;\n val[M23] += z;\n return this;\n }\n\n /** @return the backing double array */\n public double[] getValues() {\n return val;\n }\n\n public float[] getValuesFloat() {\n float[] res = new float[val.length];\n for (int i = 0; i < val.length; i++)\n res[i] = (float) val[i];\n return res;\n }\n\n /**\n * Postmultiplies this matrix with the given matrix, storing the result in\n * this matrix. For example:\n *\n *
\n * A.mul(B) results in A := AB.\n *\n *\n * @param matrix The other matrix to multiply by.\n *\n * @return This matrix for the purpose of chaining operations together.\n */\n public Matrix4d mul(Matrix4d matrix) {\n matrix4_mul(val, matrix.val);\n return this;\n }\n\n /**\n * Premultiplies this matrix with the given matrix, storing the result in\n * this matrix. For example:\n *\n *
\n * A.mulLeft(B) results in A := BA.\n *\n *\n * @param matrix The other matrix to multiply by.\n *\n * @return This matrix for the purpose of chaining operations together.\n */\n public Matrix4d mulLeft(Matrix4d matrix) {\n tmpMat.set(matrix);\n // mul(tmpMat.val, this.val);\n tmpMat.mul(this);\n return set(tmpMat);\n }\n\n /**\n * Transposes the matrix.\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d tra() {\n tmp[M00] = val[M00];\n tmp[M01] = val[M10];\n tmp[M02] = val[M20];\n tmp[M03] = val[M30];\n tmp[M10] = val[M01];\n tmp[M11] = val[M11];\n tmp[M12] = val[M21];\n tmp[M13] = val[M31];\n tmp[M20] = val[M02];\n tmp[M21] = val[M12];\n tmp[M22] = val[M22];\n tmp[M23] = val[M32];\n tmp[M30] = val[M03];\n tmp[M31] = val[M13];\n tmp[M32] = val[M23];\n tmp[M33] = val[M33];\n return set(tmp);\n }\n\n /**\n * Sets the matrix to an identity matrix.\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d idt() {\n val[M00] = 1;\n val[M01] = 0;\n val[M02] = 0;\n val[M03] = 0;\n val[M10] = 0;\n val[M11] = 1;\n val[M12] = 0;\n val[M13] = 0;\n val[M20] = 0;\n val[M21] = 0;\n val[M22] = 1;\n val[M23] = 0;\n val[M30] = 0;\n val[M31] = 0;\n val[M32] = 0;\n val[M33] = 1;\n return this;\n }\n\n public Matrix4d inv() {\n matrix4_inv(val);\n return this;\n }\n\n /**\n * Computes the inverse of the given matrix. The matrix array is assumed to\n * hold a 4x4 column major matrix as you can get from {@link Matrix4#val}.\n *\n * @param values the matrix values.\n *\n * @return false in case the inverse could not be calculated, true\n * otherwise.\n */\n public static boolean inv(double[] values) {\n return matrix4_inv(values);\n }\n\n /** @return The determinant of this matrix */\n public double det() {\n return val[M30] * val[M21] * val[M12] * val[M03] - val[M20] * val[M31] * val[M12] * val[M03] - val[M30] * val[M11] * val[M22] * val[M03] + val[M10] * val[M31] * val[M22] * val[M03] + val[M20] * val[M11] * val[M32] * val[M03] - val[M10] * val[M21] * val[M32] * val[M03] - val[M30] * val[M21] * val[M02] * val[M13] + val[M20] * val[M31] * val[M02] * val[M13] + val[M30] * val[M01] * val[M22] * val[M13] - val[M00] * val[M31] * val[M22] * val[M13] - val[M20] * val[M01] * val[M32] * val[M13]\n + val[M00] * val[M21] * val[M32] * val[M13] + val[M30] * val[M11] * val[M02] * val[M23] - val[M10] * val[M31] * val[M02] * val[M23] - val[M30] * val[M01] * val[M12] * val[M23] + val[M00] * val[M31] * val[M12] * val[M23] + val[M10] * val[M01] * val[M32] * val[M23] - val[M00] * val[M11] * val[M32] * val[M23] - val[M20] * val[M11] * val[M02] * val[M33] + val[M10] * val[M21] * val[M02] * val[M33] + val[M20] * val[M01] * val[M12] * val[M33] - val[M00] * val[M21] * val[M12] * val[M33]\n - val[M10] * val[M01] * val[M22] * val[M33] + val[M00] * val[M11] * val[M22] * val[M33];\n }\n\n /** @return The determinant of the 3x3 upper left matrix */\n public double det3x3() {\n return val[M00] * val[M11] * val[M22] + val[M01] * val[M12] * val[M20] + val[M02] * val[M10] * val[M21] - val[M00] * val[M12] * val[M21] - val[M01] * val[M10] * val[M22] - val[M02] * val[M11] * val[M20];\n }\n\n /**\n * Sets the matrix to a projection matrix with a near- and far plane, a\n * field of view in degrees and an aspect ratio.\n *\n * @param near The near plane\n * @param far The far plane\n * @param fov The field of view in degrees\n * @param aspectRatio The \"width over height\" aspect ratio\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setToProjection(double near, double far, double fov, double aspectRatio) {\n idt();\n double l_fd = 1.0 / Math.tan((fov * (Math.PI / 180)) / 2.0);\n double l_a1 = (far + near) / (near - far);\n double l_a2 = (2 * far * near) / (near - far);\n val[M00] = l_fd / aspectRatio;\n val[M10] = 0;\n val[M20] = 0;\n val[M30] = 0;\n val[M01] = 0;\n val[M11] = l_fd;\n val[M21] = 0;\n val[M31] = 0;\n val[M02] = 0;\n val[M12] = 0;\n val[M22] = l_a1;\n val[M32] = -1;\n val[M03] = 0;\n val[M13] = 0;\n val[M23] = l_a2;\n val[M33] = 0;\n\n return this;\n }\n\n /**\n * Sets this matrix to an orthographic projection matrix with the origin at\n * (x,y) extending by width and height. The near plane is set to 0, the far\n * plane is set to 1.\n *\n * @param x The x-coordinate of the origin\n * @param y The y-coordinate of the origin\n * @param width The width\n * @param height The height\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setToOrtho2D(double x, double y, double width, double height) {\n setToOrtho(x, x + width, y, y + height, 0, 1);\n return this;\n }\n\n /**\n * Sets this matrix to an orthographic projection matrix with the origin at\n * (x,y) extending by width and height, having a near and far plane.\n *\n * @param x The x-coordinate of the origin\n * @param y The y-coordinate of the origin\n * @param width The width\n * @param height The height\n * @param near The near plane\n * @param far The far plane\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setToOrtho2D(double x, double y, double width, double height, double near, double far) {\n setToOrtho(x, x + width, y, y + height, near, far);\n return this;\n }\n\n /**\n * Sets the matrix to an orthographic projection like glOrtho\n * (http://www.opengl.org/sdk/docs/man/xhtml/glOrtho.xml) following the\n * OpenGL equivalent\n *\n * @param left The left clipping plane\n * @param right The right clipping plane\n * @param bottom The bottom clipping plane\n * @param top The top clipping plane\n * @param near The near clipping plane\n * @param far The far clipping plane\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setToOrtho(double left, double right, double bottom, double top, double near, double far) {\n\n this.idt();\n double x_orth = 2 / (right - left);\n double y_orth = 2 / (top - bottom);\n double z_orth = -2 / (far - near);\n\n double tx = -(right + left) / (right - left);\n double ty = -(top + bottom) / (top - bottom);\n double tz = -(far + near) / (far - near);\n\n val[M00] = x_orth;\n val[M10] = 0;\n val[M20] = 0;\n val[M30] = 0;\n val[M01] = 0;\n val[M11] = y_orth;\n val[M21] = 0;\n val[M31] = 0;\n val[M02] = 0;\n val[M12] = 0;\n val[M22] = z_orth;\n val[M32] = 0;\n val[M03] = tx;\n val[M13] = ty;\n val[M23] = tz;\n val[M33] = 1;\n\n return this;\n }\n\n /**\n * Sets the 4th column to the translation vector.\n *\n * @param vector The translation vector\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setTranslation(Vector3d vector) {\n val[M03] = vector.x;\n val[M13] = vector.y;\n val[M23] = vector.z;\n return this;\n }\n\n /**\n * Sets the 4th column to the translation vector.\n *\n * @param x The X coordinate of the translation vector\n * @param y The Y coordinate of the translation vector\n * @param z The Z coordinate of the translation vector\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setTranslation(double x, double y, double z) {\n val[M03] = x;\n val[M13] = y;\n val[M23] = z;\n return this;\n }\n\n /**\n * Sets this matrix to a translation matrix, overwriting it first by an\n * identity matrix and then setting the 4th column to the translation\n * vector.\n *\n * @param vector The translation vector\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setToTranslation(Vector3d vector) {\n idt();\n val[M03] = vector.x;\n val[M13] = vector.y;\n val[M23] = vector.z;\n return this;\n }\n\n public Matrix4d setToTranslation(Vector3 vector) {\n idt();\n val[M03] = vector.x;\n val[M13] = vector.y;\n val[M23] = vector.z;\n return this;\n }\n\n /**\n * Sets this matrix to a translation matrix, overwriting it first by an\n * identity matrix and then setting the 4th column to the translation\n * vector.\n *\n * @param x The x-component of the translation vector.\n * @param y The y-component of the translation vector.\n * @param z The z-component of the translation vector.\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setToTranslation(double x, double y, double z) {\n idt();\n val[M03] = x;\n val[M13] = y;\n val[M23] = z;\n return this;\n }\n\n /**\n * Sets this matrix to a translation and scaling matrix by first overwriting\n * it with an identity and then setting the translation vector in the 4th\n * column and the scaling vector in the diagonal.\n *\n * @param translation The translation vector\n * @param scaling The scaling vector\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setToTranslationAndScaling(Vector3d translation, Vector3d scaling) {\n idt();\n val[M03] = translation.x;\n val[M13] = translation.y;\n val[M23] = translation.z;\n val[M00] = scaling.x;\n val[M11] = scaling.y;\n val[M22] = scaling.z;\n return this;\n }\n\n /**\n * Sets this matrix to a translation and scaling matrix by first overwriting\n * it with an identity and then setting the translation vector in the 4th\n * column and the scaling vector in the diagonal.\n *\n * @param translationX The x-component of the translation vector\n * @param translationY The y-component of the translation vector\n * @param translationZ The z-component of the translation vector\n * @param scalingX The x-component of the scaling vector\n * @param scalingY The x-component of the scaling vector\n * @param scalingZ The x-component of the scaling vector\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setToTranslationAndScaling(double translationX, double translationY, double translationZ, double scalingX, double scalingY, double scalingZ) {\n idt();\n val[M03] = translationX;\n val[M13] = translationY;\n val[M23] = translationZ;\n val[M00] = scalingX;\n val[M11] = scalingY;\n val[M22] = scalingZ;\n return this;\n }\n\n static Quaterniond quat = new Quaterniond();\n\n /**\n * Sets the matrix to a rotation matrix around the given axis.\n *\n * @param axis The axis\n * @param degrees The angle in degrees\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setToRotation(Vector3d axis, double degrees) {\n if (degrees == 0) {\n idt();\n return this;\n }\n return set(quat.set(axis, degrees));\n }\n\n /**\n * Sets the matrix to a rotation matrix around the given axis.\n *\n * @param axis The axis\n * @param radians The angle in radians\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setToRotationRad(Vector3d axis, double radians) {\n if (radians == 0) {\n idt();\n return this;\n }\n return set(quat.setFromAxisRad(axis, radians));\n }\n\n /**\n * Sets the matrix to a rotation matrix around the given axis.\n *\n * @param axisX The x-component of the axis\n * @param axisY The y-component of the axis\n * @param axisZ The z-component of the axis\n * @param degrees The angle in degrees\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setToRotation(double axisX, double axisY, double axisZ, double degrees) {\n if (degrees == 0) {\n idt();\n return this;\n }\n return set(quat.setFromAxis(axisX, axisY, axisZ, degrees));\n }\n\n /**\n * Sets the matrix to a rotation matrix around the given axis.\n *\n * @param axisX The x-component of the axis\n * @param axisY The y-component of the axis\n * @param axisZ The z-component of the axis\n * @param radians The angle in radians\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setToRotationRad(double axisX, double axisY, double axisZ, double radians) {\n if (radians == 0) {\n idt();\n return this;\n }\n return set(quat.setFromAxisRad(axisX, axisY, axisZ, radians));\n }\n\n /**\n * Set the matrix to a rotation matrix between two vectors.\n *\n * @param v1 The base vector\n * @param v2 The target vector\n *\n * @return This matrix for the purpose of chaining methods together\n */\n public Matrix4d setToRotation(final Vector3d v1, final Vector3d v2) {\n return set(quat.setFromCross(v1, v2));\n }\n\n /**\n * Set the matrix to a rotation matrix between two vectors.\n *\n * @param x1 The base vectors x value\n * @param y1 The base vectors y value\n * @param z1 The base vectors z value\n * @param x2 The target vector x value\n * @param y2 The target vector y value\n * @param z2 The target vector z value\n *\n * @return This matrix for the purpose of chaining methods together\n */\n public Matrix4d setToRotation(final double x1, final double y1, final double z1, final double x2, final double y2, final double z2) {\n return set(quat.setFromCross(x1, y1, z1, x2, y2, z2));\n }\n\n /**\n * Sets this matrix to a rotation matrix from the given euler angles.\n *\n * @param yaw the yaw in degrees\n * @param pitch the pitch in degrees\n * @param roll the roll in degrees\n *\n * @return This matrix\n */\n public Matrix4d setFromEulerAngles(double yaw, double pitch, double roll) {\n quat.setEulerAngles(yaw, pitch, roll);\n return set(quat);\n }\n\n /**\n * Sets this matrix to a scaling matrix\n *\n * @param vector The scaling vector\n *\n * @return This matrix for chaining.\n */\n public Matrix4d setToScaling(Vector3d vector) {\n idt();\n val[M00] = vector.x;\n val[M11] = vector.y;\n val[M22] = vector.z;\n return this;\n }\n\n /**\n * Sets this matrix to a scaling matrix\n *\n * @param x The x-component of the scaling vector\n * @param y The y-component of the scaling vector\n * @param z The z-component of the scaling vector\n *\n * @return This matrix for chaining.\n */\n public Matrix4d setToScaling(double x, double y, double z) {\n idt();\n val[M00] = x;\n val[M11] = y;\n val[M22] = z;\n return this;\n }\n\n static final Vector3d l_vez = new Vector3d();\n static final Vector3d l_vex = new Vector3d();\n static final Vector3d l_vey = new Vector3d();\n static final Vector3b l_vezb = new Vector3b();\n static final Vector3b l_vexb = new Vector3b();\n static final Vector3b l_veyb = new Vector3b();\n\n /**\n * Sets the matrix to a look at matrix with a direction and an up vector.\n * Multiply with a translation matrix to get a camera model view matrix.\n *\n * @param direction The direction vector\n * @param up The up vector\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d setToLookAt(Vector3d direction, Vector3d up) {\n l_vez.set(direction).nor();\n l_vex.set(direction).nor();\n l_vex.crs(up).nor();\n l_vey.set(l_vex).crs(l_vez).nor();\n idt();\n val[M00] = l_vex.x;\n val[M01] = l_vex.y;\n val[M02] = l_vex.z;\n val[M10] = l_vey.x;\n val[M11] = l_vey.y;\n val[M12] = l_vey.z;\n val[M20] = -l_vez.x;\n val[M21] = -l_vez.y;\n val[M22] = -l_vez.z;\n\n return this;\n }\n\n public Matrix4d setToLookAt(Vector3b direction, Vector3b up) {\n l_vezb.set(direction).nor();\n l_vexb.set(direction).nor();\n l_vexb.crs(up).nor();\n l_veyb.set(l_vexb).crs(l_vezb).nor();\n idt();\n val[M00] = l_vexb.x.doubleValue();\n val[M01] = l_vexb.y.doubleValue();\n val[M02] = l_vexb.z.doubleValue();\n val[M10] = l_veyb.x.doubleValue();\n val[M11] = l_veyb.y.doubleValue();\n val[M12] = l_veyb.z.doubleValue();\n val[M20] = -l_vezb.x.doubleValue();\n val[M21] = -l_vezb.y.doubleValue();\n val[M22] = -l_vezb.z.doubleValue();\n\n return this;\n }\n\n static final Vector3d tmpVec = new Vector3d();\n static final Vector3b tmpVecb = new Vector3b();\n static final Matrix4d tmpMat = new Matrix4d();\n\n /**\n * Sets this matrix to a look at matrix with the given position, target and\n * up vector.\n *\n * @param position the position\n * @param target the target\n * @param up the up vector\n *\n * @return This matrix\n */\n public Matrix4d setToLookAt(Vector3d position, Vector3d target, Vector3d up) {\n tmpVec.set(target).sub(position);\n setToLookAt(tmpVec, up);\n this.mul(tmpMat.setToTranslation(-position.x, -position.y, -position.z));\n\n return this;\n }\n\n public Matrix4d setToLookAt(Vector3b position, Vector3b target, Vector3b up) {\n tmpVecb.set(target).sub(position);\n setToLookAt(tmpVecb, up);\n this.mul(tmpMat.setToTranslation(-position.x.doubleValue(), -position.y.doubleValue(), -position.z.doubleValue()));\n\n return this;\n }\n\n static final Vector3d right = new Vector3d();\n static final Vector3d tmpForward = new Vector3d();\n static final Vector3d tmpUp = new Vector3d();\n\n public Matrix4d setToWorld(Vector3d position, Vector3d forward, Vector3d up) {\n tmpForward.set(forward).nor();\n right.set(tmpForward).crs(up).nor();\n tmpUp.set(right).crs(tmpForward).nor();\n\n this.set(right, tmpUp, tmpForward, position);\n return this;\n }\n\n public String toString() {\n return \"[\" + val[M00] + \"|\" + val[M01] + \"|\" + val[M02] + \"|\" + val[M03] + \"]\\n\" + \"[\" + val[M10] + \"|\" + val[M11] + \"|\" + val[M12] + \"|\" + val[M13] + \"]\\n\" + \"[\" + val[M20] + \"|\" + val[M21] + \"|\" + val[M22] + \"|\" + val[M23] + \"]\\n\" + \"[\" + val[M30] + \"|\" + val[M31] + \"|\" + val[M32] + \"|\" + val[M33] + \"]\\n\";\n }\n\n /**\n * Linearly interpolates between this matrix and the given matrix mixing by\n * alpha\n *\n * @param matrix the matrix\n * @param alpha the alpha value in the range [0,1]\n *\n * @return This matrix for the purpose of chaining methods together.\n */\n public Matrix4d lerp(Matrix4d matrix, double alpha) {\n for (int i = 0; i < 16; i++)\n this.val[i] = this.val[i] * (1 - alpha) + matrix.val[i] * alpha;\n return this;\n }\n\n /**\n * Sets this matrix to the given 3x3 matrix. The third column of this matrix\n * is set to (0,0,1,0).\n *\n * @param mat the matrix\n */\n public Matrix4d set(Matrix3 mat) {\n val[0] = mat.val[0];\n val[1] = mat.val[1];\n val[2] = mat.val[2];\n val[3] = 0;\n val[4] = mat.val[3];\n val[5] = mat.val[4];\n val[6] = mat.val[5];\n val[7] = 0;\n val[8] = 0;\n val[9] = 0;\n val[10] = 1;\n val[11] = 0;\n val[12] = mat.val[6];\n val[13] = mat.val[7];\n val[14] = 0;\n val[15] = mat.val[8];\n return this;\n }\n\n public Matrix4d scl(Vector3d scale) {\n val[M00] *= scale.x;\n val[M11] *= scale.y;\n val[M22] *= scale.z;\n return this;\n }\n\n public Matrix4d scl(double x, double y, double z) {\n val[M00] *= x;\n val[M11] *= y;\n val[M22] *= z;\n return this;\n }\n\n public Matrix4d scl(double scale) {\n val[M00] *= scale;\n val[M11] *= scale;\n val[M22] *= scale;\n return this;\n }\n\n public Vector3d getTranslation(Vector3d position) {\n position.x = val[M03];\n position.y = val[M13];\n position.z = val[M23];\n return position;\n }\n\n public Vector3 getTranslationf(Vector3 position) {\n position.x = (float) val[M03];\n position.y = (float) val[M13];\n position.z = (float) val[M23];\n return position;\n }\n\n public double[] getTranslation() {\n return new double[] { val[M03], val[M13], val[M23] };\n }\n\n public float[] getTranslationf() {\n return new float[] { (float) val[M03], (float) val[M13], (float) val[M23] };\n }\n\n public void getTranslationf(float[] vec) {\n vec[0] = (float) val[M03];\n vec[1] = (float) val[M13];\n vec[2] = (float) val[M23];\n }\n\n public Vector3d addTranslationTo(Vector3d position) {\n position.x += val[M03];\n position.y += val[M13];\n position.z += val[M23];\n return position;\n }\n\n /** @return the squared scale factor on the X axis */\n public double getScaleXSquared() {\n return val[Matrix4d.M00] * val[Matrix4d.M00] + val[Matrix4d.M01] * val[Matrix4d.M01] + val[Matrix4d.M02] * val[Matrix4d.M02];\n }\n\n /** @return the squared scale factor on the Y axis */\n public double getScaleYSquared() {\n return val[Matrix4d.M10] * val[Matrix4d.M10] + val[Matrix4d.M11] * val[Matrix4d.M11] + val[Matrix4d.M12] * val[Matrix4d.M12];\n }\n\n /** @return the squared scale factor on the Z axis */\n public double getScaleZSquared() {\n return val[Matrix4d.M20] * val[Matrix4d.M20] + val[Matrix4d.M21] * val[Matrix4d.M21] + val[Matrix4d.M22] * val[Matrix4d.M22];\n }\n\n /** @return the scale factor on the X axis (non-negative) */\n public double getScaleX() {\n return (MathUtilsd.isZero(val[Matrix4d.M01]) && MathUtilsd.isZero(val[Matrix4d.M02])) ? val[Matrix4d.M00] : Math.sqrt(getScaleXSquared());\n }\n\n /** @return the scale factor on the Y axis (non-negative) */\n public double getScaleY() {\n return (MathUtilsd.isZero(val[Matrix4d.M10]) && MathUtilsd.isZero(val[Matrix4d.M12])) ? val[Matrix4d.M11] : Math.sqrt(getScaleYSquared());\n }\n\n /** @return the scale factor on the X axis (non-negative) */\n public double getScaleZ() {\n return (MathUtilsd.isZero(val[Matrix4d.M20]) && MathUtilsd.isZero(val[Matrix4d.M21])) ? val[Matrix4d.M22] : Math.sqrt(getScaleZSquared());\n }\n\n public Vector3d getScale(Vector3d scale) {\n return scale.set(getScaleX(), getScaleY(), getScaleZ());\n }\n\n /** removes the translational part and transposes the matrix. */\n public Matrix4d toNormalMatrix() {\n val[M03] = 0;\n val[M13] = 0;\n val[M23] = 0;\n return inv().tra();\n }\n\n /**\n * Multiplies the vector with the given matrix, performing a division by w.\n * The matrix array is assumed to hold a 4x4 column major matrix as you can\n * get from {@link Matrix4d#val}. The vector array is assumed to hold a\n * 3-component vector, with x being the first element, y being the second\n * and z being the last component. The result is stored in the vector array.\n * This is the same as {@link Vector3d#prj(Matrix4d)}.\n *\n * @param mat the matrix\n * @param vec the vector.\n */\n public static void prj(double[] mat, double[] vec) {\n matrix4_proj(mat, vec, 0);\n }\n\n /**\n * Multiplies the vectors with the given matrix, , performing a division by\n * w. The matrix array is assumed to hold a 4x4 column major matrix as you\n * can get from {@link Matrix4#val}. The vectors array is assumed to hold\n * 3-component vectors. Offset specifies the offset into the array where the\n * x-component of the first vector is located. The numVecs parameter\n * specifies the number of vectors stored in the vectors array. The stride\n * parameter specifies the number of floats between subsequent vectors and\n * must be >= 3. This is the same as {@link Vector3#prj(Matrix4)} applied to\n * multiple vectors.\n *\n * @param mat the matrix\n * @param vecs the vectors\n * @param offset the offset into the vectors array\n * @param numVecs the number of vectors\n * @param stride the stride between vectors in floats\n */\n public static void prj(double[] mat, double[] vecs, int offset, int numVecs, int stride) {\n for (int i = 0; i < numVecs; i++) {\n matrix4_proj(mat, vecs, offset);\n offset += stride;\n }\n }\n\n static void matrix4_mul(double[] mata, double[] matb) {\n stmp[M00] = mata[M00] * matb[M00] + mata[M01] * matb[M10] + mata[M02] * matb[M20] + mata[M03] * matb[M30];\n stmp[M01] = mata[M00] * matb[M01] + mata[M01] * matb[M11] + mata[M02] * matb[M21] + mata[M03] * matb[M31];\n stmp[M02] = mata[M00] * matb[M02] + mata[M01] * matb[M12] + mata[M02] * matb[M22] + mata[M03] * matb[M32];\n stmp[M03] = mata[M00] * matb[M03] + mata[M01] * matb[M13] + mata[M02] * matb[M23] + mata[M03] * matb[M33];\n stmp[M10] = mata[M10] * matb[M00] + mata[M11] * matb[M10] + mata[M12] * matb[M20] + mata[M13] * matb[M30];\n stmp[M11] = mata[M10] * matb[M01] + mata[M11] * matb[M11] + mata[M12] * matb[M21] + mata[M13] * matb[M31];\n stmp[M12] = mata[M10] * matb[M02] + mata[M11] * matb[M12] + mata[M12] * matb[M22] + mata[M13] * matb[M32];\n stmp[M13] = mata[M10] * matb[M03] + mata[M11] * matb[M13] + mata[M12] * matb[M23] + mata[M13] * matb[M33];\n stmp[M20] = mata[M20] * matb[M00] + mata[M21] * matb[M10] + mata[M22] * matb[M20] + mata[M23] * matb[M30];\n stmp[M21] = mata[M20] * matb[M01] + mata[M21] * matb[M11] + mata[M22] * matb[M21] + mata[M23] * matb[M31];\n stmp[M22] = mata[M20] * matb[M02] + mata[M21] * matb[M12] + mata[M22] * matb[M22] + mata[M23] * matb[M32];\n stmp[M23] = mata[M20] * matb[M03] + mata[M21] * matb[M13] + mata[M22] * matb[M23] + mata[M23] * matb[M33];\n stmp[M30] = mata[M30] * matb[M00] + mata[M31] * matb[M10] + mata[M32] * matb[M20] + mata[M33] * matb[M30];\n stmp[M31] = mata[M30] * matb[M01] + mata[M31] * matb[M11] + mata[M32] * matb[M21] + mata[M33] * matb[M31];\n stmp[M32] = mata[M30] * matb[M02] + mata[M31] * matb[M12] + mata[M32] * matb[M22] + mata[M33] * matb[M32];\n stmp[M33] = mata[M30] * matb[M03] + mata[M31] * matb[M13] + mata[M32] * matb[M23] + mata[M33] * matb[M33];\n System.arraycopy(stmp, 0, mata, 0, 16);\n }\n\n static double matrix4_det(double[] val) {\n return val[M30] * val[M21] * val[M12] * val[M03] - val[M20] * val[M31] * val[M12] * val[M03] - val[M30] * val[M11] * val[M22] * val[M03] + val[M10] * val[M31] * val[M22] * val[M03] + val[M20] * val[M11] * val[M32] * val[M03] - val[M10] * val[M21] * val[M32] * val[M03] - val[M30] * val[M21] * val[M02] * val[M13] + val[M20] * val[M31] * val[M02] * val[M13] + val[M30] * val[M01] * val[M22] * val[M13] - val[M00] * val[M31] * val[M22] * val[M13] - val[M20] * val[M01] * val[M32] * val[M13]\n + val[M00] * val[M21] * val[M32] * val[M13] + val[M30] * val[M11] * val[M02] * val[M23] - val[M10] * val[M31] * val[M02] * val[M23] - val[M30] * val[M01] * val[M12] * val[M23] + val[M00] * val[M31] * val[M12] * val[M23] + val[M10] * val[M01] * val[M32] * val[M23] - val[M00] * val[M11] * val[M32] * val[M23] - val[M20] * val[M11] * val[M02] * val[M33] + val[M10] * val[M21] * val[M02] * val[M33] + val[M20] * val[M01] * val[M12] * val[M33] - val[M00] * val[M21] * val[M12] * val[M33]\n - val[M10] * val[M01] * val[M22] * val[M33] + val[M00] * val[M11] * val[M22] * val[M33];\n }\n\n static boolean matrix4_inv(double[] val) {\n double[] tmp = new double[16];\n double l_det = matrix4_det(val);\n if (l_det == 0)\n return false;\n stmp[M00] = val[M12] * val[M23] * val[M31] - val[M13] * val[M22] * val[M31] + val[M13] * val[M21] * val[M32] - val[M11] * val[M23] * val[M32] - val[M12] * val[M21] * val[M33] + val[M11] * val[M22] * val[M33];\n stmp[M01] = val[M03] * val[M22] * val[M31] - val[M02] * val[M23] * val[M31] - val[M03] * val[M21] * val[M32] + val[M01] * val[M23] * val[M32] + val[M02] * val[M21] * val[M33] - val[M01] * val[M22] * val[M33];\n stmp[M02] = val[M02] * val[M13] * val[M31] - val[M03] * val[M12] * val[M31] + val[M03] * val[M11] * val[M32] - val[M01] * val[M13] * val[M32] - val[M02] * val[M11] * val[M33] + val[M01] * val[M12] * val[M33];\n stmp[M03] = val[M03] * val[M12] * val[M21] - val[M02] * val[M13] * val[M21] - val[M03] * val[M11] * val[M22] + val[M01] * val[M13] * val[M22] + val[M02] * val[M11] * val[M23] - val[M01] * val[M12] * val[M23];\n stmp[M10] = val[M13] * val[M22] * val[M30] - val[M12] * val[M23] * val[M30] - val[M13] * val[M20] * val[M32] + val[M10] * val[M23] * val[M32] + val[M12] * val[M20] * val[M33] - val[M10] * val[M22] * val[M33];\n stmp[M11] = val[M02] * val[M23] * val[M30] - val[M03] * val[M22] * val[M30] + val[M03] * val[M20] * val[M32] - val[M00] * val[M23] * val[M32] - val[M02] * val[M20] * val[M33] + val[M00] * val[M22] * val[M33];\n stmp[M12] = val[M03] * val[M12] * val[M30] - val[M02] * val[M13] * val[M30] - val[M03] * val[M10] * val[M32] + val[M00] * val[M13] * val[M32] + val[M02] * val[M10] * val[M33] - val[M00] * val[M12] * val[M33];\n stmp[M13] = val[M02] * val[M13] * val[M20] - val[M03] * val[M12] * val[M20] + val[M03] * val[M10] * val[M22] - val[M00] * val[M13] * val[M22] - val[M02] * val[M10] * val[M23] + val[M00] * val[M12] * val[M23];\n stmp[M20] = val[M11] * val[M23] * val[M30] - val[M13] * val[M21] * val[M30] + val[M13] * val[M20] * val[M31] - val[M10] * val[M23] * val[M31] - val[M11] * val[M20] * val[M33] + val[M10] * val[M21] * val[M33];\n stmp[M21] = val[M03] * val[M21] * val[M30] - val[M01] * val[M23] * val[M30] - val[M03] * val[M20] * val[M31] + val[M00] * val[M23] * val[M31] + val[M01] * val[M20] * val[M33] - val[M00] * val[M21] * val[M33];\n stmp[M22] = val[M01] * val[M13] * val[M30] - val[M03] * val[M11] * val[M30] + val[M03] * val[M10] * val[M31] - val[M00] * val[M13] * val[M31] - val[M01] * val[M10] * val[M33] + val[M00] * val[M11] * val[M33];\n stmp[M23] = val[M03] * val[M11] * val[M20] - val[M01] * val[M13] * val[M20] - val[M03] * val[M10] * val[M21] + val[M00] * val[M13] * val[M21] + val[M01] * val[M10] * val[M23] - val[M00] * val[M11] * val[M23];\n stmp[M30] = val[M12] * val[M21] * val[M30] - val[M11] * val[M22] * val[M30] - val[M12] * val[M20] * val[M31] + val[M10] * val[M22] * val[M31] + val[M11] * val[M20] * val[M32] - val[M10] * val[M21] * val[M32];\n stmp[M31] = val[M01] * val[M22] * val[M30] - val[M02] * val[M21] * val[M30] + val[M02] * val[M20] * val[M31] - val[M00] * val[M22] * val[M31] - val[M01] * val[M20] * val[M32] + val[M00] * val[M21] * val[M32];\n stmp[M32] = val[M02] * val[M11] * val[M30] - val[M01] * val[M12] * val[M30] - val[M02] * val[M10] * val[M31] + val[M00] * val[M12] * val[M31] + val[M01] * val[M10] * val[M32] - val[M00] * val[M11] * val[M32];\n stmp[M33] = val[M01] * val[M12] * val[M20] - val[M02] * val[M11] * val[M20] + val[M02] * val[M10] * val[M21] - val[M00] * val[M12] * val[M21] - val[M01] * val[M10] * val[M22] + val[M00] * val[M11] * val[M22];\n\n double inv_det = 1.0 / l_det;\n val[M00] = stmp[M00] * inv_det;\n val[M01] = stmp[M01] * inv_det;\n val[M02] = stmp[M02] * inv_det;\n val[M03] = stmp[M03] * inv_det;\n val[M10] = stmp[M10] * inv_det;\n val[M11] = stmp[M11] * inv_det;\n val[M12] = stmp[M12] * inv_det;\n val[M13] = stmp[M13] * inv_det;\n val[M20] = stmp[M20] * inv_det;\n val[M21] = stmp[M21] * inv_det;\n val[M22] = stmp[M22] * inv_det;\n val[M23] = stmp[M23] * inv_det;\n val[M30] = stmp[M30] * inv_det;\n val[M31] = stmp[M31] * inv_det;\n val[M32] = stmp[M32] * inv_det;\n val[M33] = stmp[M33] * inv_det;\n return true;\n }\n\n static void matrix4_mulVec(double[] mat, double[] vec, int offset) {\n double x = vec[offset + 0] * mat[M00] + vec[offset + 1] * mat[M01] + vec[offset + 2] * mat[M02] + mat[M03];\n double y = vec[offset + 0] * mat[M10] + vec[offset + 1] * mat[M11] + vec[offset + 2] * mat[M12] + mat[M13];\n double z = vec[offset + 0] * mat[M20] + vec[offset + 1] * mat[M21] + vec[offset + 2] * mat[M22] + mat[M23];\n vec[offset + 0] = x;\n vec[offset + 1] = y;\n vec[offset + 2] = z;\n }\n", "answers": [" static void matrix4_proj(double[] mat, double[] vec, int offset) {"], "length": 7318, "dataset": "lcc", "language": "csharp", "all_classes": null, "_id": "ae5735d7-ff75-4689-b021-2d022600076c", "reasoning": "The code ends with the definition of matrix4_mulVec. In the original library, the next utility method defined after this is the projection helper matrix4_proj, which takes a matrix, a vector array, and an offset. Therefore the next line is the method signature for matrix4_proj.", "reasoning_model_answer": "static void matrix4_proj(double[] mat, double[] vec, int offset) {", "assistant_with_reasoning": "
The methods of this class all throw a NullPointerException\n * if the collections or class objects provided to them are null.\n *\n *
The documentation for the polymorphic algorithms contained in this class\n * generally includes a brief description of the implementation. Such\n * descriptions should be regarded as implementation notes, rather than\n * parts of the specification. Implementors should feel free to\n * substitute other algorithms, so long as the specification itself is adhered\n * to. (For example, the algorithm used by sort does not have to be\n * a mergesort, but it does have to be stable.)\n *\n *
The \"destructive\" algorithms contained in this class, that is, the\n * algorithms that modify the collection on which they operate, are specified\n * to throw UnsupportedOperationException if the collection does not\n * support the appropriate mutation primitive(s), such as the set\n * method. These algorithms may, but are not required to, throw this\n * exception if an invocation would have no effect on the collection. For\n * example, invoking the sort method on an unmodifiable list that is\n * already sorted may or may not throw UnsupportedOperationException.\n *\n *
This class is a member of the\n * \n * Java Collections Framework.\n *\n * @author Josh Bloch\n * @author Neal Gafter\n * @see Collection\n * @see Set\n * @see List\n * @see Map\n * @since 1.2\n */\n\npublic class Collections {\n // Suppresses default constructor, ensuring non-instantiability.\n private Collections() {\n }\n\n // Algorithms\n\n /*\n * Tuning parameters for algorithms - Many of the List algorithms have\n * two implementations, one of which is appropriate for RandomAccess\n * lists, the other for \"sequential.\" Often, the random access variant\n * yields better performance on small sequential access lists. The\n * tuning parameters below determine the cutoff point for what constitutes\n * a \"small\" sequential access list for each algorithm. The values below\n * were empirically determined to work well for LinkedList. Hopefully\n * they should be reasonable for other sequential access List\n * implementations. Those doing performance work on this code would\n * do well to validate the values of these parameters from time to time.\n * (The first word of each tuning parameter name is the algorithm to which\n * it applies.)\n */\n private static final int BINARYSEARCH_THRESHOLD = 5000;\n private static final int REVERSE_THRESHOLD = 18;\n private static final int SHUFFLE_THRESHOLD = 5;\n private static final int FILL_THRESHOLD = 25;\n private static final int ROTATE_THRESHOLD = 100;\n private static final int COPY_THRESHOLD = 10;\n private static final int REPLACEALL_THRESHOLD = 11;\n private static final int INDEXOFSUBLIST_THRESHOLD = 35;\n\n /**\n * Sorts the specified list into ascending order, according to the\n * {@linkplain Comparable natural ordering} of its elements.\n * All elements in the list must implement the {@link Comparable}\n * interface. Furthermore, all elements in the list must be\n * mutually comparable (that is, {@code e1.compareTo(e2)}\n * must not throw a {@code ClassCastException} for any elements\n * {@code e1} and {@code e2} in the list).\n *\n *
This sort is guaranteed to be stable: equal elements will\n * not be reordered as a result of the sort.\n *\n *
The specified list must be modifiable, but need not be resizable.\n *\n *
Implementation note: This implementation is a stable, adaptive,\n * iterative mergesort that requires far fewer than n lg(n) comparisons\n * when the input array is partially sorted, while offering the\n * performance of a traditional mergesort when the input array is\n * randomly ordered. If the input array is nearly sorted, the\n * implementation requires approximately n comparisons. Temporary\n * storage requirements vary from a small constant for nearly sorted\n * input arrays to n/2 object references for randomly ordered input\n * arrays.\n *\n *
The implementation takes equal advantage of ascending and\n * descending order in its input array, and can take advantage of\n * ascending and descending order in different parts of the same\n * input array. It is well-suited to merging two or more sorted arrays:\n * simply concatenate the arrays and sort the resulting array.\n *\n *
The implementation was adapted from Tim Peters's list sort for Python\n * (\n * TimSort). It uses techiques from Peter McIlroy's \"Optimistic\n * Sorting and Information Theoretic Complexity\", in Proceedings of the\n * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,\n * January 1993.\n *\n *
This implementation dumps the specified list into an array, sorts\n * the array, and iterates over the list resetting each element\n * from the corresponding position in the array. This avoids the\n * n2 log(n) performance that would result from attempting\n * to sort a linked list in place.\n *\n * @param list the list to be sorted.\n * @throws ClassCastException if the list contains elements that are not\n * mutually comparable (for example, strings and integers).\n * @throws UnsupportedOperationException if the specified list's\n * list-iterator does not support the {@code set} operation.\n * @throws IllegalArgumentException (optional) if the implementation\n * detects that the natural ordering of the list elements is\n * found to violate the {@link Comparable} contract\n */\n public static This sort is guaranteed to be stable: equal elements will\n * not be reordered as a result of the sort.\n *\n * The specified list must be modifiable, but need not be resizable.\n *\n * Implementation note: This implementation is a stable, adaptive,\n * iterative mergesort that requires far fewer than n lg(n) comparisons\n * when the input array is partially sorted, while offering the\n * performance of a traditional mergesort when the input array is\n * randomly ordered. If the input array is nearly sorted, the\n * implementation requires approximately n comparisons. Temporary\n * storage requirements vary from a small constant for nearly sorted\n * input arrays to n/2 object references for randomly ordered input\n * arrays.\n *\n * The implementation takes equal advantage of ascending and\n * descending order in its input array, and can take advantage of\n * ascending and descending order in different parts of the same\n * input array. It is well-suited to merging two or more sorted arrays:\n * simply concatenate the arrays and sort the resulting array.\n *\n * The implementation was adapted from Tim Peters's list sort for Python\n * (\n * TimSort). It uses techiques from Peter McIlroy's \"Optimistic\n * Sorting and Information Theoretic Complexity\", in Proceedings of the\n * Fourth Annual ACM-SIAM Symposium on Discrete Algorithms, pp 467-474,\n * January 1993.\n *\n * This implementation dumps the specified list into an array, sorts\n * the array, and iterates over the list resetting each element\n * from the corresponding position in the array. This avoids the\n * n2 log(n) performance that would result from attempting\n * to sort a linked list in place.\n *\n * @param list the list to be sorted.\n * @param c the comparator to determine the order of the list. A\n * {@code null} value indicates that the elements' natural\n * ordering should be used.\n * @throws ClassCastException if the list contains elements that are not\n * mutually comparable using the specified comparator.\n * @throws UnsupportedOperationException if the specified list's\n * list-iterator does not support the {@code set} operation.\n * @throws IllegalArgumentException (optional) if the comparator is\n * found to violate the {@link Comparator} contract\n */\n public static This method runs in log(n) time for a \"random access\" list (which\n * provides near-constant-time positional access). If the specified list\n * does not implement the {@link RandomAccess} interface and is large,\n * this method will do an iterator-based binary search that performs\n * O(n) link traversals and O(log n) element comparisons.\n *\n * @param list the list to be searched.\n * @param key the key to be searched for.\n * @param c the comparator by which the list is ordered.\n * A null value indicates that the elements'\n * {@linkplain Comparable natural ordering} should be used.\n * @return the index of the search key, if it is contained in the list;\n * otherwise, (-(insertion point) - 1). The\n * insertion point is defined as the point at which the\n * key would be inserted into the list: the index of the first\n * element greater than the key, or list.size() if all\n * elements in the list are less than the specified key. Note\n * that this guarantees that the return value will be >= 0 if\n * and only if the key is found.\n * @throws ClassCastException if the list contains elements that are not\n * mutually comparable using the specified comparator,\n * or the search key is not mutually comparable with the\n * elements of the list using this comparator.\n */\n public static \n *\n * This method runs in linear time.\n *\n * @param list the list whose elements are to be reversed.\n * @throws UnsupportedOperationException if the specified list or\n * its list-iterator does not support the set operation.\n */\n public static void reverse(List> list) {\n int size = list.size();\n if (size < REVERSE_THRESHOLD || list instanceof RandomAccess) {\n for (int i=0, mid=size>>1, j=size-1; i \n *\n * This implementation traverses the list backwards, from the last element\n * up to the second, repeatedly swapping a randomly selected element into\n * the \"current position\". Elements are randomly selected from the\n * portion of the list that runs from the first element to the current\n * position, inclusive. \n *\n * This method runs in linear time. If the specified list does not\n * implement the {@link RandomAccess} interface and is large, this\n * implementation dumps the specified list into an array before shuffling\n * it, and dumps the shuffled array back into the list. This avoids the\n * quadratic behavior that would result from shuffling a \"sequential\n * access\" list in place.\n *\n * @param list the list to be shuffled.\n * @throws UnsupportedOperationException if the specified list or\n * its list-iterator does not support the set operation.\n */\n public static void shuffle(List> list) {\n Random rnd = r;\n if (rnd == null)\n r = rnd = new Random();\n shuffle(list, rnd);\n }\n private static Random r;\n\n /**\n * Randomly permute the specified list using the specified source of\n * randomness. All permutations occur with equal likelihood\n * assuming that the source of randomness is fair. \n *\n * This implementation traverses the list backwards, from the last element\n * up to the second, repeatedly swapping a randomly selected element into\n * the \"current position\". Elements are randomly selected from the\n * portion of the list that runs from the first element to the current\n * position, inclusive. \n *\n * This method runs in linear time. If the specified list does not\n * implement the {@link RandomAccess} interface and is large, this\n * implementation dumps the specified list into an array before shuffling\n * it, and dumps the shuffled array back into the list. This avoids the\n * quadratic behavior that would result from shuffling a \"sequential\n * access\" list in place.\n *\n * @param list the list to be shuffled.\n * @param rnd the source of randomness to use to shuffle the list.\n * @throws UnsupportedOperationException if the specified list or its\n * list-iterator does not support the set operation.\n */\n public static void shuffle(List> list, Random rnd) {\n int size = list.size();\n if (size < SHUFFLE_THRESHOLD || list instanceof RandomAccess) {\n for (int i=size; i>1; i--)\n swap(list, i-1, rnd.nextInt(i));\n } else {\n Object arr[] = list.toArray();\n\n // Shuffle array\n for (int i=size; i>1; i--)\n swap(arr, i-1, rnd.nextInt(i));\n\n // Dump array back into list\n ListIterator it = list.listIterator();\n for (int i=0; i \n *\n * This method runs in linear time.\n *\n * @param list the list to be filled with the specified element.\n * @param obj The element with which to fill the specified list.\n * @throws UnsupportedOperationException if the specified list or its\n * list-iterator does not support the set operation.\n */\n public static \n *\n * This method iterates over the entire collection, hence it requires\n * time proportional to the size of the collection.\n *\n * @param coll the collection whose minimum element is to be determined.\n * @return the minimum element of the given collection, according\n * to the natural ordering of its elements.\n * @throws ClassCastException if the collection contains elements that are\n * not mutually comparable (for example, strings and\n * integers).\n * @throws NoSuchElementException if the collection is empty.\n * @see Comparable\n */\n public static \n *\n * This method iterates over the entire collection, hence it requires\n * time proportional to the size of the collection.\n *\n * @param coll the collection whose minimum element is to be determined.\n * @param comp the comparator with which to determine the minimum element.\n * A null value indicates that the elements' natural\n * ordering should be used.\n * @return the minimum element of the given collection, according\n * to the specified comparator.\n * @throws ClassCastException if the collection contains elements that are\n * not mutually comparable using the specified comparator.\n * @throws NoSuchElementException if the collection is empty.\n * @see Comparable\n */\n public static \n *\n * This method iterates over the entire collection, hence it requires\n * time proportional to the size of the collection.\n *\n * @param coll the collection whose maximum element is to be determined.\n * @return the maximum element of the given collection, according\n * to the natural ordering of its elements.\n * @throws ClassCastException if the collection contains elements that are\n * not mutually comparable (for example, strings and\n * integers).\n * @throws NoSuchElementException if the collection is empty.\n * @see Comparable\n */\n public static \n *\n * This method iterates over the entire collection, hence it requires\n * time proportional to the size of the collection.\n *\n * @param coll the collection whose maximum element is to be determined.\n * @param comp the comparator with which to determine the maximum element.\n * A null value indicates that the elements' natural\n * ordering should be used.\n * @return the maximum element of the given collection, according\n * to the specified comparator.\n * @throws ClassCastException if the collection contains elements that are\n * not mutually comparable using the specified comparator.\n * @throws NoSuchElementException if the collection is empty.\n * @see Comparable\n */\n public static For example, suppose list comprises [t, a, n, k, s].\n * After invoking Collections.rotate(list, 1) (or\n * Collections.rotate(list, -4)), list will comprise\n * [s, t, a, n, k].\n *\n * Note that this method can usefully be applied to sublists to\n * move one or more elements within a list while preserving the\n * order of the remaining elements. For example, the following idiom\n * moves the element at index j forward to position\n * k (which must be greater than or equal to j):\n * To move more than one element forward, increase the absolute value\n * of the rotation distance. To move elements backward, use a positive\n * shift distance.\n *\n * If the specified list is small or implements the {@link\n * RandomAccess} interface, this implementation exchanges the first\n * element into the location it should go, and then repeatedly exchanges\n * the displaced element into the location it should go until a displaced\n * element is swapped into the first element. If necessary, the process\n * is repeated on the second and successive elements, until the rotation\n * is complete. If the specified list is large and doesn't implement the\n * RandomAccess interface, this implementation breaks the\n * list into two sublist views around index -distance mod size.\n * Then the {@link #reverse(List)} method is invoked on each sublist view,\n * and finally it is invoked on the entire list. For a more complete\n * description of both algorithms, see Section 2.3 of Jon Bentley's\n * Programming Pearls (Addison-Wesley, 1986).\n *\n * @param list the list to be rotated.\n * @param distance the distance to rotate the list. There are no\n * constraints on this value; it may be zero, negative, or\n * greater than list.size().\n * @throws UnsupportedOperationException if the specified list or\n * its list-iterator does not support the set operation.\n * @since 1.4\n */\n public static void rotate(List> list, int distance) {\n if (list instanceof RandomAccess || list.size() < ROTATE_THRESHOLD)\n rotate1(list, distance);\n else\n rotate2(list, distance);\n }\n\n private static This implementation uses the \"brute force\" technique of scanning\n * over the source list, looking for a match with the target at each\n * location in turn.\n *\n * @param source the list in which to search for the first occurrence\n * of target.\n * @param target the list to search for as a subList of source.\n * @return the starting position of the first occurrence of the specified\n * target list within the specified source list, or -1 if there\n * is no such occurrence.\n * @since 1.4\n */\n public static int indexOfSubList(List> source, List> target) {\n int sourceSize = source.size();\n int targetSize = target.size();\n int maxCandidate = sourceSize - targetSize;\n\n if (sourceSize < INDEXOFSUBLIST_THRESHOLD ||\n (source instanceof RandomAccess&&target instanceof RandomAccess)) {\n nextCand:\n for (int candidate = 0; candidate <= maxCandidate; candidate++) {\n for (int i=0, j=candidate; i This implementation uses the \"brute force\" technique of iterating\n * over the source list, looking for a match with the target at each\n * location in turn.\n *\n * @param source the list in which to search for the last occurrence\n * of target.\n * @param target the list to search for as a subList of source.\n * @return the starting position of the last occurrence of the specified\n * target list within the specified source list, or -1 if there\n * is no such occurrence.\n * @since 1.4\n */\n public static int lastIndexOfSubList(List> source, List> target) {\n int sourceSize = source.size();\n int targetSize = target.size();\n int maxCandidate = sourceSize - targetSize;\n\n if (sourceSize < INDEXOFSUBLIST_THRESHOLD ||\n source instanceof RandomAccess) { // Index access version\n nextCand:\n for (int candidate = maxCandidate; candidate >= 0; candidate--) {\n for (int i=0, j=candidate; i \n *\n * The returned collection does not pass the hashCode and equals\n * operations through to the backing collection, but relies on\n * Object's equals and hashCode methods. This\n * is necessary to preserve the contracts of these operations in the case\n * that the backing collection is a set or a list. \n *\n * The returned collection will be serializable if the specified collection\n * is serializable.\n *\n * @param c the collection for which an unmodifiable view is to be\n * returned.\n * @return an unmodifiable view of the specified collection.\n */\n public static \n *\n * The returned set will be serializable if the specified set\n * is serializable.\n *\n * @param s the set for which an unmodifiable view is to be returned.\n * @return an unmodifiable view of the specified set.\n */\n public static \n *\n * The returned sorted set will be serializable if the specified sorted set\n * is serializable.\n *\n * @param s the sorted set for which an unmodifiable view is to be\n * returned.\n * @return an unmodifiable view of the specified sorted set.\n */\n public static \n *\n * The returned list will be serializable if the specified list\n * is serializable. Similarly, the returned list will implement\n * {@link RandomAccess} if the specified list does.\n *\n * @param list the list for which an unmodifiable view is to be returned.\n * @return an unmodifiable view of the specified list.\n */\n public static \n *\n * The returned map will be serializable if the specified map\n * is serializable.\n *\n * @param m the map for which an unmodifiable view is to be returned.\n * @return an unmodifiable view of the specified map.\n */\n public static \n *\n * The returned sorted map will be serializable if the specified sorted map\n * is serializable.\n *\n * @param m the sorted map for which an unmodifiable view is to be\n * returned.\n * @return an unmodifiable view of the specified sorted map.\n */\n public static \n *\n * It is imperative that the user manually synchronize on the returned\n * collection when iterating over it:\n * The returned collection does not pass the hashCode\n * and equals operations through to the backing collection, but\n * relies on Object's equals and hashCode methods. This is\n * necessary to preserve the contracts of these operations in the case\n * that the backing collection is a set or a list. \n *\n * The returned collection will be serializable if the specified collection\n * is serializable.\n *\n * @param c the collection to be \"wrapped\" in a synchronized collection.\n * @return a synchronized view of the specified collection.\n */\n public static \n *\n * It is imperative that the user manually synchronize on the returned\n * set when iterating over it:\n * The returned set will be serializable if the specified set is\n * serializable.\n *\n * @param s the set to be \"wrapped\" in a synchronized set.\n * @return a synchronized view of the specified set.\n */\n public static \n *\n * It is imperative that the user manually synchronize on the returned\n * sorted set when iterating over it or any of its subSet,\n * headSet, or tailSet views.\n * The returned sorted set will be serializable if the specified\n * sorted set is serializable.\n *\n * @param s the sorted set to be \"wrapped\" in a synchronized sorted set.\n * @return a synchronized view of the specified sorted set.\n */\n public static \n *\n * It is imperative that the user manually synchronize on the returned\n * list when iterating over it:\n * The returned list will be serializable if the specified list is\n * serializable.\n *\n * @param list the list to be \"wrapped\" in a synchronized list.\n * @return a synchronized view of the specified list.\n */\n public static \n * For every protected or public constructor in the extended class, the adapter class will have either one or two\n * public constructors (visibility of protected constructors in the extended class is promoted to public).\n * \n * For adapter methods that return values, all the JavaScript-to-Java conversions supported by Nashorn will be in effect\n * to coerce the JavaScript function return value to the expected Java return type.\n * \n * Since we are adding a trailing argument to the generated constructors in the adapter class, they will never be\n * declared as variable arity, even if the original constructor in the superclass was declared as variable arity. The\n * reason we are passing the additional argument at the end of the argument list instead at the front is that the\n * source-level script expression \n * It is possible to create two different adapter classes: those that can have class-level overrides, and those that can\n * have instance-level overrides. When {@link JavaAdapterFactory#getAdapterClassFor(Class[], ScriptObject)} is invoked\n * with non-null {@code classOverrides} parameter, an adapter class is created that can have class-level overrides, and\n * the passed script object will be used as the implementations for its methods, just as in the above case of the\n * constructor taking a script object. Note that in the case of class-level overrides, a new adapter class is created on\n * every invocation, and the implementation object is bound to the class, not to any instance. All created instances\n * will share these functions. If it is required to have both class-level overrides and instance-level overrides, the\n * class-level override adapter class should be subclassed with an instance-override adapter. Since adapters delegate to\n * super class when an overriding method handle is not specified, this will behave as expected. It is not possible to\n * have both class-level and instance-level overrides in the same class for security reasons: adapter classes are\n * defined with a protection domain of their creator code, and an adapter class that has both class and instance level\n * overrides would need to have two potentially different protection domains: one for class-based behavior and one for\n * instance-based behavior; since Java classes can only belong to a single protection domain, this could not be\n * implemented securely.\n */\nfinal class JavaAdapterBytecodeGenerator {\n private static final Type CONTEXT_TYPE = Type.getType(Context.class);\n private static final Type OBJECT_TYPE = Type.getType(Object.class);\n private static final Type SCRIPT_OBJECT_TYPE = Type.getType(ScriptObject.class);\n private static final Type GLOBAL_TYPE = Type.getType(Global.class);\n private static final Type CLASS_TYPE = Type.getType(Class.class);\n\n static final String CONTEXT_TYPE_NAME = CONTEXT_TYPE.getInternalName();\n static final String OBJECT_TYPE_NAME = OBJECT_TYPE.getInternalName();\n\n static final String INIT = \"\n * Collections.rotate(list.subList(j, k+1), -1);\n *
\n * To make this concrete, suppose list comprises\n * [a, b, c, d, e]. To move the element at index 1\n * (b) forward two positions, perform the following invocation:\n * \n * Collections.rotate(l.subList(1, 4), -1);\n *
\n * The resulting list is [a, c, d, b, e].\n *\n * \n * Collection c = Collections.synchronizedCollection(myCollection);\n * ...\n * synchronized (c) {\n * Iterator i = c.iterator(); // Must be in the synchronized block\n * while (i.hasNext())\n * foo(i.next());\n * }\n * \n * Failure to follow this advice may result in non-deterministic behavior.\n *\n * \n * Set s = Collections.synchronizedSet(new HashSet());\n * ...\n * synchronized (s) {\n * Iterator i = s.iterator(); // Must be in the synchronized block\n * while (i.hasNext())\n * foo(i.next());\n * }\n * \n * Failure to follow this advice may result in non-deterministic behavior.\n *\n * \n * SortedSet s = Collections.synchronizedSortedSet(new TreeSet());\n * ...\n * synchronized (s) {\n * Iterator i = s.iterator(); // Must be in the synchronized block\n * while (i.hasNext())\n * foo(i.next());\n * }\n * \n * or:\n * \n * SortedSet s = Collections.synchronizedSortedSet(new TreeSet());\n * SortedSet s2 = s.headSet(foo);\n * ...\n * synchronized (s) { // Note: s, not s2!!!\n * Iterator i = s2.iterator(); // Must be in the synchronized block\n * while (i.hasNext())\n * foo(i.next());\n * }\n * \n * Failure to follow this advice may result in non-deterministic behavior.\n *\n * \n * List list = Collections.synchronizedList(new ArrayList());\n * ...\n * synchronized (list) {\n * Iterator i = list.iterator(); // Must be in synchronized block\n * while (i.hasNext())\n * foo(i.next());\n * }\n * \n * Failure to follow this advice may result in non-deterministic behavior.\n *\n * new X(a, b) { ... } (which is a proprietary syntax extension Nashorn uses\n * to resemble Java anonymous classes) is actually equivalent to new X(a, b, { ... }).\n *