use of org.apache.sis.geometry.DirectPosition1D in project sis by apache.
the class LinearTransformBuilderTest method testMinimalist1D.
/**
* Tests a very simple case where an exact answer is expected.
*
* @throws FactoryException if the transform can not be created.
*/
@Test
public void testMinimalist1D() throws FactoryException {
final LinearTransformBuilder builder = new LinearTransformBuilder();
final Map<DirectPosition1D, DirectPosition1D> pos = new HashMap<>(4);
assertNull(pos.put(new DirectPosition1D(1), new DirectPosition1D(1)));
assertNull(pos.put(new DirectPosition1D(2), new DirectPosition1D(3)));
builder.setControlPoints(pos);
assertArrayEquals(new double[] { 1 }, builder.getControlPoint(new int[] { 1 }), STRICT);
assertArrayEquals(new double[] { 3 }, builder.getControlPoint(new int[] { 2 }), STRICT);
assertNull(builder.getControlPoint(new int[] { 3 }));
final Matrix m = builder.create(null).getMatrix();
assertEquals("m₀₀", 2, m.getElement(0, 0), STRICT);
assertEquals("m₀₁", -1, m.getElement(0, 1), STRICT);
assertArrayEquals("correlation", new double[] { 1 }, builder.correlation(), STRICT);
}
use of org.apache.sis.geometry.DirectPosition1D in project sis by apache.
the class LinearTransformBuilderTest method test1D.
/**
* Implementation of {@link #testExact1D()} and {@link #testNonExact1D()}.
*
* @param rd the random number generator to use.
* @param numPts the number of points to generate.
* @param addErrors {@code true} for adding a random error in the target points.
* @param scaleTolerance tolerance threshold for floating point comparisons.
*/
private static void test1D(final Random rd, final int numPts, final boolean addErrors, final double scaleTolerance, final double translationTolerance) throws FactoryException {
final double scale = rd.nextDouble() * 30 - 12;
final double offset = rd.nextDouble() * 10 - 4;
final Map<DirectPosition1D, DirectPosition1D> pos = new HashMap<>(numPts);
for (int i = 0; i < numPts; i++) {
final DirectPosition1D src = new DirectPosition1D(rd.nextDouble() * 100 - 50);
final DirectPosition1D tgt = new DirectPosition1D(src.ordinate * scale + offset);
if (addErrors) {
tgt.ordinate += rd.nextDouble() * 10 - 5;
}
assertNull(pos.put(src, tgt));
}
/*
* Create the fitted transform to test.
*/
final LinearTransformBuilder builder = new LinearTransformBuilder();
builder.setControlPoints(pos);
final Matrix m = builder.create(null).getMatrix();
assertEquals("m₀₀", scale, m.getElement(0, 0), scaleTolerance);
assertEquals("m₀₁", offset, m.getElement(0, 1), translationTolerance);
assertEquals("correlation", 1, StrictMath.abs(builder.correlation()[0]), scaleTolerance);
}
use of org.apache.sis.geometry.DirectPosition1D in project sis by apache.
the class ConcatenatedTransform1D method derivative.
/**
* Gets the derivative of this function at a value.
*/
@Override
public double derivative(final double value) throws TransformException {
final DirectPosition1D p = new DirectPosition1D(value);
final Matrix m = super.derivative(p);
assert (m.getNumRow() == 1) && (m.getNumCol() == 1);
return m.getElement(0, 0);
}
Aggregations