class KDTree {

    public double[] estimateL2DistanceSquared(Datum queryDatum) {
        RealVector vector = queryDatum.metrics();
        double[] estimates = new double[2];
        for (int i=0; i<k; i++) {
            double deltaLo = vector.getEntry(i) - this.boundaries[i][0];
            double deltaHi = this.boundaries[i][1] - vector.getEntry(i);
            double sqDeltaLo = deltaLo * deltaLo;
            double sqDeltaHi = deltaHi * deltaHi;

            // point is outside
            if (deltaLo < 0 || deltaHi < 0) {
                // Add the bigger distance to the longer estimate;
                if (sqDeltaHi < sqDeltaLo) {
                    estimates[0] += sqDeltaHi;
                    estimates[1] += sqDeltaLo;
                } else {
                    estimates[0] += sqDeltaLo;
                    estimates[1] += sqDeltaHi;
                }
            } else {
                // Point is inside so only add to max distance.
                // The point is inside the tree boundaries.
                estimates[1] += Math.max(sqDeltaHi, sqDeltaLo);
            }
        }
        return estimates;
    }

    public  KDTree(List<Datum> data, int leafCapacity);

}