private final ZSamplePoint<TZ> closeSample(int x, int y) {
   ZSamplePoint<TZ> A = sampleGrid.getOrCreate(x, y);
   A.setZ(
       metric.closeSample(
           A.up() != null ? A.up().getZ() : null,
           A.down() != null ? A.down().getZ() : null,
           A.right() != null ? A.right().getZ() : null,
           A.left() != null ? A.left().getZ() : null));
   return A;
 }
 public final void addSamplingPoint(Coordinate C0, double z) {
   if (closed) throw new IllegalStateException("Can't add a sample after closing.");
   int[] xy = sampleGrid.getLowerLeftIndex(C0);
   int x = xy[0];
   int y = xy[1];
   @SuppressWarnings("unchecked")
   ZSamplePoint<TZ>[] ABCD = new ZSamplePoint[4];
   ABCD[0] = sampleGrid.getOrCreate(x, y);
   ABCD[1] = sampleGrid.getOrCreate(x + 1, y);
   ABCD[2] = sampleGrid.getOrCreate(x, y + 1);
   ABCD[3] = sampleGrid.getOrCreate(x + 1, y + 1);
   for (ZSamplePoint<TZ> P : ABCD) {
     Coordinate C = sampleGrid.getCoordinates(P);
     P.setZ(metric.cumulateSample(C0, C, z, P.getZ()));
   }
 }