private void split(Box b)
    {
        byte dim = b.dominantDimensionNum();
        ArrayList<ValFreqPair> values = new ArrayList<>();

        int total = 0;
        for (Entry<MultiColor, Integer> e : freqTable.entrySet())
        {
            MultiColor c = e.getKey();
            if (b.inside(c))
                if (c.data[dim] != -1)
                {
                    values.add(new ValFreqPair(c.data[dim], e.getValue()));
                    total += e.getValue();
                }
        }

        Collections.sort(values);

        if (values.isEmpty())
            throw new RuntimeException("WTF?!");

        int m = median(values, total);
        if (m == values.get(0).b)
            m++;

        Box nb = new Box(b);
        nb.setDimMax(dim, (byte) (m - 1));
        b.setDimMin(dim, m);

        boxes.add(nb);

        b.shrink();
        nb.shrink();
    }