public int hexSideInPixels(int availableWidthForMapInPixels,
                               int availableHeightForMapInPixels) {
        int h = availableHeightForMapInPixels;
        int w = availableWidthForMapInPixels;
        int resultBasedOnHeight = (int) Drafter.roundToNearestEvenNumber(h / getMapHeightInHexSides());
        if (resultBasedOnHeight * getMapHeightInHexSides() > h) {
            resultBasedOnHeight = resultBasedOnHeight - 2;
        }
        if (resultBasedOnHeight < 2) {
            resultBasedOnHeight = 2;
        }

        int estimatedMaxWidth = (int) Drafter.roundToNearestEvenNumber(w / getMapWidthInHexesAcrossFlats());
        if (estimatedMaxWidth * getMapWidthInHexesAcrossFlats() > w) {
            estimatedMaxWidth = estimatedMaxWidth - 2;
        }
        if (estimatedMaxWidth < 4) {
            estimatedMaxWidth = 4;
        }

        int resultBasedOnWidth = (int) Drafter.roundToNearestEvenNumber(estimatedMaxWidth / Math.sqrt(3.0));
        int correspondingWidth = (int) Drafter.roundToNearestEvenNumber(resultBasedOnWidth * Math.sqrt(3.0));
        if (correspondingWidth * getMapWidthInHexesAcrossFlats() > w) {
            resultBasedOnWidth = resultBasedOnWidth - 2;
        }
        if (resultBasedOnWidth < 2) {
            resultBasedOnWidth = 2;
        }

        if (resultBasedOnWidth < resultBasedOnHeight) {
            return resultBasedOnWidth;
        }
        return resultBasedOnHeight;
    }