Beispiel #1
0
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            layer.Clear();

            double boxLength    = layer.BoxLength;
            double boxWidth     = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth  = GetPalletWidth(layer);

            int sizeX = (int)Math.Floor(palletLength / boxLength);
            int sizeY = (int)Math.Floor(palletWidth / boxWidth);

            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            double spaceX = sizeX > 1 ? (actualLength - sizeX * boxLength) / (sizeX - 1) : 0.0;
            double spaceY = sizeY > 1 ? (actualWidth - sizeY * boxWidth) / (sizeY - 1) : 0.0;

            for (int i = 0; i < sizeX; ++i)
            {
                for (int j = 0; j < sizeY; ++j)
                {
                    AddPosition(layer
                                , new Vector2D(
                                    offsetX + i * (boxLength + spaceX)
                                    , offsetY + j * (boxWidth + spaceY)
                                    )
                                , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                }
            }
            // set spacing to ZERO i.e. no spacing with column layout
            layer.UpdateMaxSpace(spaceX, Name);
            layer.UpdateMaxSpace(spaceY, Name);
        }
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            layer.Clear();

            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            int sizeX = (int)Math.Floor(palletLength / boxLength);
            int sizeY = (int)Math.Floor(palletWidth / boxWidth);

            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            double spaceX = sizeX > 1 ? (actualLength - sizeX * boxLength) / (sizeX - 1) : 0.0;
            double spaceY = sizeY > 1 ? (actualWidth - sizeY * boxWidth) / (sizeY - 1) : 0.0;

            for (int i = 0; i < sizeX; ++i)
                for (int j = 0; j < sizeY; ++j)
                    AddPosition(layer
                        , new Vector2D(
                            offsetX + i * (boxLength + spaceX)
                            , offsetY + j * (boxWidth + spaceY)
                            )
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
            // set spacing to ZERO i.e. no spacing with column layout
            layer.UpdateMaxSpace(spaceX);
            layer.UpdateMaxSpace(spaceY);
        }
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            layer.Clear();

            double boxLength    = layer.BoxLength;
            double boxWidth     = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth  = GetPalletWidth(layer);

            int maxSizeXLength = 0, maxSizeXWidth = 0, maxSizeYLength = 0, maxSizeYWidth = 0;

            GetSizeXY(boxLength, boxWidth, palletLength, palletWidth
                      , out maxSizeXLength, out maxSizeXWidth, out maxSizeYLength, out maxSizeYWidth);

            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            double spaceX       = maxSizeXLength + maxSizeXWidth > 1 ? (actualLength - (maxSizeXLength * boxLength + maxSizeXWidth * boxWidth)) / (maxSizeXLength + maxSizeXWidth - 1) : 0.0;
            double spaceYLength = maxSizeYLength > 1 ? (actualWidth - maxSizeYLength * boxWidth) / (maxSizeYLength - 1) : 0.0;
            double spaceYWidth  = maxSizeYWidth > 1 ? actualWidth - maxSizeYWidth * boxLength : 0.0;

            for (int i = 0; i < maxSizeXLength / 2; ++i)
            {
                for (int j = 0; j < maxSizeYLength; ++j)
                {
                    AddPosition(
                        layer
                        , new Vector2D(
                            offsetX + i * (boxLength + spaceX)
                            , offsetY + j * (boxWidth + spaceYLength))
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);

                    AddPosition(
                        layer
                        , new Vector2D(
                            palletLength - offsetX - i * (boxLength + spaceX)
                            , palletWidth - offsetY - j * (boxWidth + spaceYLength))
                        , HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Y_N);
                }
            }
            for (int i = 0; i < maxSizeXWidth; ++i)
            {
                for (int j = 0; j < maxSizeYWidth; ++j)
                {
                    AddPosition(
                        layer
                        , new Vector2D(
                            offsetX + maxSizeXLength / 2 * (boxLength + spaceX) + i * (boxWidth + spaceX) + boxWidth
                            , offsetY + j * (boxLength + spaceYWidth))
                        , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                }
            }

            layer.UpdateMaxSpace(spaceX, Name);
            layer.UpdateMaxSpace(spaceYLength, Name);
            layer.UpdateMaxSpace(spaceYWidth, Name);
        }
