use of org.opengis.referencing.operation.Matrix in project sis by apache.
the class LinearTransformBuilderTest method testMinimalist2D.
/**
* Tests a very simple case where an exact answer is expected.
* Tolerance threshold is set to zero because the math transform has been built from exactly 3 points,
* in which case we expect an exact solution without rounding errors at the scale of the {@code double}
* type. This is possible because SIS implementation uses double-double arithmetic.
*
* @throws FactoryException if the transform can not be created.
*/
@Test
public void testMinimalist2D() throws FactoryException {
final Map<DirectPosition2D, DirectPosition2D> pos = new HashMap<>(8);
assertNull(pos.put(new DirectPosition2D(1, 1), new DirectPosition2D(3, 2)));
assertNull(pos.put(new DirectPosition2D(1, 2), new DirectPosition2D(3, 5)));
assertNull(pos.put(new DirectPosition2D(2, 2), new DirectPosition2D(5, 5)));
final LinearTransformBuilder builder = new LinearTransformBuilder();
builder.setControlPoints(pos);
assertArrayEquals(new double[] { 3, 2 }, builder.getControlPoint(new int[] { 1, 1 }), STRICT);
assertArrayEquals(new double[] { 3, 5 }, builder.getControlPoint(new int[] { 1, 2 }), STRICT);
assertArrayEquals(new double[] { 5, 5 }, builder.getControlPoint(new int[] { 2, 2 }), STRICT);
assertNull(builder.getControlPoint(new int[] { 2, 1 }));
final Matrix m = builder.create(null).getMatrix();
// First row (x)
assertEquals("m₀₀", 2, m.getElement(0, 0), STRICT);
assertEquals("m₀₁", 0, m.getElement(0, 1), STRICT);
assertEquals("m₀₂", 1, m.getElement(0, 2), STRICT);
// Second row (y)
assertEquals("m₁₀", 0, m.getElement(1, 0), STRICT);
assertEquals("m₁₁", 3, m.getElement(1, 1), STRICT);
assertEquals("m₁₂", -1, m.getElement(1, 2), STRICT);
assertArrayEquals("correlation", new double[] { 1, 1 }, builder.correlation(), STRICT);
}
use of org.opengis.referencing.operation.Matrix in project sis by apache.
the class LinearTransformBuilderTest method verify.
/**
* Verifies the transform created by {@link #testExplicitSource2D()} and {@link #testImplicitSource2D()}.
*/
private void verify(final LinearTransformBuilder builder) throws FactoryException {
final Matrix m = builder.create(null).getMatrix();
assertArrayEquals(new double[] { 3, 9 }, builder.getControlPoint(new int[] { 0, 0 }), STRICT);
assertArrayEquals(new double[] { 4, 7 }, builder.getControlPoint(new int[] { 0, 1 }), STRICT);
assertArrayEquals(new double[] { 6, 6 }, builder.getControlPoint(new int[] { 0, 2 }), STRICT);
assertArrayEquals(new double[] { 4, 8 }, builder.getControlPoint(new int[] { 1, 0 }), STRICT);
assertArrayEquals(new double[] { 5, 4 }, builder.getControlPoint(new int[] { 1, 1 }), STRICT);
assertArrayEquals(new double[] { 8, 2 }, builder.getControlPoint(new int[] { 1, 2 }), STRICT);
/*
* Expect STRICT results because Apache SIS uses double-double arithmetic.
*/
// First row (x)
assertEquals("m₀₀", 16 / 12d, m.getElement(0, 0), STRICT);
assertEquals("m₀₁", 21 / 12d, m.getElement(0, 1), STRICT);
assertEquals("m₀₂", 31 / 12d, m.getElement(0, 2), STRICT);
// Second row (y)
assertEquals("m₁₀", -32 / 12d, m.getElement(1, 0), STRICT);
assertEquals("m₁₁", -27 / 12d, m.getElement(1, 1), STRICT);
assertEquals("m₁₂", 115 / 12d, m.getElement(1, 2), STRICT);
assertArrayEquals("correlation", new double[] { 0.9656, 0.9536 }, builder.correlation(), 0.0001);
}
use of org.opengis.referencing.operation.Matrix in project sis by apache.
the class ContextualParametersTest method testCompleteTransform.
/**
* Tests {@link ContextualParameters#completeTransform(MathTransformFactory, MathTransform)}
* with non-identity normalization transforms.
*
* @throws FactoryException should never happen.
*/
@Test
@DependsOnMethod("testSameTransform")
public void testCompleteTransform() throws FactoryException {
final ContextualParameters p = create(2, 2);
final Matrix normalize = p.normalizeGeographicInputs(12);
final Matrix denormalize = p.denormalizeGeographicOutputs(18);
final Matrix product = MathTransforms.getMatrix(p.completeTransform(DefaultMathTransformFactoryTest.factory(), MathTransforms.identity(2)));
assertMatrixEquals("normalize", new Matrix3(PI / 180, 0, toRadians(-12), 0, PI / 180, 0, 0, 0, 1), normalize, 1E-16);
assertMatrixEquals("denormalize", new Matrix3(180 / PI, 0, 18, 0, 180 / PI, 0, 0, 0, 1), denormalize, STRICT);
assertMatrixEquals("product", new Matrix3(1, 0, 6, 0, 1, 0, 0, 0, 1), product, STRICT);
}
use of org.opengis.referencing.operation.Matrix in project sis by apache.
the class ObliqueStereographicTest method testSphericalDerivative.
/**
* 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 {
// in degrees
final double[] srcPts = new double[] { λt, φt };
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);
}
use of org.opengis.referencing.operation.Matrix in project sis by apache.
the class ProjectionResultComparator method transform.
/**
* Checks if transform using {@link #tested} formulas produces the same result than the {@link #reference} formulas.
*/
@Override
public Matrix transform(final double[] srcPts, final int srcOff, final double[] dstPts, final int dstOff, boolean derivate) throws ProjectionException {
final double[] point = Arrays.copyOfRange(srcPts, srcOff, srcOff + 2);
final Matrix derivative = tested.transform(srcPts, srcOff, dstPts, dstOff, derivate);
final Matrix expected = reference.transform(point, 0, point, 0, derivate);
if (dstPts != null) {
assertEquals("x", point[0], dstPts[dstOff], FORWARD_TOLERANCE);
assertEquals("y", point[1], dstPts[dstOff + 1], FORWARD_TOLERANCE);
}
if (expected != null && derivative != null) {
assertEquals("m00", expected.getElement(0, 0), derivative.getElement(0, 0), DERIVATIVE_TOLERANCE);
assertEquals("m01", expected.getElement(0, 1), derivative.getElement(0, 1), DERIVATIVE_TOLERANCE);
assertEquals("m10", expected.getElement(1, 0), derivative.getElement(1, 0), DERIVATIVE_TOLERANCE);
assertEquals("m11", expected.getElement(1, 1), derivative.getElement(1, 1), DERIVATIVE_TOLERANCE);
}
return derivative;
}
Aggregations