ReciprocalInterpolation implements PositionInterpolator<T> { @Override public T interpolatePosition(final SortedSet<T> points) { if (points.size() == 0) { return pointFactory.newPoint(); } float normalizationFactor = 0; float x = 0; float y = 0; for (final T point : points) { if (point.getDivergence() == 0.0) { return point; } final double weight = 1 / point.getDivergence(); normalizationFactor += weight; x += weight * point.getX(); y += weight * point.getY(); } x = x / normalizationFactor; y = y / normalizationFactor; return getResultingPoint(x, y); } ReciprocalInterpolation(final PointFactory<T> factory); @Override T interpolatePosition(final SortedSet<T> points);  }
@Test public void testEmptySet() { NicGeoPoint dstPoint = interpolator.interpolatePosition(distanceSet); assertEquals(0.0, dstPoint.getX()); assertEquals(0.0, dstPoint.getY()); }
@Test public void testZeroDivergence() { NicGeoPoint point1 = new XYPoint(50721776, 7061692); point1.setDivergence(0.0); NicGeoPoint point2 = new XYPoint(50721859, 7061444); point2.setDivergence(5.245503270998597E-4); NicGeoPoint point3 = new XYPoint(50721817, 7061446); point3.setDivergence(0.0012848408659920096); distanceSet = new TreeSet<NicGeoPoint>(); distanceSet.add(point1); distanceSet.add(point2); distanceSet.add(point3); NicGeoPoint pointResult = interpolator.interpolatePosition(distanceSet); assertTrue(pointResult.getX()!=0.0); assertTrue(pointResult.getY()!=0.0); }
@Test public void testSinglePoint() { p1.setDivergence(4.0f); distanceSet.add(p1); NicGeoPoint dstPoint = interpolator.interpolatePosition(distanceSet); assertEquals(p1.getX(), dstPoint.getX(), delta); assertEquals(p1.getY(), dstPoint.getY(), delta); }
@Test public void testTwoPoints() { p1.setDivergence(0.5f); p2.setDivergence(0.3f); distanceSet.add(p1); distanceSet.add(p2); NicGeoPoint dstPoint = interpolator.interpolatePosition(distanceSet); assertEquals(2.6876f, dstPoint.getX(), delta); assertEquals(2.375f, dstPoint.getY(), delta); }
@Test public void testThreePoints() { p1.setDivergence(0.4f); p2.setDivergence(1.1f); p3.setDivergence(0.6f); distanceSet.add(p1); distanceSet.add(p2); distanceSet.add(p3); NicGeoPoint dstPoint = interpolator.interpolatePosition(distanceSet); assertEquals(1.8567f, dstPoint.getX(), delta); assertEquals(2.4925f, dstPoint.getY(), delta); }