Beispiel #4
0
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            // initialization
            layer.Clear();

            double boxLength    = layer.BoxLength;
            double boxWidth     = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth  = GetPalletWidth(layer);

            // compute optimal layout by evaluating all spirale configurations
            int sizeX_area1 = 0, sizeY_area1 = 0, sizeX_area2 = 0, sizeY_area2 = 0;

            GetOptimalSizesXY(boxLength, boxWidth, palletLength, palletWidth
                              , out sizeX_area1, out sizeY_area1, out sizeX_area2, out sizeY_area2);

            // compute offsets
            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            // area1
            for (int i = 0; i < sizeX_area1; ++i)
            {
                for (int j = 0; j < sizeY_area1; ++j)
                {
                    AddPosition(layer
                                , new Vector2D(offsetX + i * boxLength, offsetY + j * boxWidth)
                                , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    AddPosition(layer
                                , new Vector2D(palletLength - offsetX - i * boxLength, palletWidth - offsetY - j * boxWidth)
                                , HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Y_N);
                }
            }
            double spaceX_Area1 = actualLength - 2.0 * sizeX_area1 * boxLength;
            double spaceY_Area1 = actualWidth - 2.0 * sizeY_area1 * boxWidth;

            // area2
            for (int i = 0; i < sizeX_area2; ++i)
            {
                for (int j = 0; j < sizeY_area2; ++j)
                {
                    AddPosition(layer
                                , new Vector2D(palletLength - offsetX - i * boxWidth, offsetY + j * boxLength)
                                , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                    AddPosition(layer
                                , new Vector2D(offsetX + i * boxWidth, palletWidth - offsetY - j * boxLength)
                                , HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_X_P);
                }
            }

            double spaceX_Area2 = actualLength - 2.0 * sizeX_area2 * boxWidth;
            double spaceY_Area2 = actualWidth - 2.0 * sizeY_area2 * boxLength;
            double spaceX       = spaceX_Area1 > 0 ? spaceX_Area1 : spaceX_Area2;
            double spaceY       = spaceY_Area1 > 0 ? spaceY_Area1 : spaceY_Area2;

            layer.UpdateMaxSpace(Math.Min(spaceX, spaceY), Name);
        }
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            // initialization
            layer.Clear();

            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            // compute optimal layout by evaluating all spirale configurations
            int sizeX_area1 = 0, sizeY_area1 = 0, sizeX_area2 = 0, sizeY_area2 = 0;
            GetOptimalSizesXY(boxLength, boxWidth, palletLength, palletWidth
                , out sizeX_area1, out sizeY_area1, out sizeX_area2, out sizeY_area2);

            // compute offsets
            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            // area1
            for (int i=0; i<sizeX_area1; ++i)
                for (int j = 0; j<sizeY_area1; ++j)
                {
                    AddPosition(layer
                        , new Vector2D(offsetX + i * boxLength, offsetY + j * boxWidth)
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    AddPosition(layer
                        , new Vector2D(palletLength - offsetX - i * boxLength, palletWidth - offsetY - j * boxWidth)
                        , HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Y_N);
                }
            double spaceX_Area1 = actualLength - 2.0 * sizeX_area1 * boxLength;
            double spaceY_Area1 = actualWidth - 2.0 * sizeY_area1 * boxWidth;

            // area2
            for (int i=0; i<sizeX_area2; ++i)
                for (int j = 0; j<sizeY_area2; ++j)
                {
                    AddPosition(layer
                        , new Vector2D(palletLength - offsetX - i * boxWidth, offsetY + j * boxLength)
                        , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                    AddPosition(layer
                        , new Vector2D(offsetX + i * boxWidth, palletWidth - offsetY - j * boxLength)
                        , HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_X_P);
                }

            double spaceX_Area2 = actualLength - 2.0 * sizeX_area2 * boxWidth;
            double spaceY_Area2 = actualWidth - 2.0 * sizeY_area2 * boxLength;
            double spaceX = spaceX_Area1 > 0 ? spaceX_Area1 : spaceX_Area2;
            double spaceY = spaceY_Area1 > 0 ? spaceY_Area1 : spaceY_Area2;

            layer.UpdateMaxSpace( Math.Min(spaceX, spaceY) );
        }
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            layer.Clear();

            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            int maxSizeXLength = 0, maxSizeXWidth = 0, maxSizeYLength = 0, maxSizeYWidth = 0;
            GetSizeXY(boxLength, boxWidth, palletLength, palletWidth
                , out maxSizeXLength, out maxSizeXWidth, out maxSizeYLength, out maxSizeYWidth);

            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            double spaceX = maxSizeXLength + maxSizeXWidth > 1 ? (actualLength - (maxSizeXLength * boxLength + maxSizeXWidth * boxWidth)) / (maxSizeXLength + maxSizeXWidth - 1) : 0.0;
            double spaceYLength = maxSizeYLength > 1 ? (actualWidth - maxSizeYLength * boxWidth) / (maxSizeYLength - 1) : 0.0;
            double spaceYWidth = maxSizeYWidth > 1 ? (actualWidth - maxSizeYWidth * boxLength) / (maxSizeYWidth - 1) : 0.0;

            for (int i = 0; i < maxSizeXLength/2; ++i)
                for (int j = 0; j < maxSizeYLength; ++j)
                {
                    AddPosition(
                        layer
                        , new Vector2D(
                            offsetX + i * (boxLength + spaceX)
                            , offsetY + j * (boxWidth + spaceYLength))
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);

                    AddPosition(
                        layer
                        , new Vector2D(
                            palletLength - offsetX - i * (boxLength + spaceX)
                            , palletWidth - offsetY - j * (boxWidth + spaceYLength))
                        , HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Y_N);
                }
            for (int i = 0; i < maxSizeXWidth; ++i)
                for (int j = 0; j < maxSizeYWidth; ++j)
                    AddPosition(
                        layer
                        , new Vector2D(
                            offsetX + maxSizeXLength/2 * (boxLength + spaceX) + i * (boxWidth + spaceX) + boxWidth
                            , offsetY + j * (boxLength + spaceYWidth))
                        , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);

            layer.UpdateMaxSpace(spaceX);
            layer.UpdateMaxSpace(spaceYLength);
            layer.UpdateMaxSpace(spaceYWidth);
        }
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            layer.Clear();

            double boxLength    = layer.BoxLength;
            double boxWidth     = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth  = GetPalletWidth(layer);

            int sizeX_area1 = 0, sizeY_area1 = 0, sizeX_area2 = 0, sizeY_area2 = 0, sizeX_area3 = 0, sizeY_area3 = 0;

            GetOptimalSizeArea1(boxLength, boxWidth, palletLength, palletWidth, out sizeX_area1, out sizeY_area1);
            GetSizeXY(boxLength, boxWidth, palletLength, palletWidth, sizeX_area1, sizeY_area1
                      , out sizeX_area2, out sizeY_area2, out sizeX_area3, out sizeY_area3);

            // compute offsets
            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            // compute spaces
            double spaceX_area1 = (actualLength - (boxWidth * sizeX_area1 + boxLength * sizeX_area3)) / (sizeX_area1 + sizeX_area3 > 1 ? (sizeX_area1 + sizeX_area3 - 1) : 1.0);
            double spaceX_area2 = (actualLength - sizeX_area2 * boxLength) / (sizeX_area2 > 1 ?(sizeX_area2 - 1) : 1.0);
            double spaceX_area3 = spaceX_area1;

            double spaceY_area1 = 0.0, spaceY_area2 = 0.0, spaceY_area3 = 0.0;

            if (sizeY_area1 * boxLength > sizeY_area3 * boxWidth)
            {
                spaceY_area1 = (actualWidth - sizeY_area1 * boxLength - sizeY_area2 * boxWidth) / (sizeY_area1 + sizeY_area2 > 1 ?(sizeY_area1 + sizeY_area2 - 1) : 1.0);
                spaceY_area2 = spaceY_area1;
                spaceY_area3 = (sizeY_area1 * (boxLength + spaceY_area1) - sizeY_area3 * boxWidth) / (0 != sizeY_area3 ? sizeY_area3 : 1.0);
            }
            else
            {
                spaceY_area3 = (actualWidth - (sizeY_area2 + sizeY_area3) * boxWidth) / (sizeY_area2 + sizeY_area3 > 1 ? (sizeY_area2 + sizeY_area3 - 1) : 1.0);
                spaceY_area2 = spaceY_area3;
                spaceY_area1 = (sizeY_area3 * (boxWidth + spaceY_area3) - sizeY_area1 * boxLength) / (sizeY_area1 > 0 ? sizeY_area1 : 1.0);
            }
            // area1
            for (int i = 0; i < sizeX_area1; ++i)
            {
                for (int j = 0; j < sizeY_area1; ++j)
                {
                    AddPosition(layer
                                , new Vector2D(
                                    offsetX + boxWidth + i * (boxWidth + spaceX_area1)
                                    , offsetY + j * (boxLength + spaceY_area1))
                                , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                }
            }
            // area2
            for (int i = 0; i < sizeX_area2; ++i)
            {
                for (int j = 0; j < sizeY_area2; ++j)
                {
                    AddPosition(layer
                                , new Vector2D(
                                    offsetX + i * (boxLength + spaceX_area2)
                                    , actualWidth + offsetY - (j + 1) * boxWidth - j * spaceY_area2)
                                , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                }
            }
            // area3
            for (int i = 0; i < sizeX_area3; ++i)
            {
                for (int j = 0; j < sizeY_area3; ++j)
                {
                    AddPosition(layer
                                , new Vector2D(
                                    offsetX + sizeX_area1 * (boxWidth + spaceX_area1) + i * (boxLength + spaceX_area3)
                                    , offsetY + j * (boxWidth + spaceY_area3))
                                , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                }
            }

            layer.UpdateMaxSpace(spaceX_area1, Name);
            layer.UpdateMaxSpace(spaceY_area1, Name);
            layer.UpdateMaxSpace(spaceX_area2, Name);
            layer.UpdateMaxSpace(spaceY_area2, Name);
            layer.UpdateMaxSpace(spaceX_area3, Name);
            layer.UpdateMaxSpace(spaceY_area3, Name);
        }
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            // initialization
            layer.Clear();

            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            // compute optimal layout
            int sizeX_area1 = 0, sizeY_area1 = 0
                , sizeX_area2 = 0, sizeY_area2 = 0
                , sizeX_area3 = 0, sizeY_area3 = 0
                , dir_area3 = 0;

            GetOptimalSizesXY(
            boxLength, boxWidth, palletLength, palletWidth
            , out sizeX_area1, out sizeY_area1
            , out sizeX_area2, out sizeY_area2
            , out sizeX_area3, out sizeY_area3
            , out dir_area3);

            // compute offsets
            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            // area1
            for (int i = 0; i < sizeX_area1; ++i)
                for (int j = 0; j < sizeY_area1; ++j)
                {
                    AddPosition(layer
                        , new Vector2D(offsetX + i * boxLength, offsetY + j * boxWidth)
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    AddPosition(layer
                        , new Vector2D(palletLength - offsetX - i * boxLength, palletWidth - offsetY - j * boxWidth)
                        , HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Y_N);
                }
            double spaceX_area1 = actualLength - 2 * sizeX_area1 * boxLength;
            double spaceY_area1 = actualWidth - 2 * sizeY_area1 * boxWidth;
            // area2
            for (int i = 0; i < sizeX_area2; ++i)
                for (int j = 0; j < sizeY_area2; ++j)
                {
                    AddPosition(layer
                        , new Vector2D(palletLength - offsetX - i * boxWidth, offsetY + j * boxLength)
                        , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                    AddPosition(layer
                        , new Vector2D(offsetX + i * boxWidth, palletWidth - offsetY - j * boxLength)
                        , HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_X_P);
                }
            double spaceX_area2 = actualLength - 2 * sizeX_area2 * boxWidth;
            double spaceY_area2 = actualWidth - 2 * sizeY_area2 * boxLength;
            // area3
            for (int i = 0; i < sizeX_area3; ++i)
                for (int j = 0; j < sizeY_area3; ++j)
                {
                    if (dir_area3 == 0)
                        AddPosition(layer
                        , new Vector2D(
                            offsetX + 0.5 * (actualLength  - sizeX_area3 * boxLength) + i * boxLength
                            , offsetY + 0.5 * (actualWidth - sizeY_area3 * boxWidth) + j * boxWidth
                            )
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    else
                        AddPosition(layer
                            , new Vector2D(
                            offsetX + 0.5 * (actualLength - sizeX_area3 * boxWidth) + (i+1) * boxWidth
                            , offsetY + 0.5 * (actualWidth - sizeY_area3 * boxLength) + j * boxLength
                            )
                            , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                }

            double spaceX_area3 = 0.0, spaceY_area3 = 0.0;
            if (dir_area3 == 0)
            {
                spaceX_area3 = 0.5 * (actualLength - sizeX_area3 * boxLength - 2.0 * (spaceX_area1 > 0 ? sizeX_area1 * boxLength : sizeX_area2 * boxWidth));
                spaceY_area3 = 0.5 * (actualWidth - sizeY_area3 * boxWidth - 2.0 * (spaceY_area1 > 0 ? sizeY_area1 * boxWidth : sizeY_area2 * boxLength));
            }
            else
            {
                spaceX_area3 = 0.5 * (actualLength - sizeX_area3 * boxWidth - 2.0 * (spaceX_area1 > 0 ? sizeX_area1 * boxLength : sizeX_area2 * boxWidth));
                spaceY_area3 = 0.5 * (actualWidth - sizeY_area3 * boxLength - 2.0 * (spaceY_area1 > 0 ? sizeY_area1 * boxWidth : sizeY_area2 * boxLength));
            }
            // set spacing
            layer.UpdateMaxSpace(spaceX_area3);
            layer.UpdateMaxSpace(spaceY_area3);
        }
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            layer.Clear();

            double boxLength    = layer.BoxLength;
            double boxWidth     = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth  = GetPalletWidth(layer);

            int maxSizeXLength = 0, maxSizeXWidth = 0, maxSizeYLength = 0, maxSizeYWidth = 0, iStep = 0;

            GetSizeXY(boxLength, boxWidth, palletLength, palletWidth
                      , out iStep, out maxSizeXLength, out maxSizeXWidth, out maxSizeYLength, out maxSizeYWidth);

            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            for (int i = 0; i < iStep; ++i)
            {
                double spaceX = maxSizeXLength + maxSizeXWidth > 1
                    ? (actualLength - maxSizeXLength * boxLength - maxSizeXWidth * boxWidth) / (maxSizeXLength + maxSizeXWidth - 1)
                    : 0.0;
                double spaceY = maxSizeYLength + maxSizeYWidth > 1
                    ? (actualWidth - maxSizeYWidth * boxWidth - maxSizeYLength * boxLength) / (maxSizeYLength + maxSizeYWidth - 1)
                    : 0.0;

                double xBase = offsetX + i * (boxLength + spaceX);
                double yBase = offsetY + i * (boxWidth + spaceY);
                // first box
                AddPosition(
                    layer
                    , new Vector2D(xBase + boxWidth, yBase)
                    , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);

                // along X
                for (int ix = 0; ix < iStep - 1 - i; ++ix)
                {
                    AddPosition(
                        layer
                        , new Vector2D(
                            xBase + boxWidth + spaceX + ix * (boxLength + spaceX)
                            , yBase)
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                }

                int    maxY      = (int)Math.Floor(actualWidth / boxWidth);
                double ySpaceNew = maxY > 1 ? (actualWidth - boxWidth * maxY) / (maxY - 1) : 0;
                for (int ix = iStep - 1 - i; ix < maxSizeXLength - i && i < iStep - 1; ++ix)
                {
                    AddPosition(
                        layer
                        , new Vector2D(
                            xBase + boxWidth + spaceX + ix * (boxLength + spaceX)
                            , offsetY + i * (boxWidth + ySpaceNew))
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                }
                // along Y
                for (int iy = 0; iy < iStep - 1 - i; ++iy)
                {
                    AddPosition(
                        layer
                        , new Vector2D(
                            xBase
                            , yBase + boxLength + spaceY + iy * (boxWidth + spaceY))
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                }
                int    maxX      = (int)Math.Floor(actualLength / boxLength);
                double xSpaceNew = maxX > 1 ? (actualLength - boxLength * maxX) / (maxX - 1) : 0;
                for (int iy = iStep - 1 - i; iy < maxSizeYWidth - i && i < iStep - 1; ++iy)
                {
                    AddPosition(
                        layer
                        , new Vector2D(
                            offsetX + i * (boxLength + xSpaceNew)
                            , yBase + boxLength + spaceY + iy * (boxWidth + spaceY))
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                }
                // set spacing
                layer.UpdateMaxSpace(spaceX);
                layer.UpdateMaxSpace(spaceY);
                layer.UpdateMaxSpace(Math.Abs(boxLength - boxWidth));
            }
        }
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            layer.Clear();

            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            int sizeX_area1 = 0, sizeY_area1 = 0, sizeX_area2 = 0, sizeY_area2 = 0, sizeX_area3 = 0, sizeY_area3 = 0;
            GetOptimalSizeArea1(boxLength, boxWidth, palletLength, palletWidth, out sizeX_area1, out sizeY_area1);
            GetSizeXY(boxLength, boxWidth, palletLength, palletWidth, sizeX_area1, sizeY_area1
                , out sizeX_area2, out sizeY_area2, out sizeX_area3, out sizeY_area3);

            // compute offsets
            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            // compute spaces
            double spaceX_area1 = (actualLength - (boxWidth * sizeX_area1 + boxLength * sizeX_area3)) / (sizeX_area1 + sizeX_area3 > 1 ? (sizeX_area1 + sizeX_area3 - 1) : 1.0);
            double spaceX_area2 = (actualLength - sizeX_area2 * boxLength) / (sizeX_area2 > 1 ?(sizeX_area2 - 1) : 1.0);
            double spaceX_area3 = spaceX_area1;

            double spaceY_area1 = 0.0, spaceY_area2 = 0.0, spaceY_area3 = 0.0;
            if (sizeY_area1 * boxLength > sizeY_area3 * boxWidth)
            {
                spaceY_area1 =  (actualWidth - sizeY_area1 * boxLength - sizeY_area2 * boxWidth) / (sizeY_area1 + sizeY_area2 > 1 ?(sizeY_area1 + sizeY_area2 - 1) : 1.0);
                spaceY_area2 = spaceY_area1;
                spaceY_area3 =  (sizeY_area1 * (boxLength + spaceY_area1) - sizeY_area3 * boxWidth) / (0 != sizeY_area3 ? sizeY_area3 : 1.0);
            }
            else
            {
                spaceY_area3 =  (actualWidth - (sizeY_area2 + sizeY_area3) * boxWidth) / (sizeY_area2 + sizeY_area3 > 1 ? (sizeY_area2 + sizeY_area3 - 1) : 1.0);
                spaceY_area2 = spaceY_area3;
                spaceY_area1 =  (sizeY_area3 * (boxWidth + spaceY_area3) - sizeY_area1 * boxLength) /(sizeY_area1 > 0 ? sizeY_area1 : 1.0);
            }
            // area1
            for (int i = 0; i < sizeX_area1; ++i)
                for (int j = 0; j < sizeY_area1; ++j)
                    AddPosition(layer
                        , new Vector2D(
                            offsetX + boxWidth + i * (boxWidth + spaceX_area1)
                            , offsetY + j * (boxLength + spaceY_area1))
                        , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
            // area2
            for (int i = 0; i < sizeX_area2; ++i)
                for (int j = 0; j < sizeY_area2; ++j)
                    AddPosition(layer
                        , new Vector2D(
                            offsetX + i * (boxLength + spaceX_area2)
                            , actualWidth + offsetY - (j + 1) * boxWidth - j * spaceY_area2)
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
            // area3
            for (int i = 0; i < sizeX_area3; ++i)
                for (int j = 0; j < sizeY_area3; ++j)
                    AddPosition(layer
                        , new Vector2D(
                            offsetX + sizeX_area1 * (boxWidth + spaceX_area1) + i * (boxLength + spaceX_area3)
                            , offsetY + j * (boxWidth + spaceY_area3))
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);

            layer.UpdateMaxSpace(spaceX_area1);
            layer.UpdateMaxSpace(spaceY_area1);
            layer.UpdateMaxSpace(spaceX_area2);
            layer.UpdateMaxSpace(spaceY_area2);
            layer.UpdateMaxSpace(spaceX_area3);
            layer.UpdateMaxSpace(spaceY_area3);
        }
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            layer.Clear();

            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            int maxSizeXLength = 0, maxSizeXWidth = 0, maxSizeYLength = 0, maxSizeYWidth = 0;
            int fillSizeXLength = 0, fillSizeYLength = 0, fillSizeXWidth = 0, fillSizeYWidth = 0;
            GetSizeXY(boxLength, boxWidth, palletLength, palletWidth
                , out maxSizeXLength, out maxSizeYLength, out maxSizeXWidth, out maxSizeYWidth
                , out fillSizeXLength, out fillSizeYLength, out fillSizeXWidth, out fillSizeYWidth);

            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            double l1 = Math.Max(maxSizeXLength * boxLength, fillSizeXLength * boxWidth);
            double l2 = Math.Max(maxSizeXWidth * boxWidth, fillSizeXWidth * boxLength);
            double remainingSpaceX = actualLength - l1 - l2;
            l1 = l1 + 0.5 * remainingSpaceX;
            l2 = l2 + 0.5 * remainingSpaceX;

            //double spaceX = maxSizeXLength + maxSizeXWidth > 1 ? (actualLength - (l1 + l2)) / (maxSizeXLength + maxSizeXWidth - 1) : 0.0;

            double spaceXLength = (l1 - maxSizeXLength * boxLength) / ((double)maxSizeXLength - 0.5);
            double spaceXWidth = (l2 - maxSizeXWidth * boxWidth) / ((double) maxSizeXWidth - 0.5);
            double spaceYLength = maxSizeYLength > 1 ? (actualWidth - maxSizeYLength * boxWidth - fillSizeYLength * boxLength) / (maxSizeYLength + fillSizeYLength - 1) : 0.0;
            double spaceYWidth = maxSizeYWidth > 1 ? (actualWidth - maxSizeYWidth * boxLength - fillSizeYWidth * boxWidth) / (maxSizeYWidth + fillSizeYWidth - 1) : 0.0;

            if (1 == maxSizeYLength % 2)
            {
                // LENGTH
                for (int i = 0; i < maxSizeXLength; ++i)
                    for (int j = 0; j < maxSizeYLength; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                offsetX + i * (boxLength + spaceXLength)
                                , offsetY + j * (boxWidth + spaceYLength))
                            , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    }
            }
            else
            {
                // LENGTH
                for (int i = 0; i < maxSizeXLength; ++i)
                    for (int j = 0; j < maxSizeYLength / 2; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                offsetX + i * (boxLength + spaceXLength)
                                , offsetY + j * (boxWidth + spaceYLength))
                            , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    }
                for (int i = 0; i < maxSizeXLength; ++i)
                    for (int j = maxSizeYLength / 2; j < maxSizeYLength; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                offsetX + i * (boxLength + spaceXLength)
                                , offsetY + j * (boxWidth + spaceYLength) + (fillSizeYLength > 0 ? (spaceYLength + boxLength) : 0.0))
                            , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    }

                double spaceXFill = fillSizeXLength > 1 ? (l1 - fillSizeXLength * boxWidth) / ((double)fillSizeXLength - 0.5) : 0;
                layer.UpdateMaxSpace(spaceXFill);
                for (int i = 0; i < fillSizeXLength; ++i)
                    for (int j = 0; j < fillSizeYLength; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                offsetX + boxWidth + i * (boxWidth + spaceXFill)
                                , offsetY + (maxSizeYLength / 2) * (boxWidth + spaceYLength) + j * boxLength)
                            , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N
                            );
                    }
            }
            // WIDTH
            if (1 == maxSizeYWidth % 2)
            {
                for (int i = 0; i < maxSizeXWidth; ++i)
                    for (int j = 0; j < maxSizeYWidth; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                offsetX + maxSizeXLength * (boxLength + spaceXLength) + i * (boxWidth + spaceXWidth) + boxWidth
                                , offsetY + j * (boxLength + spaceYWidth))
                            , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                    }
            }
            else
            {
                for (int i = 0; i < maxSizeXWidth; ++i)
                    for (int j = 0; j < maxSizeYWidth / 2; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                /*offsetX + maxSizeXLength * (boxLength + spaceXLength) + i * (boxWidth + spaceXWidth) + boxWidth*/
                                offsetX + actualLength - (i) * (boxWidth + spaceXWidth) /*- boxWidth*/
                                , offsetY + j * (boxLength + spaceYWidth))
                            , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                    }

                for (int i = 0; i < maxSizeXWidth; ++i)
                    for (int j = maxSizeYWidth / 2; j < maxSizeYWidth; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                /*offsetX + maxSizeXLength * (boxLength + spaceX) + i * (boxWidth + spaceX) + boxWidth*/
                                offsetX + actualLength - (i) * (boxWidth + spaceXWidth) /*- boxWidth*/
                                , offsetY + j * (boxLength + spaceYWidth) + (fillSizeYWidth > 0 ? (boxWidth + spaceYWidth) : 0.0))
                            , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                    }

                double spaceXFill = fillSizeXWidth > 1 ? (l2 - fillSizeXWidth * boxLength) / ((double)fillSizeXWidth - 0.5) : 0.0;
                layer.UpdateMaxSpace(spaceXFill);
                for (int i = 0; i < fillSizeXWidth; ++i)
                    for (int j = 0; j < fillSizeYWidth; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                offsetX + actualLength - (i+1) * (boxLength + spaceXFill)
                                /*offsetX + maxSizeXLength * (boxLength + spaceX) + spaceXFill + i * (boxLength + spaceXFill)*/
                                , offsetY + (maxSizeYWidth / 2) * (boxLength + spaceYWidth) + j * boxWidth)
                            , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P
                            );
                    }
            }
            // maximum space
            layer.UpdateMaxSpace(spaceYLength);
            layer.UpdateMaxSpace(spaceYWidth);
        }
