1
z8018
2025-04-16 1f361850d35ba47225951efbc49d592eea685cf8
ÏîÄ¿´úÂë/WCS/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/PlaceBlockService.cs
@@ -3,6 +3,7 @@
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using WIDESEAWCS_DTO.PlacedBlockDTO;
using WIDESEAWCS_IBasicInfoService;
namespace WIDESEAWCS_BasicInfoService
@@ -25,8 +26,8 @@
        public PlaceBlockService(ContainerSize containerSize, List<PlacedBlock>? placedBlocks = null)
        {
            containerSize.Length = containerSize.Length + 2 * SPACING;
            containerSize.Width = containerSize.Width + 2 * SPACING;
            containerSize.Length = containerSize.Length;
            containerSize.Width = containerSize.Width;
            ContainerSize = containerSize;
            if (placedBlocks == null || placedBlocks.Count == 0)
            {
@@ -38,7 +39,7 @@
            }
            containerFloor = new PlacedBlock(new Point3D(SPACING, SPACING, 0), ContainerSize.Length - 2 * SPACING, ContainerSize.Width - 2 * SPACING, 0);
            containerFloor = new PlacedBlock(new Point3D(0, 0, 0), ContainerSize.Length, ContainerSize.Width, 0);
        }
        /// <summary>
@@ -136,11 +137,6 @@
                    xEnd = Math.Min(xEnd, ContainerSize.Length - l - SPACING);
                    yEnd = Math.Min(yEnd, ContainerSize.Width - w - SPACING);
                    // éªŒè¯æ”¯æ’‘面积
                    //int supportArea = support.Length * support.Width;
                    //int requiredSupportArea = (int)(l * w * 0.7); // æ”¯æ’‘面积 >= è¢«æ”¯æ’‘面面积的70%
                    //if (supportArea < requiredSupportArea) continue;
                    if (xStart > xEnd || yStart > yEnd) continue;
                    // ä¼˜åŒ–搜索:优先角落位置
@@ -182,38 +178,6 @@
            }
            return blocks;
            //// èŽ·å–æ‰€æœ‰åœ¨ baseZ é«˜åº¦çš„æ”¯æ’‘块
            //var blocks = PlacedBlocks
            //    .Where(b => b.Position.Z + b.Height == baseZ)
            //    .ToList();
            //// å½“ baseZ=0 æ—¶æ·»åŠ å®¹å™¨åº•éƒ¨æ”¯æ’‘
            //if (baseZ == 0 && !blocks.Any())
            //{
            //    return new List<PlacedBlock> { containerFloor };
            //}
            //// è®¡ç®—整体平面
            //if (blocks.Any())
            //{
            //    int minX = blocks.Min(b => b.Position.X);
            //    int minY = blocks.Min(b => b.Position.Y);
            //    int maxX = blocks.Max(b => b.Position.X + b.Length);
            //    int maxY = blocks.Max(b => b.Position.Y + b.Width);
            //    var overallSupport = new PlacedBlock(
            //        new Point3D(minX, minY, baseZ),
            //        maxX - minX,
            //        maxY - minY,
            //        0
            //    );
            //    return new List<PlacedBlock> { overallSupport };
            //}
            //return blocks;
        }
        /// <summary>
@@ -252,75 +216,6 @@
                return xOverlap && yOverlap && zOverlap;
            });
        }
    }
    /// <summary>
    /// ä¸‰ç»´åæ ‡ç»“构体
    /// è¡¨ç¤ºè´§ç‰©æ”¾ç½®ä½ç½®çš„左下前角坐标(X,Y,Z)
    /// åæ ‡ç³»è¯´æ˜Žï¼š
    /// - X轴:沿容器长度方向
    /// - Y轴:沿容器宽度方向
    /// - Z轴:垂直方向(高度)
    /// </summary>
    public struct Point3D
    {
        /// <summary>X轴坐标(毫米)</summary>
        public int X { get; }
        /// <summary>Y轴坐标(毫米)</summary>
        public int Y { get; }
        /// <summary>Z轴坐标(毫米)</summary>
        public int Z { get; }
        public Point3D(int x, int y, int z)
        {
            X = x;
            Y = y;
            Z = z;
        }
    }
    /// <summary>
    /// å·²æ”¾ç½®è´§ç‰©ä¿¡æ¯ç±»
    /// è®°å½•每个货物的位置和尺寸信息
    /// åæ ‡ç³»è¯´æ˜Žï¼šä½ç½®ç‚¹ä¸ºè´§ç‰©çš„左下前角坐标
    /// </summary>
    public class PlacedBlock
    {
        /// <summary>货物左下前角坐标</summary>
        public Point3D Position { get; }
        /// <summary>沿X轴方向长度(毫米)</summary>
        public int Length { get; }
        /// <summary>沿Y轴方向宽度(毫米)</summary>
        public int Width { get; }
        /// <summary>沿Z轴方向高度(毫米)</summary>
        public int Height { get; }
        public PlacedBlock(Point3D position, int length, int width, int height)
        {
            Position = position;
            Length = length;
            Width = width;
            Height = height;
        }
    }
    public struct ContainerSize
    {
        public int Length { get; set; }
        public int Width { get; set; }
        public int Height { get; set; }
        public ContainerSize(int length, int width, int height)
        {
            Length = length;
            Width = width;
            Height = height;
        }
    }
}