keremdemirer / 3dbinpackingjs

javascript conversion of https://github.com/wknechtel/3d-bin-pack/
83 stars 26 forks source link

Forcing items to stay upright. #9

Closed luenib closed 11 months ago

luenib commented 11 months ago

What should I do to force items to be packed upright (no flip)?

It seems to me that the key is in the functions listCanditLayers and findLayer, but I can't see how.

luenib commented 11 months ago

Yes, the solution involves the functions listCanditLayers and findLayer.

Precondition: Each item must be marked as isflip=true or isflip=false.

Inside the functions listCanditLayers, right before we "get each dimension of each box, one at a time" [1] we check if the item being evaluated isflip value is true. If so, we only run EXDIM=BOXLIST[X].DIM1. If not we run the original 3-cycles for-loop. Something like this:

FUNCTION LISTCANDITLAYERS();

LAYERLISTLEN=0;
For X=1 to TBN {
  CYCLES=1;
  If BOXLIST[X].ISFLIP do {
    CYCLES=3;
  }

  For Y=1 to CYCLES {
    If CYCLES=1 do {
      EXDIM=BOXLIST[X].DIM1;
      DIMEN2=BOXLIST[X].DIM2;
      DIMEN3=BOXLIST[X].DIM3;
    }
    ELSE {
          If Y=1 do { ... }
      If Y=2 do { ... }
      If Y=3 do { ... } 
    }
    If any of the dimensions ...
    ...
  }
}

The same solution must be applied inside the function findlayer.

[1] taken from the original thesis here https://scholar.afit.edu/etd/4563/