private List<Pair<Integer, Double>> integerPixelCoordinatesAndWeights(double d, int numPixels) {
        if (d <= 0.5) return Collections.singletonList(new Pair<>(0, 1.0));
        else if (d >= numPixels - 0.5) return Collections.singletonList(new Pair<>(numPixels - 1, 1.0));
        else {
            double shifted = d - 0.5;
            double floor = Math.floor(shifted);
            double floorWeight = 1 - (shifted - floor);
            double ceil = Math.ceil(shifted);
            double ceilWeight = 1 - floorWeight;
            assert (floorWeight + ceilWeight == 1);
            return Arrays.asList(new Pair<>((int) floor, floorWeight), new Pair<>((int) ceil, ceilWeight));
        }
    }
private List < Pair < Integer , Double > > integerPixelCoordinatesAndWeights ( double d , int numPixels ) { if ( d <= 0.5 ) return Collections . singletonList ( new Pair < > ( 0 , 1.0 ) ) ; else if ( d >= numPixels - 0.5 ) return Collections . singletonList ( new Pair < > ( numPixels - 1 , 1.0 ) ) ; else { double shifted = d - 0.5 ; double floor = Math . floor ( shifted ) ; double floorWeight = 1 - ( shifted - floor ) ; double ceil = Math . ceil ( shifted ) ; double ceilWeight = 1 - floorWeight ; assert ( floorWeight + ceilWeight == 1 ) ; return Arrays . asList ( new Pair < > ( ( int ) floor , floorWeight ) , new Pair < > ( ( int ) ceil , ceilWeight ) ) ; } }
Operates on one dimension at a time.