static void removeNaN(PointList pointList) {
        int curr = 0;
        for (int i = 0; i < pointList.size(); i++) {
            if (!Double.isNaN(pointList.getLat(i))) {
                pointList.set(curr, pointList.getLat(i), pointList.getLon(i), pointList.getEle(i));
                curr++;
            }
        }
        pointList.trimToSize(curr);
    }
@Test
    public void testRemoveNaN() {
        PointList pl = new PointList(10, true);
        pl.add(Double.NaN, Double.NaN, Double.NaN);
        pl.add(1, 1, 1);
        pl.add(Double.NaN, Double.NaN, Double.NaN);
        pl.add(Double.NaN, Double.NaN, Double.NaN);
        pl.add(Double.NaN, Double.NaN, Double.NaN);
        pl.add(5, 5, 5);
        pl.add(6, 6, 6);
        pl.add(7, 7, 7);
        pl.add(Double.NaN, Double.NaN, Double.NaN);
        pl.add(8, 8, 8);
        pl.add(Double.NaN, Double.NaN, Double.NaN);
        pl.add(9, 9, 9);
        pl.add(10, 10, 10);
        pl.add(Double.NaN, Double.NaN, Double.NaN);
        pl.add(Double.NaN, Double.NaN, Double.NaN);
        pl.add(Double.NaN, Double.NaN, Double.NaN);
        pl.add(14, 14, 14);
        pl.add(Double.NaN, Double.NaN, Double.NaN);

        RamerDouglasPeucker.removeNaN(pl);
        // doing it again should be no problem
        RamerDouglasPeucker.removeNaN(pl);
        RamerDouglasPeucker.removeNaN(pl);
        assertEquals(8, pl.size());
        List<Integer> expected = Arrays.asList(1, 5, 6, 7, 8, 9, 10, 14);
        List<Integer> given = new ArrayList<>();
        for (int i = 0; i < pl.size(); i++) {
            assertEquals(pl.getLat(i), pl.getEle(i), 1.e-6);
            assertEquals(pl.getLon(i), pl.getEle(i), 1.e-6);
            given.add((int) pl.getLat(i));
        }
        assertEquals(expected, given);
    }