Beispiel #12
0
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            layer.Clear();

            double boxLength    = layer.BoxLength;
            double boxWidth     = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth  = GetPalletWidth(layer);

            int maxSizeXLength = 0, maxSizeXWidth = 0, maxSizeYLength = 0, maxSizeYWidth = 0;
            int fillSizeXLength = 0, fillSizeYLength = 0, fillSizeXWidth = 0, fillSizeYWidth = 0;

            GetSizeXY(boxLength, boxWidth, palletLength, palletWidth
                      , out maxSizeXLength, out maxSizeYLength, out maxSizeXWidth, out maxSizeYWidth
                      , out fillSizeXLength, out fillSizeYLength, out fillSizeXWidth, out fillSizeYWidth);

            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            double l1 = Math.Max(maxSizeXLength * boxLength, fillSizeXLength * boxWidth);
            double l2 = Math.Max(maxSizeXWidth * boxWidth, fillSizeXWidth * boxLength);
            double remainingSpaceX = actualLength - l1 - l2;

            l1 = l1 + 0.5 * remainingSpaceX;
            l2 = l2 + 0.5 * remainingSpaceX;

            double spaceXLength = (l1 - maxSizeXLength * boxLength) / ((double)maxSizeXLength - 0.5);
            double spaceXWidth  = (l2 - maxSizeXWidth * boxWidth) / ((double)maxSizeXWidth - 0.5);
            double spaceYLength = maxSizeYLength > 1 ? (actualWidth - maxSizeYLength * boxWidth - fillSizeYLength * boxLength) / (maxSizeYLength + fillSizeYLength - 1) : 0.0;
            double spaceYWidth  = maxSizeYWidth > 1 ? (actualWidth - maxSizeYWidth * boxLength - fillSizeYWidth * boxWidth) / (maxSizeYWidth + fillSizeYWidth - 1) : 0.0;

            if (1 == maxSizeYLength % 2)
            {
                // LENGTH
                for (int i = 0; i < maxSizeXLength; ++i)
                {
                    for (int j = 0; j < maxSizeYLength; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                offsetX + i * (boxLength + spaceXLength)
                                , offsetY + j * (boxWidth + spaceYLength))
                            , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    }
                }
            }
            else
            {
                // LENGTH
                for (int i = 0; i < maxSizeXLength; ++i)
                {
                    for (int j = 0; j < maxSizeYLength / 2; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                offsetX + i * (boxLength + spaceXLength)
                                , offsetY + j * (boxWidth + spaceYLength))
                            , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    }
                }
                for (int i = 0; i < maxSizeXLength; ++i)
                {
                    for (int j = maxSizeYLength / 2; j < maxSizeYLength; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                offsetX + i * (boxLength + spaceXLength)
                                , offsetY + j * (boxWidth + spaceYLength) + (fillSizeYLength > 0 ? (spaceYLength + boxLength) : 0.0))
                            , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    }
                }

                double spaceXFill = fillSizeXLength > 1 ? (l1 - fillSizeXLength * boxWidth) / ((double)fillSizeXLength - 0.5) : 0;
                layer.UpdateMaxSpace(spaceXFill, Name);
                for (int i = 0; i < fillSizeXLength; ++i)
                {
                    for (int j = 0; j < fillSizeYLength; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                offsetX + boxWidth + i * (boxWidth + spaceXFill)
                                , offsetY + (maxSizeYLength / 2) * (boxWidth + spaceYLength) + j * boxLength)
                            , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N
                            );
                    }
                }
            }
            // WIDTH
            if (1 == maxSizeYWidth % 2)
            {
                for (int i = 0; i < maxSizeXWidth; ++i)
                {
                    for (int j = 0; j < maxSizeYWidth; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                offsetX + maxSizeXLength * (boxLength + spaceXLength) + i * (boxWidth + spaceXWidth) + boxWidth
                                , offsetY + j * (boxLength + spaceYWidth))
                            , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                    }
                }
            }
            else
            {
                for (int i = 0; i < maxSizeXWidth; ++i)
                {
                    for (int j = 0; j < maxSizeYWidth / 2; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                /*offsetX + maxSizeXLength * (boxLength + spaceXLength) + i * (boxWidth + spaceXWidth) + boxWidth*/
                                offsetX + actualLength - (i) * (boxWidth + spaceXWidth) /*- boxWidth*/
                                , offsetY + j * (boxLength + spaceYWidth))
                            , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                    }
                }

                for (int i = 0; i < maxSizeXWidth; ++i)
                {
                    for (int j = maxSizeYWidth / 2; j < maxSizeYWidth; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                /*offsetX + maxSizeXLength * (boxLength + spaceX) + i * (boxWidth + spaceX) + boxWidth*/
                                offsetX + actualLength - (i) * (boxWidth + spaceXWidth) /*- boxWidth*/
                                , offsetY + j * (boxLength + spaceYWidth) + (fillSizeYWidth > 0 ? (boxWidth + spaceYWidth) : 0.0))
                            , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                    }
                }

                double spaceXFill = fillSizeXWidth > 1 ? (l2 - fillSizeXWidth * boxLength) / ((double)fillSizeXWidth - 0.5) : 0.0;
                layer.UpdateMaxSpace(spaceXFill, Name);
                for (int i = 0; i < fillSizeXWidth; ++i)
                {
                    for (int j = 0; j < fillSizeYWidth; ++j)
                    {
                        AddPosition(
                            layer
                            , new Vector2D(
                                offsetX + actualLength - (i + 1) * (boxLength + spaceXFill)
                                /*offsetX + maxSizeXLength * (boxLength + spaceX) + spaceXFill + i * (boxLength + spaceXFill)*/
                                , offsetY + (maxSizeYWidth / 2) * (boxLength + spaceYWidth) + j * boxWidth)
                            , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P
                            );
                    }
                }
            }
            // maximum space
            layer.UpdateMaxSpace(spaceYLength, Name);
            layer.UpdateMaxSpace(spaceYWidth, Name);
        }
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            layer.Clear();

            double boxLength = layer.BoxLength;
            double boxWidth = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth = GetPalletWidth(layer);

            int maxSizeXLength = 0, maxSizeXWidth = 0, maxSizeYLength = 0, maxSizeYWidth = 0, iStep = 0;
            GetSizeXY(boxLength, boxWidth, palletLength, palletWidth
                , out iStep, out maxSizeXLength, out maxSizeXWidth, out maxSizeYLength, out maxSizeYWidth);

            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            for (int i = 0; i < iStep; ++i)
            {
                double spaceX = maxSizeXLength + maxSizeXWidth > 1
                    ? (actualLength - maxSizeXLength * boxLength - maxSizeXWidth * boxWidth) / (maxSizeXLength + maxSizeXWidth - 1)
                    : 0.0;
                double spaceY = maxSizeYLength + maxSizeYWidth > 1
                    ? (actualWidth - maxSizeYWidth * boxWidth - maxSizeYLength * boxLength) / (maxSizeYLength + maxSizeYWidth - 1)
                    : 0.0;

                double xBase = offsetX + i * (boxLength + spaceX);
                double yBase = offsetY + i * (boxWidth + spaceY);
                // first box
                AddPosition(
                    layer
                    , new Vector2D(xBase + boxWidth, yBase)
                    , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);

                // along X
                for (int ix = 0; ix < iStep - 1 - i; ++ix)
                    AddPosition(
                        layer
                        , new Vector2D(
                        xBase + boxWidth + spaceX + ix * (boxLength + spaceX)
                        , yBase)
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);

                int maxY = (int)Math.Floor(actualWidth / boxWidth);
                double ySpaceNew = maxY > 1 ? (actualWidth - boxWidth * maxY) / (maxY - 1) : 0;
                for (int ix = iStep - 1 - i; ix < maxSizeXLength - i && i < iStep - 1; ++ix)
                    AddPosition(
                        layer
                        , new Vector2D(
                        xBase + boxWidth + spaceX + ix * (boxLength + spaceX)
                        , offsetY + i * (boxWidth + ySpaceNew))
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                // along Y
                for (int iy = 0; iy < iStep - 1 - i; ++iy)
                    AddPosition(
                        layer
                        , new Vector2D(
                        xBase
                        , yBase + boxLength + spaceY + iy * (boxWidth + spaceY))
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                int maxX = (int)Math.Floor(actualLength / boxLength);
                double xSpaceNew = maxX > 1 ? (actualLength - boxLength * maxX) / (maxX - 1) : 0;
                for (int iy = iStep - 1 - i; iy < maxSizeYWidth - i && i < iStep - 1; ++iy)
                {
                    AddPosition(
                        layer
                        , new Vector2D(
                        offsetX + i * (boxLength + xSpaceNew)
                        , yBase + boxLength + spaceY + iy * (boxWidth + spaceY))
                        , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                }
                // set spacing
                layer.UpdateMaxSpace(spaceX);
                layer.UpdateMaxSpace(spaceY);
                layer.UpdateMaxSpace(Math.Abs(boxLength - boxWidth));
            }
        }
        public override void GenerateLayer(Layer2D layer, double actualLength, double actualWidth)
        {
            // initialization
            layer.Clear();

            double boxLength    = layer.BoxLength;
            double boxWidth     = layer.BoxWidth;
            double palletLength = GetPalletLength(layer);
            double palletWidth  = GetPalletWidth(layer);

            // compute optimal layout
            int sizeX_area1 = 0, sizeY_area1 = 0
            , sizeX_area2 = 0, sizeY_area2 = 0
            , sizeX_area3 = 0, sizeY_area3 = 0
            , dir_area3 = 0;

            GetOptimalSizesXY(
                boxLength, boxWidth, palletLength, palletWidth
                , out sizeX_area1, out sizeY_area1
                , out sizeX_area2, out sizeY_area2
                , out sizeX_area3, out sizeY_area3
                , out dir_area3);

            // compute offsets
            double offsetX = 0.5 * (palletLength - actualLength);
            double offsetY = 0.5 * (palletWidth - actualWidth);

            // area1
            for (int i = 0; i < sizeX_area1; ++i)
            {
                for (int j = 0; j < sizeY_area1; ++j)
                {
                    AddPosition(layer
                                , new Vector2D(offsetX + i * boxLength, offsetY + j * boxWidth)
                                , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    AddPosition(layer
                                , new Vector2D(palletLength - offsetX - i * boxLength, palletWidth - offsetY - j * boxWidth)
                                , HalfAxis.HAxis.AXIS_X_N, HalfAxis.HAxis.AXIS_Y_N);
                }
            }
            double spaceX_area1 = actualLength - 2 * sizeX_area1 * boxLength;
            double spaceY_area1 = actualWidth - 2 * sizeY_area1 * boxWidth;

            // area2
            for (int i = 0; i < sizeX_area2; ++i)
            {
                for (int j = 0; j < sizeY_area2; ++j)
                {
                    AddPosition(layer
                                , new Vector2D(palletLength - offsetX - i * boxWidth, offsetY + j * boxLength)
                                , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                    AddPosition(layer
                                , new Vector2D(offsetX + i * boxWidth, palletWidth - offsetY - j * boxLength)
                                , HalfAxis.HAxis.AXIS_Y_N, HalfAxis.HAxis.AXIS_X_P);
                }
            }
            double spaceX_area2 = actualLength - 2 * sizeX_area2 * boxWidth;
            double spaceY_area2 = actualWidth - 2 * sizeY_area2 * boxLength;

            // area3
            for (int i = 0; i < sizeX_area3; ++i)
            {
                for (int j = 0; j < sizeY_area3; ++j)
                {
                    if (dir_area3 == 0)
                    {
                        AddPosition(layer
                                    , new Vector2D(
                                        offsetX + 0.5 * (actualLength - sizeX_area3 * boxLength) + i * boxLength
                                        , offsetY + 0.5 * (actualWidth - sizeY_area3 * boxWidth) + j * boxWidth
                                        )
                                    , HalfAxis.HAxis.AXIS_X_P, HalfAxis.HAxis.AXIS_Y_P);
                    }
                    else
                    {
                        AddPosition(layer
                                    , new Vector2D(
                                        offsetX + 0.5 * (actualLength - sizeX_area3 * boxWidth) + (i + 1) * boxWidth
                                        , offsetY + 0.5 * (actualWidth - sizeY_area3 * boxLength) + j * boxLength
                                        )
                                    , HalfAxis.HAxis.AXIS_Y_P, HalfAxis.HAxis.AXIS_X_N);
                    }
                }
            }

            double spaceX_area3 = 0.0, spaceY_area3 = 0.0;

            if (dir_area3 == 0)
            {
                spaceX_area3 = 0.5 * (actualLength - sizeX_area3 * boxLength - 2.0 * (spaceX_area1 > 0 ? sizeX_area1 * boxLength : sizeX_area2 * boxWidth));
                spaceY_area3 = 0.5 * (actualWidth - sizeY_area3 * boxWidth - 2.0 * (spaceY_area1 > 0 ? sizeY_area1 * boxWidth : sizeY_area2 * boxLength));
            }
            else
            {
                spaceX_area3 = 0.5 * (actualLength - sizeX_area3 * boxWidth - 2.0 * (spaceX_area1 > 0 ? sizeX_area1 * boxLength : sizeX_area2 * boxWidth));
                spaceY_area3 = 0.5 * (actualWidth - sizeY_area3 * boxLength - 2.0 * (spaceY_area1 > 0 ? sizeY_area1 * boxWidth : sizeY_area2 * boxLength));
            }
            // set spacing
            layer.UpdateMaxSpace(spaceX_area3);
            layer.UpdateMaxSpace(spaceY_area3);
        }