use of org.apache.sis.referencing.operation.matrix.Matrix2 in project sis by apache.
the class TransferFunctionTest method testLinear.
/**
* Tests the creation of a linear transfer function.
*/
@Test
public void testLinear() {
final TransferFunction f = new TransferFunction();
assertEquals("type", TransferFunctionType.LINEAR, f.getType());
assertEquals("base", 1, f.getBase(), STRICT);
assertEquals("scale", 1, f.getScale(), STRICT);
assertEquals("offset", 0, f.getOffset(), STRICT);
assertEquals("toString", "y = x", f.toString());
f.setScale(0.15);
f.setOffset(-2);
assertEquals("toString", "y = 0.15⋅x − 2", f.toString());
final MathTransform1D transform = f.getTransform();
assertInstanceOf("transform", LinearTransform.class, transform);
assertMatrixEquals("transform.matrix", new Matrix2(0.15, -2, 0, 1), ((LinearTransform) transform).getMatrix(), STRICT);
/*
* Get back the coefficients.
*/
final TransferFunction b = new TransferFunction();
b.setTransform(transform);
assertEquals("type", TransferFunctionType.LINEAR, b.getType());
assertEquals("base", 1, b.getBase(), STRICT);
assertEquals("scale", 0.15, b.getScale(), STRICT);
assertEquals("offset", -2, b.getOffset(), STRICT);
}
use of org.apache.sis.referencing.operation.matrix.Matrix2 in project sis by apache.
the class MathTransformParserTest method testParamMT.
/**
* Tests parsing of a {@code PARAM_MT["Affine", …]} element.
*
* @throws ParseException if an error occurred during the parsing.
*/
@Test
public void testParamMT() throws ParseException {
MathTransform tr;
tr = parse("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);
/*
* Larger matrix, mix quote and bracket styles and insert spaces.
*/
tr = parse("Param_MT(\"Affine\", " + "PARAMETER(“num_row”, 3), " + "Parameter(“num_col”, 3),\n" + "parameter[“elt_0_1”, 1], " + "parameter[“elt_0_2”, 2], " + "parameter[“elt_1_2”, 3] )");
assertMatrixEquals("Affine", new Matrix3(1, 1, 2, 0, 1, 3, 0, 0, 1), MathTransforms.getMatrix(tr), STRICT);
}
use of org.apache.sis.referencing.operation.matrix.Matrix2 in project sis by apache.
the class MathTransformsTest method testCompound.
/**
* Tests {@link MathTransforms#compound(MathTransform...)}.
* This test uses linear transforms because they are easy to test, but the
* {@code MathTransforms.compound(…)} method should work with any transforms.
*/
@Test
public void testCompound() {
final MathTransform t1 = MathTransforms.linear(new Matrix2(// Random numbers (no real meaning)
3, // Random numbers (no real meaning)
-1, 0, 1));
final MathTransform t2 = MathTransforms.linear(new Matrix4(0, 8, 0, 9, 5, 0, 0, -7, 0, 0, 2, 0, 0, 0, 0, 1));
final MathTransform t3 = MathTransforms.linear(new Matrix3(0, -5, -3, 7, 0, -9, 0, 0, 1));
final MathTransform r = MathTransforms.compound(t1, t2, t3);
assertMatrixEquals("compound", Matrices.create(7, 7, new double[] { 3, 0, 0, 0, 0, 0, -1, 0, 0, 8, 0, 0, 0, 9, 0, 5, 0, 0, 0, 0, -7, 0, 0, 0, 2, 0, 0, 0, 0, 0, 0, 0, 0, -5, -3, 0, 0, 0, 0, 7, 0, -9, 0, 0, 0, 0, 0, 0, 1 }), MathTransforms.getMatrix(r), STRICT);
}
use of org.apache.sis.referencing.operation.matrix.Matrix2 in project sis by apache.
the class DefaultMathTransformFactoryTest method testCreateFromWKT.
/**
* 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);
}
use of org.apache.sis.referencing.operation.matrix.Matrix2 in project sis by apache.
the class VerticalOffset method createMathTransform.
/**
* Creates a transform from the specified group of parameter values.
* The parameter value is unconditionally converted to metres.
*
* @param factory ignored (can be null).
* @param values the group of parameter values.
* @return the created math transform.
* @throws ParameterNotFoundException if a required parameter was not found.
*/
@Override
public MathTransform createMathTransform(final MathTransformFactory factory, final ParameterValueGroup values) throws ParameterNotFoundException {
final Parameters pv = Parameters.castOrWrap(values);
final Matrix2 t = new Matrix2();
t.m01 = pv.doubleValue(TZ);
return MathTransforms.linear(t);
}
Aggregations