浏览代码

Merge branch 'master' of https://git.dev.tencent.com/xuhuo1234/saga

mengxiangge 6 年之前
父节点
当前提交
7b242772f4

+ 1 - 1
MBI/SAGA.DotNetUtils/Extend/DoubleExt.cs

@@ -11,7 +11,7 @@ namespace SAGA.DotNetUtils.Extend
 {
     public static class DoubleExt
     {
-        private const double Precision = 0.01;
+        private const double Precision = 0.001;
 
         /// <summary>
         /// ÁíÒ»°ë»¡³¤

+ 1 - 0
MBI/SAGA.DotNetUtils/SAGA.DotNetUtils.csproj

@@ -411,6 +411,7 @@
     <Compile Include="Utilities\FileUp.cs" />
     <Compile Include="Utilities\IniOperator.cs" />
     <Compile Include="Utilities\IWaitingView.cs" />
+    <Compile Include="Utilities\ListExtensions.cs" />
     <Compile Include="Utilities\PinyinUtil.cs" />
     <Compile Include="Utilities\SharpZip.cs" />
     <Compile Include="Utilities\SmtpMailUtil.cs" />

+ 82 - 0
MBI/SAGA.DotNetUtils/Utilities/ListExtensions.cs

@@ -0,0 +1,82 @@
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+
+namespace SAGA.DotNetUtils
+{
+    public static class ListExtensions
+    {
+        public static int CalcIndex(int index,int total)
+        {
+            return index % total;
+        }
+        public static T GetFirstElement<T>(this List<T> source, int startIndex, Func<T, bool> breakCondition, bool isFoward)
+        {
+            var total = source.Count;
+            //如果是后退,则增加一
+            var useIndex = (isFoward ? 0 : total) + startIndex;
+            var count = 0;
+            var currentIndex = CalcIndex(useIndex, total);
+            while (count < total)
+            {
+                var current = source[currentIndex];
+                if (breakCondition(current))
+                {
+                    return current;
+                }
+                useIndex = useIndex + (isFoward ? 1 : -1);
+                currentIndex = CalcIndex(useIndex, total);
+                count++;
+            }
+            return default(T);
+        }
+        
+        public static int GetFirstElementIndex<T>(this List<T> source,int startIndex,Func<T,bool> breakCondition,bool isFoward)
+        {
+            var total = source.Count;
+            //如果是后退,则增加一
+            var useIndex = (isFoward?0:total) + startIndex;
+            var count = 0;
+            var currentIndex = CalcIndex(useIndex,total);
+            while(count < total)
+            {
+                var current = source[currentIndex];
+                if (breakCondition(current))
+                {
+                    return currentIndex;
+                }
+                useIndex = useIndex + (isFoward ? 1 : -1);
+                currentIndex = CalcIndex(useIndex, total);
+                count++;
+            }
+            return -1;
+        }
+        /// <summary>
+        /// 获取以指定索引为起始点的集合
+        /// </summary>
+        /// <typeparam name="T"></typeparam>
+        /// <param name="source"></param>
+        /// <param name="startIndex"></param>
+        /// <param name="isFoward"></param>
+        /// <returns></returns>
+        public static IEnumerable<T> GetElements<T>(this List<T> source, int startIndex, bool isFoward)
+        {
+            var total = source.Count;
+            //如果是后退,则增加一
+            var useIndex = (isFoward ? 0 : total) + startIndex;
+            var count = 0;
+            var currentIndex = CalcIndex(useIndex, total);
+            while (count < total)
+            {
+                var current = source[currentIndex];
+                yield return current;
+                useIndex = useIndex + (isFoward ? 1 : -1);
+                currentIndex = CalcIndex(useIndex, total);
+                count++;
+            }
+            yield break;
+        }
+    }
+}

+ 13 - 2
MBI/SAGA.GplotManage/TopologyApplicationCommand.cs

@@ -7,6 +7,7 @@
 
 using System;
 using System.Collections.Generic;
+using System.Diagnostics;
 using System.Linq;
 using System.Text;
 using System.Threading;
@@ -66,8 +67,18 @@ namespace SAGA.GplotManage
             {
                 return Result.Succeeded;
             }
-            SpaceAirSupplyHandler.ShellExecute();
-            MessageShow.Infomation("完成");
+
+            Stopwatch watch = new Stopwatch();
+            watch.Start();
+            for (int i = 0; i < 4*300*2300; i++)
+            {
+                Line.CreateBound(new XYZ(0, 0,0), new XYZ(100, 100,100));
+            }
+
+            watch.Stop();
+            MessageShowBase.Confirm(watch.ElapsedMilliseconds.ToString());
+            //SpaceAirSupplyHandler.ShellExecute();
+            //MessageShow.Infomation("完成");
             return Result.Succeeded;
         }
 

+ 89 - 5
MBI/SAGA.RevitUtils/Extends/XYZExtend.cs

@@ -1813,14 +1813,98 @@ namespace SAGA.RevitUtils.Extends
         /// </returns>
         public static int PointInPolygonByRay(this XYZ inputPoint, List<XYZ> points)
         {
-            List<Line> lines = new List<Line>();
-            for (int i = 0; i < points.Count; i++)
+            #region 老方法
+            //List<Line> lines = new List<Line>();
+            //for (int i = 0; i < points.Count; i++)
+            //{
+            //    var start = points[i];
+            //    var end = points[(i + 1) % points.Count];
+            //    lines.Add(Line.CreateBound(start, end));
+            //}
+            //return PointInPolygonByRay(inputPoint, lines); 
+            #endregion
+            bool isEven = true;
+            double baseX = inputPoint.X;
+            double baseY = inputPoint.Y;
+            var total = points.Count;
+            for (int i = 0; i < total; i++)
             {
+                var endIndex = (i + 1) % total;
                 var start = points[i];
-                var end = points[(i + 1) % points.Count];
-                lines.Add(Line.CreateBound(start, end));
+                var end = points[endIndex];
+                if (start.IsEqual2(inputPoint) || end.IsEqual2(inputPoint))
+                {
+                    return 0;
+                }
+                bool isEndIntersection = false;//判断交点是否是end
+                //判断给定线的端点是否在射线两侧,利用水平线的性质
+                if ((start.Y.IsLessEq(baseY) && baseY.IsLessEq(end.Y)) || (end.Y.IsLessEq(baseY) && baseY.IsLessEq(start.Y)))
+                {
+                    double minX = Math.Min(start.X, end.X);
+                    double maxX = Math.Min(start.X, end.X);
+                    if (start.Y.IsEqual(end.Y))
+                    {
+                        #region 与给定射线共线处理                 
+                        //给定线段与射线平行
+                        if (minX.IsLessEq(baseX) && baseX.IsLessEq(maxX))
+                        {
+                            return 0;
+                        }
+                        else if (baseX.IsLess(minX))
+                        {
+                            isEndIntersection = true;
+                        }
+                        #endregion
+                    }
+                    else if (baseX.IsLessEq(maxX))
+                    {
+                        double c = (baseY - start.Y) / (end.Y - start.Y);
+                        double useX = start.X + c * (end.X - start.X);
+                        if (useX.IsEqual(baseX))
+                        {
+                            //给定点,在线上
+                            return 0;
+                        }
+                        if (baseX.IsLessEq(useX))
+                        {
+                            //这种情况下肯定相交
+                            var intersectionPoint = new XYZ(useX, baseY,0);
+                            if (end.IsEqual2(intersectionPoint))
+                            {
+                                //开始点不处理
+                                isEndIntersection = true;
+                            }
+                            else if (start.IsEqual2(intersectionPoint))
+                            {
+                                isEndIntersection = false;
+                            }
+                            else
+                            {
+                                isEven = !isEven;
+                            }
+                        }
+                    }
+
+                    if (isEndIntersection)
+                    {
+                        var end2 = points[(endIndex + 1) % total];
+                        if (!baseY.IsEqual(end2.Y))
+                        {
+                            var point = points.GetFirstElement(endIndex, p => !p.Y.IsEqual(baseY), false);
+                            if (end2.Y.IsLess(baseY) == point.Y.IsThan(baseY))
+                            {
+                                //排除同时相等的情况
+                                if (!end2.Y.IsEqual(baseY) && !point.Y.IsEqual(baseY))
+                                {
+                                    isEven = !isEven;
+                                }
+                            }
+                        }
+                    }
+
+                }
             }
-            return PointInPolygonByRay(inputPoint, lines);
+            return isEven ? -1 : 1;
         }
     }
 }