/** * Casts or copies the given matrix to a {@code Matrix3} implementation. If the given {@code matrix} * is already an instance of {@code Matrix3}, then it is returned unchanged. Otherwise this method * verifies the matrix size, then copies all elements in a new {@code Matrix3} object. * * @param matrix the matrix to cast or copy, or {@code null}. * @return the matrix argument if it can be safely casted (including {@code null} argument), * or a copy of the given matrix otherwise. * @throws MismatchedMatrixSizeException if the size of the given matrix is not {@value #SIZE}×{@value #SIZE}. */ public static Matrix3 castOrCopy(final Matrix matrix) throws MismatchedMatrixSizeException { if (matrix == null || matrix instanceof Matrix3) { return (Matrix3) matrix; } ensureSizeMatch(SIZE, SIZE, matrix); return new Matrix3(matrix); }
/** * Casts or copies the given matrix to a {@code Matrix3} implementation. If the given {@code matrix} * is already an instance of {@code Matrix3}, then it is returned unchanged. Otherwise this method * verifies the matrix size, then copies all elements in a new {@code Matrix3} object. * * @param matrix the matrix to cast or copy, or {@code null}. * @return the matrix argument if it can be safely casted (including {@code null} argument), * or a copy of the given matrix otherwise. * @throws MismatchedMatrixSizeException if the size of the given matrix is not {@value #SIZE}×{@value #SIZE}. */ public static Matrix3 castOrCopy(final Matrix matrix) throws MismatchedMatrixSizeException { if (matrix == null || matrix instanceof Matrix3) { return (Matrix3) matrix; } ensureSizeMatch(SIZE, SIZE, matrix); return new Matrix3(matrix); }