src/main/java/dev/rsoliveira/tools/binpacking/simulation/PalletPackingSimulation.java
/**
     * After finding each box, evaluate the candidate boxes and the current layer.
     * Verifies these rules:<br>
     * - if a box fitting in the current layer thickness has been found, keep its index and orientation for packing.<br>
     * - if a box with a y-dimension greater than the current layer thickness has been found and the edge of the current
     * layer is evenedLayer, reserve the box for another layer.<br>
     * - if there is no gap in the edge of the current layer, the packing of this layer is done.<br>
     * - if there is not fitting box to the current layer gap, skip this gap and even it by arranging the already packed items.
     */
After finding each box, evaluate the candidate boxes and the current layer.
After finding each box evaluate the candidate boxes and the current layer .
private void checkFound(PalletPackingState state, ScrapPad smallestZ) {
        state.setEvenedLayer(false);
        if (state.getBoxFittingIndex() > -1) {
            state.setCheckedBoxIndex(state.getBoxFittingIndex());
            state.setCheckedBoxX(state.getBoxX());
            state.setCheckedBoxY(state.getBoxY());
            state.setCheckedBoxZ(state.getBoxZ());
        } else {
            if ((state.getBoxNotFittingIndex() > -1) &&
                (state.getLayerInLayer() != 0 || smallestZ.isSituation().equals(ScrapPad.Situation.EMPTY))) {
                if (state.getLayerInLayer() == 0) {
                    state.setPreLayer(state.getLayerThickness());
                    state.setLayerInLayerZ(smallestZ.getGapZ());
                }
                state.setCheckedBoxIndex(state.getBoxNotFittingIndex());
                state.setCheckedBoxX(state.getbBoxX());
                state.setCheckedBoxY(state.getbBoxY());
                state.setCheckedBoxZ(state.getbBoxZ());
                state.setLayerInLayer(state.getLayerInLayer() + state.getbBoxY() - state.getLayerThickness());
                state.setLayerThickness(state.getbBoxY());
            } else {
                state.setEvenedLayer(true);
                switch (smallestZ.isSituation()) {
                    case EMPTY:  {
                        state.setEvenedLayer(false);
                        state.setLayerDone(true);
                        break;
                    }
                    case ONLY_RIGHT_BOX: {
                        smallestZ.updateGaps(smallestZ.getNext().getGapX(), smallestZ.getNext().getGapZ());
                        smallestZ.setNext(smallestZ.getNext().getNext());
                        if (smallestZ.getNext() != null) {
                            smallestZ.getNext().setPrevious(smallestZ);
                        }
                        break;
                    }
                    case ONLY_LEFT_BOX: {
                        smallestZ.getPrevious().setNext(null);
                        smallestZ.getPrevious().setGapX(smallestZ.getGapX());
                        break;
                    }
                    case EQUAL_SIDES: {
                        smallestZ.getPrevious().setNext(smallestZ.getNext().getNext());
                        if (smallestZ.getNext().getNext() != null) {
                            smallestZ.getNext().getNext().setPrevious(smallestZ.getPrevious());
                        }
                        smallestZ.getPrevious().setGapX(smallestZ.getNext().getGapX());
                        break;
                    }
                    case DIFFERENT_SIDES:
                    default: {
                        smallestZ.getPrevious().setNext(smallestZ.getNext());
                        smallestZ.getNext().setPrevious(smallestZ.getPrevious());
                        if (smallestZ.getPrevious().getGapZ() < smallestZ.getNext().getGapZ()) {
                            smallestZ.getPrevious().setGapX(smallestZ.getGapX());
                        }
                        break;
                    }
                }
            }
        }
    }
private void checkFound ( PalletPackingState state , ScrapPad smallestZ ) { state . setEvenedLayer ( false ) ; if ( state . getBoxFittingIndex ( ) > - 1 ) { state . setCheckedBoxIndex ( state . getBoxFittingIndex ( ) ) ; state . setCheckedBoxX ( state . getBoxX ( ) ) ; state . setCheckedBoxY ( state . getBoxY ( ) ) ; state . setCheckedBoxZ ( state . getBoxZ ( ) ) ; } else { if ( ( state . getBoxNotFittingIndex ( ) > - 1 ) && ( state . getLayerInLayer ( ) != 0 || smallestZ . isSituation ( ) . equals ( ScrapPad . Situation . EMPTY ) ) ) { if ( state . getLayerInLayer ( ) == 0 ) { state . setPreLayer ( state . getLayerThickness ( ) ) ; state . setLayerInLayerZ ( smallestZ . getGapZ ( ) ) ; } state . setCheckedBoxIndex ( state . getBoxNotFittingIndex ( ) ) ; state . setCheckedBoxX ( state . getbBoxX ( ) ) ; state . setCheckedBoxY ( state . getbBoxY ( ) ) ; state . setCheckedBoxZ ( state . getbBoxZ ( ) ) ; state . setLayerInLayer ( state . getLayerInLayer ( ) + state . getbBoxY ( ) - state . getLayerThickness ( ) ) ; state . setLayerThickness ( state . getbBoxY ( ) ) ; } else { state . setEvenedLayer ( true ) ; switch ( smallestZ . isSituation ( ) ) { case EMPTY : { state . setEvenedLayer ( false ) ; state . setLayerDone ( true ) ; break ; } case ONLY_RIGHT_BOX : { smallestZ . updateGaps ( smallestZ . getNext ( ) . getGapX ( ) , smallestZ . getNext ( ) . getGapZ ( ) ) ; smallestZ . setNext ( smallestZ . getNext ( ) . getNext ( ) ) ; if ( smallestZ . getNext ( ) != null ) { smallestZ . getNext ( ) . setPrevious ( smallestZ ) ; } break ; } case ONLY_LEFT_BOX : { smallestZ . getPrevious ( ) . setNext ( null ) ; smallestZ . getPrevious ( ) . setGapX ( smallestZ . getGapX ( ) ) ; break ; } case EQUAL_SIDES : { smallestZ . getPrevious ( ) . setNext ( smallestZ . getNext ( ) . getNext ( ) ) ; if ( smallestZ . getNext ( ) . getNext ( ) != null ) { smallestZ . getNext ( ) . getNext ( ) . setPrevious ( smallestZ . getPrevious ( ) ) ; } smallestZ . getPrevious ( ) . setGapX ( smallestZ . getNext ( ) . getGapX ( ) ) ; break ; } case DIFFERENT_SIDES : default : { smallestZ . getPrevious ( ) . setNext ( smallestZ . getNext ( ) ) ; smallestZ . getNext ( ) . setPrevious ( smallestZ . getPrevious ( ) ) ; if ( smallestZ . getPrevious ( ) . getGapZ ( ) < smallestZ . getNext ( ) . getGapZ ( ) ) { smallestZ . getPrevious ( ) . setGapX ( smallestZ . getGapX ( ) ) ; } break ; } } } } }
After finding each box, evaluate the candidate boxes and the current layer.
After finding each box evaluate the candidate boxes and the current layer .