src/main/java/dev/rsoliveira/tools/binpacking/simulation/PalletPackingSimulation.java
/**
     * Finds the most proper boxes by looking at the available orientations, empty space given, adjacent boxes
     * and container limits.
     *
     * @param state            the packing state.
     * @param maxGapX          the container x-dimension.
     * @param currentGapZ      the remaining z-dimension gap.
     * @param maxGapZ          the container z-dimension.
     */
Finds the most proper boxes by looking at the available orientations, empty space given, adjacent boxes
and container limits.

@param state            the packing state.
@param maxGapX          the container x-dimension.
@param currentGapZ      the remaining z-dimension gap.
@param maxGapZ          the container z-dimension.
Finds the most proper boxes by looking at the available orientations empty space given adjacent boxes and container limits . @param state the packing state . @param maxGapX the container x - dimension . @param currentGapZ the remaining z - dimension gap . @param maxGapZ the container z - dimension .
private void findBox(PalletPackingState state, long maxGapX, long currentGapZ, long maxGapZ) {
        int MAX_LENGTH = 1048576;
        state.setBoxFittingX(MAX_LENGTH);
        state.setBoxFittingY(MAX_LENGTH);
        state.setBoxFittingZ(MAX_LENGTH);
        state.setBoxNotFittingX(MAX_LENGTH);
        state.setBoxNotFittingY(MAX_LENGTH);
        state.setBotNotFittingZ(MAX_LENGTH);
        state.setBoxFittingIndex(-1);
        state.setBoxNotFittingIndex(-1);
        for (int y = 0; y < state.getItemsToPack().length; y += state.getItemsToPack()[y].getQuantity()) {
            int index;
            for (index = y; index < (index + state.getItemsToPack()[y].getQuantity()) - 1; index++) {
                if (index == state.getItemsToPack().length) return;
                if (!state.getItemsToPack()[index].isPacked()) {
                    break;
                }
            }
            if (state.getItemsToPack()[index].isPacked()) {
                continue;
            }
            int max;
            if (state.getItemsToPack()[index].isCubic()) {
                max = 1;
            } else {
                switch (state.getItemsToPack()[index].getRotation()) {
                    case FULL: max = 6; break;
                    case HORIZONTAL: max = 2; break;
                    case NONE:
                    default: max = 1; break;
                }
            }
            for (int i = 1; i <= max; i++) {
                analyzeBox(state, index, maxGapX, currentGapZ, maxGapZ, state.getItemsToPack()[index].atOrientation(i));
            }
        }
    }
private void findBox ( PalletPackingState state , long maxGapX , long currentGapZ , long maxGapZ ) { int MAX_LENGTH = 1048576 ; state . setBoxFittingX ( MAX_LENGTH ) ; state . setBoxFittingY ( MAX_LENGTH ) ; state . setBoxFittingZ ( MAX_LENGTH ) ; state . setBoxNotFittingX ( MAX_LENGTH ) ; state . setBoxNotFittingY ( MAX_LENGTH ) ; state . setBotNotFittingZ ( MAX_LENGTH ) ; state . setBoxFittingIndex ( - 1 ) ; state . setBoxNotFittingIndex ( - 1 ) ; for ( int y = 0 ; y < state . getItemsToPack ( ) . length ; y += state . getItemsToPack ( ) [ y ] . getQuantity ( ) ) { int index ; for ( index = y ; index < ( index + state . getItemsToPack ( ) [ y ] . getQuantity ( ) ) - 1 ; index ++ ) { if ( index == state . getItemsToPack ( ) . length ) return ; if ( ! state . getItemsToPack ( ) [ index ] . isPacked ( ) ) { break ; } } if ( state . getItemsToPack ( ) [ index ] . isPacked ( ) ) { continue ; } int max ; if ( state . getItemsToPack ( ) [ index ] . isCubic ( ) ) { max = 1 ; } else { switch ( state . getItemsToPack ( ) [ index ] . getRotation ( ) ) { case FULL : max = 6 ; break ; case HORIZONTAL : max = 2 ; break ; case NONE : default : max = 1 ; break ; } } for ( int i = 1 ; i <= max ; i ++ ) { analyzeBox ( state , index , maxGapX , currentGapZ , maxGapZ , state . getItemsToPack ( ) [ index ] . atOrientation ( i ) ) ; } } }
Finds the most proper boxes by looking at the available orientations, empty space given, adjacent boxes
 and container limits.
Finds the most proper boxes by looking at the available orientations empty space given adjacent boxes and container limits .