/** * Gets the derivative of this transform at a point. * * @param point ignored for a linear transform. Can be null. * @return the derivative at the given point. */ @Override public Matrix derivative(final DirectPosition point) throws TransformException { return new Matrix1(scale); }
/** * Returns all matrix elements in a flat, row-major (column indices vary fastest) array. * The array length is 1. * * @return {@inheritDoc} */ @Override public final double[] getElements() { final double[] elements = new double[SIZE*SIZE]; getElements(elements); return elements; }
/** * Sets all matrix elements from a flat, row-major (column indices vary fastest) array. * The array length shall be 1. */ @Override public final void setElements(final double[] elements) { ensureLengthMatch(SIZE*SIZE, elements); m00 = elements[0]; }
/** * Casts or copies the given matrix to a {@code Matrix1} implementation. If the given {@code matrix} * is already an instance of {@code Matrix1}, then it is returned unchanged. Otherwise this method * verifies the matrix size, then copies the element in a new {@code Matrix1} 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 Matrix1 castOrCopy(final Matrix matrix) throws MismatchedMatrixSizeException { if (matrix == null || matrix instanceof Matrix1) { return (Matrix1) matrix; } ensureSizeMatch(SIZE, SIZE, matrix); return new Matrix1(matrix); }
/** * Tests the {@link Matrix1#Matrix1(double)} constructor. * This constructor is specific to the implementation class. */ @Test public void testConstructor() { initialize(415870088589607716L); final double[] elements = createRandomPositiveValues(SIZE * SIZE); final Matrix1 matrix = new Matrix1( elements[0]); validate(matrix); assertArrayEquals(elements, matrix.getElements(), STRICT); } }
/** * Retrieves the value at the specified row and column of this matrix. * This method can be invoked when the matrix size or type is unknown. * If the matrix is known to be an instance of {@code Matrix1}, * then the {@link #m00} field can be read directly for efficiency. * * @param row the row index, which can only be 0. * @param column the column index, which can only be 0. * @return the current value. */ @Override public final double getElement(final int row, final int column) { if (row == 0 && column == 0) { return m00; } else { throw indexOutOfBounds(row, column); } }
/** * Creates a new matrix initialized to the specified values. * The length of the given array must be 1. * * @param elements elements of the matrix. * @throws IllegalArgumentException if the given array does not have the expected length. * * @see #setElements(double[]) * @see Matrices#create(int, int, double[]) */ public Matrix1(final double[] elements) throws IllegalArgumentException { setElements(elements); }
/** * Casts or copies the given matrix to a {@code Matrix1} implementation. If the given {@code matrix} * is already an instance of {@code Matrix1}, then it is returned unchanged. Otherwise this method * verifies the matrix size, then copies the element in a new {@code Matrix1} 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 Matrix1 castOrCopy(final Matrix matrix) throws MismatchedMatrixSizeException { if (matrix == null || matrix instanceof Matrix1) { return (Matrix1) matrix; } ensureSizeMatch(SIZE, SIZE, matrix); return new Matrix1(matrix); }
/** * Modifies the value at the specified row and column of this matrix. * This method can be invoked when the matrix size or type is unknown. * If the matrix is known to be an instance of {@code Matrix1}, * then the {@link #m00} field can be set directly for efficiency. * * @param row the row index, which can only be 0. * @param column the column index, which can only be 0. * @param value the new value to set. */ @Override public final void setElement(final int row, final int column, final double value) { if (row == 0 && column == 0) { m00 = value; } else { throw indexOutOfBounds(row, column); } }
/** * Creates a new matrix initialized to the specified values. * The length of the given array must be 1. * * @param elements elements of the matrix. * @throws IllegalArgumentException if the given array does not have the expected length. * * @see #setElements(double[]) * @see Matrices#create(int, int, double[]) */ public Matrix1(final double[] elements) throws IllegalArgumentException { setElements(elements); }
/** * Gets the derivative of this transform at a point. * * @param point ignored for a linear transform. Can be null. * @return the derivative at the given point. */ @Override public Matrix derivative(final DirectPosition point) throws TransformException { return new Matrix1(scale); }
/** * Returns all matrix elements in a flat, row-major (column indices vary fastest) array. * The array length is 1. * * @return {@inheritDoc} */ @Override public final double[] getElements() { final double[] elements = new double[SIZE*SIZE]; getElements(elements); return elements; }
/** * Modifies the value at the specified row and column of this matrix. * This method can be invoked when the matrix size or type is unknown. * If the matrix is known to be an instance of {@code Matrix1}, * then the {@link #m00} field can be set directly for efficiency. * * @param row the row index, which can only be 0. * @param column the column index, which can only be 0. * @param value the new value to set. */ @Override public final void setElement(final int row, final int column, final double value) { if (row == 0 && column == 0) { m00 = value; } else { throw indexOutOfBounds(row, column); } }
/** * Sets all matrix elements from a flat, row-major (column indices vary fastest) array. * The array length shall be 1. */ @Override public final void setElements(final double[] elements) { ensureLengthMatch(SIZE*SIZE, elements); m00 = elements[0]; }
/** * Transforms a single point in the given array and opportunistically computes its derivative * if requested. The default implementation computes all those values from the {@link #scale} * and {@link #offset} coefficients. */ @Override public Matrix transform(final double[] srcPts, final int srcOff, final double[] dstPts, final int dstOff, final boolean derivate) { if (dstPts != null) { dstPts[dstOff] = offset + scale*srcPts[srcOff]; } return derivate ? new Matrix1(scale) : null; }
/** * Retrieves the value at the specified row and column of this matrix. * This method can be invoked when the matrix size or type is unknown. * If the matrix is known to be an instance of {@code Matrix1}, * then the {@link #m00} field can be read directly for efficiency. * * @param row the row index, which can only be 0. * @param column the column index, which can only be 0. * @return the current value. */ @Override public final double getElement(final int row, final int column) { if (row == 0 && column == 0) { return m00; } else { throw indexOutOfBounds(row, column); } }
/** * Transforms a single point in the given array and opportunistically computes its derivative * if requested. The default implementation computes all those values from the {@link #scale} * and {@link #offset} coefficients. */ @Override public Matrix transform(final double[] srcPts, final int srcOff, final double[] dstPts, final int dstOff, final boolean derivate) { if (dstPts != null) { dstPts[dstOff] = offset + scale*srcPts[srcOff]; } return derivate ? new Matrix1(scale) : null; }
dstPts[dstOff] = y; return derivate ? new Matrix1(d) : null;
dstPts[dstOff] = y; return derivate ? new Matrix1(d) : null;
dstPts[dstOff] = x; return derivate ? new Matrix1(1/d) : null;