From e46aa927d231af83724683c7286d9db503e24cf7 Mon Sep 17 00:00:00 2001
From: z8018 <1282578289@qq.com>
Date: 星期二, 10 六月 2025 11:46:20 +0800
Subject: [PATCH] 1

---
 项目代码/WCS/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/PlaceBlockService.cs |  352 +++++++++++++++++++++++++++++++---------------------------
 1 files changed, 189 insertions(+), 163 deletions(-)

diff --git "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/PlaceBlockService.cs" "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/PlaceBlockService.cs"
index a1ae45c..d214f45 100644
--- "a/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/PlaceBlockService.cs"
+++ "b/\351\241\271\347\233\256\344\273\243\347\240\201/WCS/WIDESEAWCS_Server/WIDESEAWCS_BasicInfoService/PlaceBlockService.cs"
@@ -11,10 +11,32 @@
 
 namespace WIDESEAWCS_BasicInfoService
 {
+    /// <summary>
+    /// 璐х墿鏀剧疆鏈嶅姟锛屾彁渚涢泦瑁呯鍐呰揣鐗╂憜鏀句綅缃绠楀姛鑳�
+    /// </summary>
+    /// <remarks>
+    /// 涓昏鍔熻兘鍖呮嫭锛� <br/>
+    /// 1. 鏍规嵁璐х墿灏哄鑷姩璁$畻鏈�浼樻憜鏀句綅缃� <br/>
+    /// 2. 鏀寔妯悜/绾靛悜涓ょ鎽嗘斁鏂瑰紡 <br/>
+    /// 3. 鑰冭檻鍚哥洏灏哄銆佸鍣ㄨ竟鐣岀瓑鐗╃悊闄愬埗 <br/>
+    /// 4. 鎻愪緵浠诲姟浣嶇疆鍧愭爣杞崲鍔熻兘 <br/>
+    ///  <br/>
+    /// 鏍稿績鍙傛暟锛� <br/>
+    /// - SPACING: 璐х墿闂存渶灏忛棿璺� <br/>
+    /// - MaxRotateLength: 鏈�澶ф棆杞暱搴﹂檺鍒� <br/>
+    /// - MaxY/MinY: Y杞村潗鏍囬檺鍒� <br/>
+    /// - SuctionLength/Width: 鍚哥洏灏哄鍙傛暟
+    /// </remarks>
     public class PlaceBlockService
     {
+        /// <summary>
+        /// 鑾峰彇閰嶇疆鏂囦欢涓�"Spacing"閿搴旂殑鏁存暟鍊硷紝琛ㄧず闂磋窛鍊�
+        /// </summary>
         public static int SPACING = AppSettings.GetValue("Spacing").ObjToInt();
 
+        /// <summary>
+        /// 鑾峰彇鎴栬缃渶澶ф棆杞暱搴﹂厤缃��
+        /// </summary>
         public static int MaxRotateLength = AppSettings.GetValue("MaxRotateLength").ObjToInt();
 
         /// <summary>
@@ -26,6 +48,11 @@
         /// 鏈�灏忔í鍚慪鍧愭爣闄愬埗锛堟绫筹級
         /// </summary>
         public static int MinY = AppSettings.GetValue("MinY").ObjToInt();
+
+        /// <summary>
+        /// 鏃嬭浆鎶撳彇Y杞村亸绉婚噺锛堟绫筹級
+        /// </summary>
+        public static int RotateYOffset = AppSettings.GetValue("RotateYOffset").ObjToInt();
 
         /// <summary>
         /// 鍚哥洏妯悜闀垮害
@@ -57,8 +84,21 @@
         /// </summary>
         public List<PlacedBlock> PlacedBlocks { get; private set; }
 
+        /// <summary>
+        /// 瀹瑰櫒鍦版澘鐨勬斁缃潡瀹炰緥
+        /// </summary>
         private readonly PlacedBlock containerFloor;
 
+        /// <summary>
+        /// 鍒濆鍖栨斁缃尯鍧楁湇鍔�
+        /// </summary>
+        /// <param name="containerSize">瀹瑰櫒灏哄</param>
+        /// <param name="placedBlocks">宸叉斁缃尯鍧楀垪琛紝鍙�夊弬鏁�</param>
+        /// <remarks>
+        /// 鏋勯�犲嚱鏁颁細鍒濆鍖栧鍣ㄥ昂瀵稿拰宸叉斁缃尯鍧楀垪琛ㄣ��
+        /// 濡傛灉鏈彁渚沺lacedBlocks鎴栧垪琛ㄤ负绌猴紝灏嗗垱寤烘柊鐨勭┖鍒楄〃銆�
+        /// 鍚屾椂浼氬垱寤鸿〃绀哄鍣ㄥ簳閮ㄧ殑PlacedBlock瀵硅薄銆�
+        /// </remarks>
         public PlaceBlockService(ContainerSize containerSize, List<PlacedBlock>? placedBlocks = null)
         {
             containerSize.Length = containerSize.Length;
@@ -72,21 +112,22 @@
             {
                 PlacedBlocks = placedBlocks;
             }
+            containerFloor = new PlacedBlock(new Point3D(0, 0, 0), ContainerSize.Length, ContainerSize.Width, 0);
 
-
-            containerFloor = new PlacedBlock(new Point3D(SPACING, SPACING, 0), ContainerSize.Length - 2 * SPACING, ContainerSize.Width - 2 * SPACING, 0);
+            //containerFloor = new PlacedBlock(new Point3D(SPACING, SPACING, 0), ContainerSize.Length - 2 * SPACING, ContainerSize.Width - 2 * SPACING, 0);
         }
 
         /// <summary>
-        /// 涓绘斁缃柟娉曪細灏濊瘯鏀剧疆鎸囧畾灏哄鐨勮揣鐗�
+        /// 鏍规嵁缁欏畾鐨勯暱瀹介珮瀵绘壘鍚堥�傜殑鏀剧疆浣嶇疆
         /// </summary>
-        /// <param name="length">璐х墿闀垮害锛圶杞存柟鍚戯級</param>
-        /// <param name="width">璐х墿瀹藉害锛圷杞存柟鍚戯級</param>
-        /// <param name="height">璐х墿楂樺害锛圸杞存柟鍚戯級</param>
-        /// <returns>
-        /// 鎴愬姛锛氳繑鍥炲彲鏀剧疆浣嶇疆鐨勫乏涓嬪墠瑙扨oint3D鍧愭爣
-        /// 澶辫触锛氳繑鍥瀗ull锛堝昂瀵告棤鏁堟垨绌洪棿涓嶈冻锛�
-        /// </returns>
+        /// <param name="length">鍧楃殑闀垮害</param>
+        /// <param name="width">鍧楃殑瀹藉害</param>
+        /// <param name="height">鍧楃殑楂樺害</param>
+        /// <returns>鍙斁缃殑3D鍧愭爣鐐癸紝鑻ユ棤娉曟斁缃垯杩斿洖null</returns>
+        /// <remarks>
+        /// 鏂规硶浼氳嚜鍔ㄥ鐞嗛暱瀹藉弬鏁帮紝纭繚length >= width
+        /// 鍦ㄦ斁缃墠浼氬厛妫�鏌ュ潡鐨勬湁鏁堟��
+        /// </remarks>
         public Point3D? PlaceBlock(int length, int width, int height)
         {
             int tempLength = length;
@@ -105,15 +146,13 @@
         }
 
         /// <summary>
-        /// 涓绘斁缃柟娉曪細灏濊瘯鏀剧疆鎸囧畾灏哄鐨勮揣鐗�
+        /// 鏍规嵁缁欏畾鐨勯暱銆佸銆侀珮鍜岃竟缂樺�兼斁缃竴涓潡锛屽苟杩斿洖鍙斁缃殑浣嶇疆
         /// </summary>
-        /// <param name="length">璐х墿闀垮害锛圶杞存柟鍚戯級</param>
-        /// <param name="width">璐х墿瀹藉害锛圷杞存柟鍚戯級</param>
-        /// <param name="height">璐х墿楂樺害锛圸杞存柟鍚戯級</param>
-        /// <returns>
-        /// 鎴愬姛锛氳繑鍥炲彲鏀剧疆浣嶇疆鐨勫乏涓嬪墠瑙扨oint3D鍧愭爣
-        /// 澶辫触锛氳繑鍥瀗ull锛堝昂瀵告棤鏁堟垨绌洪棿涓嶈冻锛�
-        /// </returns>
+        /// <param name="length">鍧楃殑闀垮害</param>
+        /// <param name="width">鍧楃殑瀹藉害</param>
+        /// <param name="height">鍧楃殑楂樺害</param>
+        /// <param name="edge">杈圭紭鍊�</param>
+        /// <returns>鍙斁缃殑浣嶇疆淇℃伅锛岃嫢鍧楁棤鏁堝垯杩斿洖null</returns>
         public TaskPosition? PlaceBlock(int length, int width, int height, int edge)
         {
             int tempLength = length;
@@ -132,35 +171,43 @@
         }
 
         /// <summary>
-        /// 楠岃瘉璐х墿灏哄鏈夋晥鎬�
-        /// 鏍¢獙瑙勫垯锛�
-        /// 1. 鍚勭淮搴﹀昂瀵稿繀椤诲ぇ浜庣瓑浜�50mm
-        /// 2. 鍚勭淮搴﹀昂瀵镐笉寰楄秴杩囧鍣ㄥ搴旂淮搴︼紙鎵i櫎闂撮殧鍚庯級
-        /// 3. 楂樺害蹇呴』 <= 瀹瑰櫒鍓╀綑楂樺害
-        /// </summary>
-        /// <param name="l"></param>
-        /// <param name="w"></param>
-        /// <param name="h"></param>
-        /// <returns></returns>
-        private bool IsValidBlock(int l, int w, int h)
-        {
-            return l > 0 && w > 0 && h > 0 &&
-                   l <= ContainerSize.Length - 2 * SPACING &&
-                   w <= ContainerSize.Width - 2 * SPACING &&
-                   h < ContainerSize.Height;
-        }
-
-        /// <summary>
-        /// 鍦ㄧ幇鏈夎揣鐗╅《閮ㄥ鎵惧彔鏀句綅缃紙鍫嗗彔妯″紡锛�
-        /// 鍙犳斁鏉′欢锛�
-        /// - 鏀拺闈㈢Н >= 琚敮鎾戦潰闈㈢Н鐨�70%
-        /// - 鏂拌揣鐗╁畬鍏ㄤ綅浜庢敮鎾戣揣鐗╀笂鏂�
-        /// - 婊¤冻闂撮殧瑕佹眰
+        /// 妫�鏌ョ粰瀹氱殑闀垮楂樻槸鍚︽瀯鎴愭湁鏁堢殑鍧椾綋灏哄
         /// </summary>
         /// <param name="l">闀垮害</param>
         /// <param name="w">瀹藉害</param>
         /// <param name="h">楂樺害</param>
-        /// <returns></returns>
+        /// <returns>濡傛灉灏哄鏈夋晥杩斿洖true锛屽惁鍒欒繑鍥瀎alse</returns>
+        /// <remarks>
+        /// 鏈夋晥鍧椾綋闇�婊¤冻锛氶暱瀹介珮閮藉ぇ浜�0锛屼笖闀垮涓嶈秴杩囧鍣ㄥ昂瀵稿噺鍘讳袱鍊嶉棿璺濓紝楂樺害涓嶈秴杩囧鍣ㄩ珮搴�
+        /// </remarks>
+        private bool IsValidBlock(int l, int w, int h)
+        {
+            return l > 0 && w > 0 && h > 0 &&
+                   l <= ContainerSize.Length &&
+                   w <= ContainerSize.Width &&
+                   h < ContainerSize.Height;
+        }
+
+        //private bool IsValidBlock(int l, int w, int h)
+        //{
+        //    return l > 0 && w > 0 && h > 0 &&
+        //           l <= ContainerSize.Length - 2 * SPACING &&
+        //           w <= ContainerSize.Width - 2 * SPACING &&
+        //           h < ContainerSize.Height;
+        //}
+
+        /// <summary>
+        /// 鍦ㄥ鍣ㄤ腑鏌ユ壘鍙斁缃寚瀹氬昂瀵稿潡浣撶殑鏈夋晥浣嶇疆
+        /// </summary>
+        /// <param name="l">鍧椾綋闀垮害</param>
+        /// <param name="w">鍧椾綋瀹藉害</param>
+        /// <param name="h">鍧椾綋楂樺害</param>
+        /// <returns>鍙斁缃綅缃殑3D鍧愭爣鐐癸紝鑻ユ棤鍚堥�備綅缃垯杩斿洖null</returns>
+        /// <remarks>
+        /// 1. 閫氳繃鍒嗘瀽宸叉斁缃潡浣撶敓鎴愬�欓�夋敮鎾戝眰
+        /// 2. 鑰冭檻瀹瑰櫒搴曢儴鍜屾敮鎾戝潡鐨勪笉鍚岄棿闅旇鍒�
+        /// 3. 浼樺厛妫�鏌ヨ钀戒綅缃互鎻愰珮鎼滅储鏁堢巼
+        /// </remarks>
         private Point3D? FindStackablePosition(int l, int w, int h)
         {
             // 鐢熸垚鍊欓�夋敮鎾戝眰锛堝寘鍚鍣ㄥ簳閮級
@@ -230,16 +277,19 @@
         }
 
         /// <summary>
-        /// 鍦ㄧ幇鏈夎揣鐗╅《閮ㄥ鎵惧彔鏀句綅缃紙鍫嗗彔妯″紡锛�
-        /// 鍙犳斁鏉′欢锛�
-        /// - 鏀拺闈㈢Н >= 琚敮鎾戦潰闈㈢Н鐨�70%
-        /// - 鏂拌揣鐗╁畬鍏ㄤ綅浜庢敮鎾戣揣鐗╀笂鏂�
-        /// - 婊¤冻闂撮殧瑕佹眰
+        /// 鍦ㄥ鍣ㄤ腑鏌ユ壘鍙爢鍙犱綅缃�
         /// </summary>
-        /// <param name="l">闀垮害</param>
-        /// <param name="w">瀹藉害</param>
-        /// <param name="h">楂樺害</param>
-        /// <returns></returns>
+        /// <param name="l">鐗╁搧闀垮害</param>
+        /// <param name="w">鐗╁搧瀹藉害</param>
+        /// <param name="h">鐗╁搧楂樺害</param>
+        /// <param name="edge">杈圭紭绫诲瀷</param>
+        /// <returns>杩斿洖鎵惧埌鐨勬湁鏁堜换鍔′綅缃紝鑻ユ壘涓嶅埌鍒欒繑鍥瀗ull</returns>
+        /// <remarks>
+        /// 1. 鐢熸垚鍊欓�夋敮鎾戝眰锛堝寘鍚鍣ㄥ簳閮級
+        /// 2. 閬嶅巻姣忓眰鏀拺鍧楄绠楁湁鏁堝彔鏀惧尯鍩�
+        /// 3. 鑰冭檻瀹瑰櫒杈圭晫绾︽潫鍜岄棿闅旇鍒�
+        /// 4. 浼樺厛妫�鏌ヨ钀戒綅缃互鎻愰珮鎼滅储鏁堢巼
+        /// </remarks>
         private TaskPosition? FindStackablePosition(int l, int w, int h, int edge)
         {
             // 鐢熸垚鍊欓�夋敮鎾戝眰锛堝寘鍚鍣ㄥ簳閮級
@@ -263,25 +313,8 @@
                     int xStart = support.Position.X;
                     int yStart = support.Position.Y;
 
-                    // 瀹瑰櫒搴曢儴鏀拺蹇呴』鍐呯缉闂撮殧锛堝嵆浣垮昂瀵哥浉鍚岋級
-                    if (support == containerFloor)
-                    {
-                        xStart = support.Position.X;
-                        yStart = support.Position.Y;
-                    }
-
                     int xEnd = support.Position.X + support.Length - l;
                     int yEnd = support.Position.Y + support.Width - w;
-
-                    // 鏅�氭敮鎾戝潡浠呭湪灏哄涓嶅悓鏃跺姞闂撮殧
-                    if (support != containerFloor &&
-                       (l != support.Length && w != support.Width))
-                    {
-                        xStart += SPACING;
-                        yStart += SPACING;
-                        xEnd -= SPACING;
-                        yEnd -= SPACING;
-                    }
 
                     // 鏈�缁堝鍣ㄨ竟鐣岀害鏉�
                     xEnd = Math.Min(xEnd, ContainerSize.Length - l);
@@ -312,17 +345,18 @@
         }
 
         /// <summary>
-        /// 鑾峰彇鏀拺褰撳墠璐х墿鐨勫簳灞傝揣鐗╁垪琛�
-        /// 鐗规畩澶勭悊锛氬綋baseZ=0鏃惰繑鍥炶櫄鎷熷鍣ㄥ簳閮ㄤ綔涓烘敮鎾�
-        /// 鏀拺鏉′欢锛氳揣鐗╁簳闈笌鏀拺璐х墿椤堕潰鎺ヨЕ涓擹鍧愭爣鍖归厤
+        /// 鑾峰彇鎸囧畾楂樺害灞傜殑鏀拺鍧�
         /// </summary>
-        /// <param name="baseZ">鏀拺鍧楅珮搴�</param>
-        /// <returns></returns>
+        /// <param name="baseZ">闇�瑕佹敮鎾戠殑楂樺害灞�</param>
+        /// <returns>鎸夐潰绉粠澶у埌灏忔帓搴忕殑鏀拺鍧楅泦鍚堬紝褰揵aseZ=0涓旀棤鏀拺鍧楁椂杩斿洖瀹瑰櫒搴曢儴</returns>
         private IEnumerable<PlacedBlock> GetSupportBlocks(int baseZ)
         {
             var blocks = PlacedBlocks
                 .Where(b => b.Position.Z + b.Height == baseZ)
-                /*.OrderByDescending(b => b.Length * b.Width)*/.ToList();
+                .OrderBy(b => b.Position.X)
+                .ThenBy(b => b.Position.Y)
+                /*.OrderByDescending(b => b.Length * b.Width)*/
+                .ToList();
 
             // 褰揵aseZ=0鏃舵坊鍔犲鍣ㄥ簳閮ㄦ敮鎾�
             if (baseZ == 0 && blocks.Count == 0)
@@ -334,24 +368,24 @@
         }
 
         /// <summary>
-        /// 楠岃瘉鎸囧畾浣嶇疆鏄惁鍚堟硶
-        /// 鏍¢獙鍐呭锛�
-        /// 1. 杈圭晫鏉′欢锛氳揣鐗╀笉寰楄秴鍑哄鍣ㄦ湁鏁堢┖闂�
-        /// 2. 纰版挒妫�娴嬶細涓庡凡鏀剧疆璐х墿鏃犵┖闂撮噸鍙�
-        /// 3. 闂撮殧瑕佹眰锛氫繚鎸佹渶灏忛棿闅旓紙SPACING甯搁噺锛�
+        /// 妫�鏌ユ寚瀹氫綅缃槸鍚︽湁鏁堬紝鍗宠浣嶇疆鏄惁鍙互鏀剧疆鎸囧畾灏哄鐨勫潡浣�
         /// </summary>
-        /// <param name="pos">鍧愭爣</param>
-        /// <param name="l">闀垮害</param>
-        /// <param name="w">瀹藉害</param>
-        /// <param name="h">楂樺害</param>
-        /// <returns></returns>
+        /// <param name="pos">瑕佹鏌ョ殑浣嶇疆鍧愭爣</param>
+        /// <param name="l">鍧椾綋闀垮害</param>
+        /// <param name="w">鍧椾綋瀹藉害</param>
+        /// <param name="h">鍧椾綋楂樺害</param>
+        /// <returns>濡傛灉浣嶇疆鏈夋晥涓斾笉涓庡叾浠栧凡鏀剧疆鍧椾綋閲嶅彔鍒欒繑鍥瀟rue锛屽惁鍒欒繑鍥瀎alse</returns>
+        /// <remarks>
+        /// 妫�鏌ユ潯浠跺寘鎷細
+        /// 1. 鏄惁瓒呭嚭瀹瑰櫒灏哄闄愬埗
+        /// 2. X鍧愭爣鏄惁瓒呰繃1600闄愬埗
+        /// 3. 褰揦鍧愭爣瓒呰繃MaxY涓旈暱搴﹁秴杩嘙axRotateLength鏃剁殑闄愬埗
+        /// 4. 鏄惁涓庡凡鏀剧疆鐨勫潡浣撳彂鐢熼噸鍙狅紙鑰冭檻SPACING闂磋窛锛�
+        /// </remarks>
         private bool IsPositionValid(Point3D pos, int l, int w, int h)
         {
-            // 杈圭晫妫�鏌ワ紙鍚鍣ㄨ竟缂橀棿闅旓級
-            if (pos.X < SPACING ||
-                pos.Y < SPACING ||
-                pos.X + l > ContainerSize.Length - SPACING ||
-                pos.Y + w > ContainerSize.Width - SPACING)
+            if (pos.X + l > ContainerSize.Length ||
+                pos.Y + w > ContainerSize.Width)
                 return false;
 
             if (pos.X > 1600)
@@ -359,7 +393,6 @@
 
             if (pos.X > MaxY && l > MaxRotateLength) return false;
 
-            // 涓夌淮纰版挒妫�娴�
             var newBlock = new PlacedBlock(pos, l, w, h);
             return !PlacedBlocks.Any(existing =>
             {
@@ -376,18 +409,61 @@
             });
         }
 
+        //private bool IsPositionValid(Point3D pos, int l, int w, int h)
+        //{
+        //    // 杈圭晫妫�鏌ワ紙鍚鍣ㄨ竟缂橀棿闅旓級
+        //    if (pos.X < SPACING ||
+        //        pos.Y < SPACING ||
+        //        pos.X + l > ContainerSize.Length - SPACING ||
+        //        pos.Y + w > ContainerSize.Width - SPACING)
+        //        return false;
+
+        //    if (pos.X > 1600)
+        //        return false;
+
+        //    if (pos.X > MaxY && l > MaxRotateLength) return false;
+
+        //    // 涓夌淮纰版挒妫�娴�
+        //    var newBlock = new PlacedBlock(pos, l, w, h);
+        //    return !PlacedBlocks.Any(existing =>
+        //    {
+        //        bool xOverlap = newBlock.Position.X < existing.Position.X + existing.Length + SPACING &&
+        //                      newBlock.Position.X + newBlock.Length + SPACING > existing.Position.X;
+
+        //        bool yOverlap = newBlock.Position.Y < existing.Position.Y + existing.Width + SPACING &&
+        //                      newBlock.Position.Y + newBlock.Width + SPACING > existing.Position.Y;
+
+        //        bool zOverlap = newBlock.Position.Z < existing.Position.Z + existing.Height &&
+        //                      newBlock.Position.Z + h > existing.Position.Z;
+
+        //        return xOverlap && yOverlap && zOverlap;
+        //    });
+        //}
+
+        /// <summary>
+        /// 妫�鏌ヤ换鍔′綅缃槸鍚︽湁鏁�
+        /// </summary>
+        /// <param name="pos">瑕佹鏌ョ殑浠诲姟浣嶇疆</param>
+        /// <returns>濡傛灉Y杞村潗鏍囧湪鏈夋晥鑼冨洿鍐呰繑鍥瀟rue锛屽惁鍒欒繑鍥瀎alse</returns>
         private bool IsPositionValid(TaskPosition pos)
         {
-            // 杈圭晫妫�鏌ワ紙鍚鍣ㄨ竟缂橀棿闅旓級
-            //if (pos.X < SPACING ||
-            //    pos.Y < SPACING ||
-            //    pos.X + l > ContainerSize.Length - SPACING ||
-            //    pos.Y + w > ContainerSize.Width - SPACING)
-            //    return false;
-
             return pos.PutPositionY <= MaxY && pos.PutPositionY >= 0 && pos.TakePositionY >= 0;
         }
 
+        /// <summary>
+        /// 鏍规嵁缁欏畾鐨勪笁缁村潗鏍囧拰灏哄鍙傛暟璁$畻浠诲姟浣嶇疆淇℃伅
+        /// </summary>
+        /// <param name="point3D">璧峰涓夌淮鍧愭爣鐐�</param>
+        /// <param name="length">鐗╀綋闀垮害</param>
+        /// <param name="width">鐗╀綋瀹藉害</param>
+        /// <param name="height">鐗╀綋楂樺害</param>
+        /// <param name="edge">杈圭紭鏍囪瘑(0/1)</param>
+        /// <returns>鍖呭惈鍙栨斁璐т綅缃俊鎭殑TaskPosition瀵硅薄</returns>
+        /// <remarks>
+        /// 璇ユ柟娉曟牴鎹墿浣撳昂瀵歌嚜鍔ㄩ�夋嫨鍗曞惛鐩樻垨鍙屽惛鐩樻ā寮忥紝
+        /// 骞惰绠楀惛鐩樹腑蹇冪偣浣嶇疆锛屽悓鏃跺鐞嗚竟鐣屾潯浠堕檺鍒躲��
+        /// 妯悜鏀剧疆鏃舵渶灏廦鍧愭爣涓�155锛岀旱鍚戞椂涓�350锛屾渶澶鍧愭爣涓�700銆�
+        /// </remarks>
         public TaskPosition GetTaskPosition(Point3D point3D, int length, int width, int height, int edge)
         {
             //鏀捐揣浣嶇疆鏉挎潗涓績鐐�
@@ -397,7 +473,6 @@
             Point3D takeCenter = new Point3D(length / 2, width / 2, height / 2);
 
             //鍚哥洏闀�530 闂撮殧660  鏈�澶�920 鍚哥洏瀹�130
-
             int positionR = 1;
 
             int takePositionX = 0;
@@ -420,7 +495,7 @@
 
                 putPositionX = (putCenter.Y - deviceCenter.X);
                 putPositionY = (putCenter.X - deviceCenter.Y);
-                putPositionZ = point3D.Z; // putCenter.Z /*+ 10*/;
+                putPositionZ = point3D.Z;
             }
             else//妯悜鍗曞惛
             {
@@ -434,10 +509,9 @@
 
                 putPositionX = (putCenter.Y - deviceCenter.X);
                 putPositionY = (putCenter.X - deviceCenter.Y);
-                putPositionZ = point3D.Z; // putCenter.Z /*+ 10*/;
+                putPositionZ = point3D.Z;
             }
 
-            //1.濡傛灉鍙栬揣浣嶆渶灏廦鍧愭爣灏忎簬155
             if (takePositionY <= MinY)
             {
                 takePositionY = 0;
@@ -459,14 +533,13 @@
                 else if (Math.Abs(takePositionY - moreY) < SPACING)
                 {
                     takePositionY = 0;
-                    putPositionY = Math.Abs(takePositionY - moreY);
+                    putPositionY = Math.Abs(takePositionY - moreY) + MinY;
                 }
                 else
                 {
                     int count = PlacedBlocks.Where(x => x.Position.Y == 10).Count();
-                    //putPositionY -= (920 - 130 + takePositionY - (count + 1) * SPACING * 2);
-                    putPositionY = point3D.X - 920 + 130;
-                    takePositionY = length - MinY - 130;
+                    putPositionY = point3D.X - 920 + 130 + RotateYOffset;
+                    takePositionY = length - MinY - 130 - RotateYOffset;
                     if (putPositionY < 0 && takePositionY + putPositionY >= 0)
                     {
                         takePositionY += putPositionY;
@@ -475,61 +548,6 @@
                     positionR = 2;
                 }
             }
-
-
-
-            //妯悜鏃讹紝鏈�灏廦鍧愭爣涓�155锛岀旱鍚戞椂锛屾渶灏廦鍧愭爣涓�350銆傛渶澶鍧愭爣涓�700
-            //if (positionR == 1 && putPositionY < MinY)
-            //{
-            //    takePositionY = 0;
-
-            //    putPositionY = point3D.X + MinY;
-            //}
-            //else if (positionR == 1 && putPositionY >= MinY && putPositionY <= MaxY)
-            //{
-            //    if (takePositionY >= MinY)
-            //        takePositionY -= MinY;
-            //    else
-            //    {
-            //        putPositionY += MinY - takePositionY;
-            //        takePositionY = 0;
-            //    }
-            //}
-            //else if (positionR == 1 && putPositionY > MaxY && putPositionY < 1700)
-            //{
-            //    int moreY = putPositionY - MaxY;
-            //    if (takePositionY - moreY - MinY > 0)
-            //    {
-            //        takePositionY -= moreY + MinY;
-            //        putPositionY = MaxY;
-            //    }
-            //    else if (Math.Abs(takePositionY - moreY - MinY) < SPACING)
-            //    {
-            //        if (takePositionY - moreY - MinY > 0)
-            //        {
-            //            takePositionY -= moreY + MinY;
-            //        }
-            //        else
-            //        {
-            //            takePositionY = 0;
-            //        }
-            //        putPositionY = MaxY;
-            //    }
-            //    else
-            //    {
-            //        int count = PlacedBlocks.Where(x => x.Position.Y == 10).Count();
-            //        //putPositionY -= (920 - 130 + takePositionY - (count + 1) * SPACING * 2);
-            //        putPositionY = point3D.X - 920 + 130;
-            //        takePositionY = length - MinY - 130;
-
-            //        if (putPositionY < 0 && takePositionY + putPositionY >= 0)
-            //        {
-            //            takePositionY += putPositionY;
-            //            putPositionY = 0;
-            //        }
-            //        positionR = 2;
-            //    }
-            //}
 
             if (positionR == 2 && edge == 0)
             {
@@ -543,8 +561,16 @@
             }
             else if (positionR == 1 && edge == 1)
             {
-                takePositionX = width - 530;
-                putPositionX = point3D.Y + (width - 530);
+                if(width > ContainerSize.Width)
+                {
+                    takePositionX = 0;
+                    putPositionX = point3D.Y;
+                }
+                else
+                {
+                    takePositionX = width - 530;
+                    putPositionX = point3D.Y + (width - 530);
+                }
             }
             else if (positionR == 1 && edge == 0)
             {

--
Gitblit v1.9.3