Ejemplo n.º 1
0
        private static List <Vector2> CheckIntersect(List <Vector2> result, ref List <Vector2> insects)
        {
            List <MarginalExpandClass> temp = new List <MarginalExpandClass>();

            for (int i = 0; i < result.Count; ++i)
            {
                MarginalExpandClass marginalPoint = new MarginalExpandClass();
                int j = i + 1;
                if (j == result.Count)
                {
                    j = 0;
                }
                marginalPoint.index = i;
                marginalPoint.v1    = result[i];
                marginalPoint.v2    = result[j];
                temp.Add(marginalPoint);
            }
            for (int i = 0; i < temp.Count - 1; ++i)
            {
                MarginalExpandClass cur = temp[i];
                for (int j = i + 1; j < temp.Count; ++j)
                {
                    MarginalExpandClass other = temp[j];
                    if (temp[j].v1 == cur.v2)
                    {
                        continue;
                    }
                    GeoInsectPointInfo info = new GeoInsectPointInfo();
                    if (GeoSegmentUtils.IsSegmentInsectSegment2(cur.v1, cur.v2, other.v1, other.v2, ref info))
                    {
                        Vector2 ttt = info.mHitGlobalPoint;
                        cur.insectPoint.Add(ttt);
                        cur.insectIndex.Add(other.index);
                        other.insectPoint.Add(ttt);
                        other.insectIndex.Add(cur.index);
                    }
                }
            }
            List <Vector2> allPointsWithIntersects = new List <Vector2>();

            for (int i = 0; i < temp.Count; ++i)
            {
                allPointsWithIntersects.Add(temp[i].v1);
                if (temp[i].insectPoint.Count > 0)
                {
                    temp[i].Sort();
                    foreach (Vector2 v2t in temp[i].insectPoint)
                    {
                        int index = insects.FindIndex((Vector2 v) =>
                        {
                            return(v == v2t);
                        });
                        if (index == -1)
                        {
                            insects.Add(v2t);
                        }
                    }
                    allPointsWithIntersects.AddRange(temp[i].insectPoint);
                }
            }
            if (allPointsWithIntersects.Count < 2)
            {
                return(allPointsWithIntersects);
            }
            List <Vector2> tempResult1 = new List <Vector2>();

            {
                int index = 0;
                for (int i = 1; i < allPointsWithIntersects.Count; ++i)
                {
                    if (allPointsWithIntersects[i] != allPointsWithIntersects[0])
                    {
                        index = i;
                        break;
                    }
                }
                List <Vector2> tempResult = new List <Vector2>();
                for (int i = index; i < allPointsWithIntersects.Count; ++i)
                {
                    tempResult.Add(allPointsWithIntersects[i]);
                }
                for (int i = 0; i < index; ++i)
                {
                    tempResult.Add(allPointsWithIntersects[i]);
                }
                for (int i = 0; i < tempResult.Count;)
                {
                    tempResult1.Add(tempResult[i]);
                    int next = i + 1;
                    while (next < tempResult.Count && tempResult[i] == tempResult[next])
                    {
                        ++next;
                    }
                    i = next;
                }
            }
            return(tempResult1);
        }