本文整理了Java中org.apache.sis.test.Assert.assertMatrixEquals()
方法的一些代码示例,展示了Assert.assertMatrixEquals()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Assert.assertMatrixEquals()
方法的具体详情如下:
包路径:org.apache.sis.test.Assert
类名称:Assert
方法名:assertMatrixEquals
暂无
代码示例来源:origin: apache/sis
/**
* Delegates to the tested implementation and verifies that the value is equals
* to the one provided by the reference implementation.
*/
@Override
public Matrix derivative(DirectPosition point) throws MismatchedDimensionException, TransformException {
final Matrix value = tested.derivative(point);
assertMatrixEquals("derivative", reference.derivative(point), value, tolerance);
return value;
}
代码示例来源:origin: apache/sis
/**
* Tests {@link MatrixSIS#translate(double[])} using {@link AffineTransform} as a reference implementation.
* This test can be run only with matrices of size 3×3. Consequently it is sub-classes responsibility to add
* a {@code testTranslateVector()} method which invoke this method.
*
* @param matrix an initially empty matrix of size 3×3 to test.
*
* @since 1.0
*/
final void testTranslateVector(final MatrixSIS matrix) {
initialize(-1691066807752485433L);
final AffineTransform at = new AffineTransform();
final double vector[] = new double[] {0, 0, 1};
for (int n=0; n<NUMBER_OF_REPETITIONS; n++) {
if ((n % 10) == 0) {
setRandomValues(at, matrix);
}
at.translate(vector[0] = random.nextDouble() * 50 - 25,
vector[1] = random.nextDouble() * 50 - 25);
matrix.translate(vector);
assertMatrixEquals("translate", AffineTransforms2D.toMatrix(at), matrix, TOLERANCE);
}
}
代码示例来源:origin: apache/sis
/**
* Tests {@link MathTransforms#getSteps(MathTransform)}.
*/
@Test
public void testGetSteps() {
final Matrix4 scale = new Matrix4(); // Scales a value.
final Matrix4 swap = new Matrix4(); // Swaps two dimensions.
final List<MathTransform> steps = MathTransforms.getSteps(createConcatenateAndPassThrough(scale, swap));
assertEquals(3, steps.size());
assertMatrixEquals("Step 1", scale, MathTransforms.getMatrix(steps.get(0)), STRICT);
assertMatrixEquals("Step 3", swap, MathTransforms.getMatrix(steps.get(2)), STRICT);
assertInstanceOf ("Step 2", PassThroughTransform.class, steps.get(1));
}
代码示例来源:origin: apache/sis
/**
* Tests {@link PixelTranslation#translate(MathTransform, PixelOrientation, PixelOrientation, int, int)}.
* See {@link #testTranslatePixelInCell()} for discussion on expected values.
*/
@Test
public void testTranslatePixelOrientation() {
MathTransform mt = centerToCorner2D();
assertMatrixEquals("center → corner", new Matrix3(
1, 0, -0.5,
0, 1, -0.5,
0, 0, 1), MathTransforms.getMatrix(mt), STRICT);
mt = PixelTranslation.translate(MathTransforms.identity(3), PixelOrientation.LOWER_LEFT, PixelOrientation.CENTER, 1, 2);
assertMatrixEquals("corner → center", new Matrix4(
1, 0, 0, 0.0,
0, 1, 0, +0.5,
0, 0, 1, -0.5,
0, 0, 0, 1), MathTransforms.getMatrix(mt), STRICT);
}
代码示例来源:origin: apache/sis
/**
* Invokes {@link BursaWolfParameters#getPositionVectorTransformation(Date)}
* and compares with our own matrix calculated using double arithmetic.
*/
private static MatrixSIS getPositionVectorTransformation(final BursaWolfParameters p) {
final double S = 1 + p.dS / BursaWolfParameters.PPM;
final double RS = TO_RADIANS * S;
final Matrix4 expected = new Matrix4(
S, -p.rZ*RS, +p.rY*RS, p.tX,
+p.rZ*RS, S, -p.rX*RS, p.tY,
-p.rY*RS, +p.rX*RS, S, p.tZ,
0, 0, 0, 1);
final MatrixSIS matrix = MatrixSIS.castOrCopy(p.getPositionVectorTransformation(null));
assertMatrixEquals("getPositionVectorTransformation", expected, matrix, p.isTranslation() ? 0 : 1E-14);
return matrix;
}
代码示例来源:origin: apache/sis
/**
* Tests {@link BursaWolfParameters#getPositionVectorTransformation(Date)}.
* This test transform a point from WGS72 to WGS84, and conversely,
* as documented in the example section of EPSG operation method 9606.
*
* @throws NoninvertibleMatrixException Should never happen.
*/
@Test
public void testGetPositionVectorTransformation() throws NoninvertibleMatrixException {
final BursaWolfParameters bursaWolf = createWGS72_to_WGS84();
final MatrixSIS toWGS84 = getPositionVectorTransformation(bursaWolf);
final MatrixSIS toWGS72 = toWGS84.inverse();
final MatrixSIS source = Matrices.create(4, 1, new double[] {3657660.66, 255768.55, 5201382.11, 1});
final MatrixSIS target = Matrices.create(4, 1, new double[] {3657660.78, 255778.43, 5201387.75, 1});
assertMatrixEquals("toWGS84", target, toWGS84.multiply(source), 0.01);
assertMatrixEquals("toWGS72", source, toWGS72.multiply(target), 0.01);
/*
* Tests the optimized path for translation-only parameters.
* Matrices having only translation terms are much easier to predict.
*/
assertMatrixEquals("Translation only", new Matrix4(
1, 0, 0, -168,
0, 1, 0, -60,
0, 0, 1, 320,
0, 0, 0, 1), getPositionVectorTransformation(createNTF_to_WGS84()), 0);
}
代码示例来源:origin: apache/sis
/**
* Tests {@link ResidualGrid#derivativeInCell(double, double)}.
* The Jacobian is computed with those values:
*
* {@preformat text
* (0,4) (2,3)
* (1,4) (3,3)
* }
*
* So this mean for example that when moving from 1 cell to the right, the residual change from (0,4) to (2,3).
* Consequently the <var>x</var> position is increased from (2-0) = 2 cells in addition to the move to the right
* (so the total increase is 3), and the <var>y</var> position is increased from (3-4) = -1.
*/
@Test
@DependsOnMethod("testGetCellValue")
public void testDerivativeInCell() {
final Matrix expected = new Matrix2(3, 1, -1, 1);
final Matrix actual = grid.derivativeInCell(0.5, 2.5);
assertMatrixEquals("derivativeInCell", expected, actual, STRICT);
}
}
代码示例来源:origin: apache/sis
/**
* Tests {@link CoordinateSystems#swapAndScaleAxes(CoordinateSystem, CoordinateSystem)} for (λ,φ) ↔ (φ,λ).
* This very common conversion is of critical importance to Apache SIS.
*
* @throws IncommensurableException if a conversion between incompatible units was attempted.
*/
@Test
public void testSwapAndScaleAxes2D() throws IncommensurableException {
final CoordinateSystem λφ = new DefaultEllipsoidalCS(singletonMap(NAME_KEY, "(λ,φ)"),
HardCodedAxes.GEODETIC_LONGITUDE,
HardCodedAxes.GEODETIC_LATITUDE);
final CoordinateSystem φλ = new DefaultEllipsoidalCS(singletonMap(NAME_KEY, "(φ,λ)"),
HardCodedAxes.GEODETIC_LATITUDE,
HardCodedAxes.GEODETIC_LONGITUDE);
final Matrix expected = Matrices.create(3, 3, new double[] {
0, 1, 0,
1, 0, 0,
0, 0, 1});
assertTrue(swapAndScaleAxes(λφ, λφ).isIdentity());
assertTrue(swapAndScaleAxes(φλ, φλ).isIdentity());
assertMatrixEquals("(λ,φ) → (φ,λ)", expected, swapAndScaleAxes(λφ, φλ), STRICT);
assertMatrixEquals("(φ,λ) → (λ,φ)", expected, swapAndScaleAxes(φλ, λφ), STRICT);
}
代码示例来源:origin: apache/sis
/**
* Test {@link DefaultMathTransformFactory#createFromWKT(String)}. We test only a very small WKT here because
* it is not the purpose of this class to test the parser. The main purpose of this test is to verify that
* {@link DefaultMathTransformFactory} has been able to instantiate the parser.
*
* @throws FactoryException if the parsing failed.
*/
@Test
public void testCreateFromWKT() throws FactoryException {
final MathTransform tr = factory().createFromWKT(
"PARAM_MT[\"Affine\","
+ "PARAMETER[\"num_row\",2],"
+ "PARAMETER[\"num_col\",2],"
+ "PARAMETER[\"elt_0_1\",7]]");
assertMatrixEquals("Affine", new Matrix2(
1, 7,
0, 1), MathTransforms.getMatrix(tr), STRICT);
}
代码示例来源:origin: apache/sis
/**
* Tests parsing of a {@code INVERSE_MT[…]} element.
* This test uses an affine transform for the inner {@code PARAM_MT[…]} element,
* which is useless since we could as well inverse the matrix in-place. But this
* approach is easier to test.
*
* @throws ParseException if an error occurred during the parsing.
*/
@Test
@DependsOnMethod("testParamMT")
public void testInverseMT() throws ParseException {
final MathTransform tr = parse(
"INVERSE_MT["
+ "PARAM_MT[\"Affine\","
+ "PARAMETER[\"num_row\",3],"
+ "PARAMETER[\"num_col\",3],"
+ "PARAMETER[\"elt_0_0\",2],"
+ "PARAMETER[\"elt_1_1\",4],"
+ "PARAMETER[\"elt_0_2\",5],"
+ "PARAMETER[\"elt_1_2\",3]]]");
assertMatrixEquals("Affine", new Matrix3(
0.5, 0, -2.50,
0, 0.25, -0.75,
0, 0, 1), MathTransforms.getMatrix(tr), STRICT);
}
代码示例来源:origin: apache/sis
/**
* Tests {@link BursaWolfParameters#invert()}.
*
* @throws NoninvertibleMatrixException Should never happen.
*/
@Test
@DependsOnMethod("testProductOfInverse")
public void testInvert() throws NoninvertibleMatrixException {
final BursaWolfParameters bursaWolf = createED87_to_WGS84();
final Matrix original = getPositionVectorTransformation(bursaWolf).inverse();
bursaWolf.invert();
final Matrix inverse = getPositionVectorTransformation(bursaWolf);
assertMatrixEquals("invert", original, inverse, 0.001);
}
代码示例来源:origin: apache/sis
/**
* Tests {@link CoordinateSystems#swapAndScaleAxes(CoordinateSystem, CoordinateSystem)} with a non-square matrix.
*
* @throws IncommensurableException if a conversion between incompatible units was attempted.
*/
@Test
@DependsOnMethod("testSwapAndScaleAxes")
public void testScaleAndSwapAxesNonSquare() throws IncommensurableException {
final DefaultCartesianCS cs = new DefaultCartesianCS(singletonMap(NAME_KEY, "Test"),
new DefaultCoordinateSystemAxis(getProperties(HardCodedAxes.SOUTHING), "y", AxisDirection.SOUTH, Units.CENTIMETRE),
new DefaultCoordinateSystemAxis(getProperties(HardCodedAxes.EASTING), "x", AxisDirection.EAST, Units.MILLIMETRE));
Matrix matrix = swapAndScaleAxes(HardCodedCS.CARTESIAN_2D, cs);
assertMatrixEquals("(x,y) → (y,x)", Matrices.create(3, 3, new double[] {
0, -100, 0,
1000, 0, 0,
0, 0, 1
}), matrix, STRICT);
matrix = swapAndScaleAxes(HardCodedCS.CARTESIAN_3D, cs);
assertMatrixEquals("(x,y,z) → (y,x)", Matrices.create(3, 4, new double[] {
0, -100, 0, 0,
1000, 0, 0, 0,
0, 0, 0, 1
}), matrix, STRICT);
}
代码示例来源:origin: apache/sis
/**
* Tests {@code Geographic3Dto2D.createMathTransform(…)}.
*
* @throws FactoryException should never happen.
* @throws NoninvertibleTransformException should never happen.
*/
@Test
public void testCreateMathTransform() throws FactoryException, NoninvertibleTransformException {
final Geographic3Dto2D provider = new Geographic3Dto2D();
final MathTransform mt = provider.createMathTransform(null, null);
assertSame("Expected cached instance.", mt, provider.createMathTransform(null, null));
/*
* Verify the full matrix. Note that the longitude offset is expected to be in degrees.
* This conversion from grad to degrees is specific to Apache SIS and may be revised in
* future version. See org.apache.sis.referencing.operation package javadoc.
*/
assertInstanceOf("Shall be an affine transform.", LinearTransform.class, mt);
assertMatrixEquals("Expected a Geographic 3D to 2D conversion.", Matrices.create(3, 4, new double[] {
1, 0, 0, 0,
0, 1, 0, 0,
0, 0, 0, 1}), ((LinearTransform) mt).getMatrix(), STRICT);
assertMatrixEquals("Expected a Geographic 2D to 3D conversion.", Matrices.create(4, 3, new double[] {
1, 0, 0,
0, 1, 0,
0, 0, 0,
0, 0, 1}), ((LinearTransform) mt.inverse()).getMatrix(), STRICT);
}
代码示例来源:origin: apache/sis
/**
* Tests {@link PixelTranslation#translate(MathTransform, PixelInCell, PixelInCell)} with an identity transform.
* If grid coordinates (0,0) in "pixel center" convention map to (0,0) in "real world" coordinates,
* then grid coordinates (0,0) in "pixel corner" convention shall map to (-½, -½) in real world.
* That way, grid coordinates (½,½) in "pixel corner" convention still map to (0,0) in real world.
*
* @throws TransformException if an error occurred while transforming a test point.
*/
@Test
public void testTranslatePixelInCell() throws TransformException {
final MathTransform mt = centerToCorner(3);
assertMatrixEquals("center → corner", new Matrix4(
1, 0, 0, -0.5,
0, 1, 0, -0.5,
0, 0, 1, -0.5,
0, 0, 0, 1), MathTransforms.getMatrix(mt), STRICT);
/*
* Just for making clear what we explained in javadoc comment: the real world (0,0,0) coordinates was in the center
* of cell (0,0,0). After we switched to "cell corner" convention, that center is (½,½,½) in grid coordinates but
* should still map (0,0,0) in "real world" coordinates.
*/
final double[] coordinates = new double[] {0.5, 0.5, 0.5};
mt.transform(coordinates, 0, coordinates, 0, 1);
assertArrayEquals(new double[3], coordinates, STRICT);
}
代码示例来源:origin: apache/sis
/**
* Verifies the consistency of spherical formulas with the elliptical formulas.
* This test computes the derivative at a point and takes the result of the elliptical
* implementation as a reference.
*
* @throws TransformException if an error occurred while computing the derivative.
*/
@Test
@DependsOnMethod("testDerivative")
public void testSphericalDerivative() throws TransformException {
final double[] srcPts = new double[] {λt, φt}; // in degrees
srcPts[0] = toRadians(srcPts[0]) - λ0;
srcPts[1] = toRadians(srcPts[1]);
srcPts[0] *= n;
// Using elliptical implementation.
createNormalizedProjection(false);
final Matrix reference = ((NormalizedProjection) transform).transform(srcPts, 0, null, 0, true);
// Using spherical implementation.
ObliqueStereographic spherical = (ObliqueStereographic) transform;
spherical = new ObliqueStereographic.Spherical(spherical);
final Matrix derivative = spherical.transform(srcPts, 0, null, 0, true);
tolerance = 1E-12;
assertMatrixEquals("Spherical derivative", reference, derivative, tolerance);
}
代码示例来源:origin: apache/sis
/**
* Sets the {@link #transform} field to the {@link TranslationTransform} instance to test.
*
* @param dimensions expected number of source and target dimensions.
* @param matrix the data to use for creating the transform.
*/
private void create(final int dimensions, final MatrixSIS matrix) {
final double[] elements = matrix.getElements();
final TranslationTransform tr = new TranslationTransform(matrix.getNumRow(), elements);
assertEquals("sourceDimensions", dimensions, tr.getSourceDimensions());
assertEquals("targetDimensions", dimensions, tr.getTargetDimensions());
assertMatrixEquals("matrix", matrix, tr.getMatrix(), 0.0);
assertArrayEquals("elements", elements, tr.getExtendedElements(), 0.0);
transform = tr;
validate();
}
代码示例来源:origin: apache/sis
/**
* Tests {@link Matrices#createTransform(AxisDirection[], AxisDirection[])} with less axes
* in the destination than in the source.
*
* <div class="note"><b>Note:</b>
* {@code Matrices.createTransform(AxisDirection[], AxisDirection[])} needs to be tested with special care,
* because this method will be the most frequently invoked one when building CRS.</div>
*/
@Test
@DependsOnMethod("testCreateTransformWithDifferentAxes")
public void testCreateTransformWithLessAxes() {
final MatrixSIS matrix = Matrices.createTransform(
new AxisDirection[] {NORTH, EAST, UP},
new AxisDirection[] {DOWN, NORTH});
assertFalse("isIdentity", matrix.isIdentity());
assertEquals("numRow", 3, matrix.getNumRow());
assertEquals("numCol", 4, matrix.getNumCol());
assertMatrixEquals("(N,E,U) → (D,N)", Matrices.create(3, 4, new double[] {
0, 0,-1, 0,
1, 0, 0, 0,
0, 0, 0, 1
}), matrix, STRICT);
}
代码示例来源:origin: apache/sis
/**
* Tests separation of a linear transform containing {@link Double#NaN} values.
*
* @throws FactoryException if an error occurred while creating a new transform.
*/
@Test
public void testIncompleteTransform() throws FactoryException {
Matrix matrix = new Matrix4(
1, 0, 0, 7,
0, 0, 1, 8,
0, NaN, 0, 6,
0, 0, 0, 1
);
TransformSeparator s = new TransformSeparator(MathTransforms.linear(matrix));
s.addSourceDimensions(1);
assertMatrixEquals("transform", new Matrix2(
NaN, 6,
0, 1
), ((LinearTransform) s.separate()).getMatrix(), STRICT);
assertArrayEquals(new int[] {2}, s.getTargetDimensions());
}
代码示例来源:origin: apache/sis
/**
* Tests {@link Matrices#createTransform(AxisDirection[], AxisDirection[])} with the axis repeated twice.
* This unusual, but shall nevertheless be supported.
*
* <div class="note"><b>Note:</b>
* {@code Matrices.createTransform(AxisDirection[], AxisDirection[])} needs to be tested with special care,
* because this method will be the most frequently invoked one when building CRS.</div>
*/
@Test
@DependsOnMethod("testCreateTransformWithLessAxes")
public void testCreateTransformWithRepeatedAxes() {
final MatrixSIS matrix = Matrices.createTransform(
new AxisDirection[] {NORTH, EAST, UP},
new AxisDirection[] {DOWN, DOWN});
assertFalse("isIdentity", matrix.isIdentity());
assertEquals("numRow", 3, matrix.getNumRow());
assertEquals("numCol", 4, matrix.getNumCol());
assertMatrixEquals("(N,E,U) → (D,D)", Matrices.create(3, 4, new double[] {
0, 0,-1, 0,
0, 0,-1, 0,
0, 0, 0, 1
}), matrix, STRICT);
}
代码示例来源:origin: apache/sis
/**
* Sets the {@link #transform} field to the {@link ScaleTransform} instance to test.
*
* @param sourceDimensions expected number of source dimensions.
* @param targetDimensions expected number of source dimensions.
* @param matrix the data to use for creating the transform.
*/
private void create(final int sourceDimensions, final int targetDimensions, final MatrixSIS matrix) {
final double[] elements = matrix.getElements();
final ScaleTransform tr = new ScaleTransform(matrix.getNumRow(), matrix.getNumCol(), elements);
assertEquals("sourceDimensions", sourceDimensions, tr.getSourceDimensions());
assertEquals("targetDimensions", targetDimensions, tr.getTargetDimensions());
Assert.assertMatrixEquals("matrix", matrix, tr.getMatrix(), 0.0);
assertArrayEquals("elements", elements, tr.getExtendedElements(), 0.0);
transform = tr;
validate();
}
内容来源于网络,如有侵权,请联系作者删除!