private static float CheckSegmentsIntersect(List <Vector2> segs)
        {
            int   count = segs.Count >> 1;
            float min   = 1e10f;
            bool  flag  = false;

            for (int i = 0; i < count - 1; ++i)
            {
                Vector2 iv1 = segs[2 * i];
                Vector2 iv2 = segs[2 * i + 1];
                for (int j = i + 1; j < count; ++j)
                {
                    Vector2            jv1   = segs[2 * j];
                    Vector2            jv2   = segs[2 * j + 1];
                    GeoInsectPointInfo infor = new GeoInsectPointInfo();
                    if (GeoSegmentUtils.IsSegmentInsectSegment2(iv1, iv2, jv1, jv2, ref infor))
                    {
                        Vector2 insect = infor.mHitGlobalPoint;
                        float   isi    = (insect - iv1).sqrMagnitude;
                        float   isj    = (insect - jv1).sqrMagnitude;
                        float   maxT   = isi > isj ? isi : isj;
                        if (maxT < min)
                        {
                            flag = true;
                            min  = maxT;
                        }
                    }
                }
            }
            if (flag)
            {
                return(min);
            }
            return(-1.0f);
        }
Esempio n. 2
0
        private static bool IsInSegment(LinkedListNode <EarPoint> ele, EarPolygon poly)
        {
            LinkedListNode <EarPoint> a = poly.Previous(ele);
            LinkedListNode <EarPoint> b = ele;
            LinkedListNode <EarPoint> c = poly.Next(ele);

            return(GeoSegmentUtils.IsPointInSegment2(a.Value.mPoint, c.Value.mPoint, ref b.Value.mPoint));
        }
Esempio n. 3
0
        private static bool DoIntersect(EarPoint a, EarPoint b, EarPoint c, EarPoint d)
        {
            GeoInsectPointInfo insect = new GeoInsectPointInfo();
            bool isInsect             = GeoSegmentUtils.IsSegmentInsectSegment2(a.mPoint, b.mPoint, c.mPoint, d.mPoint, ref insect);

            if (isInsect)
            {
                float x = insect.mHitGlobalPoint[0];
                float y = insect.mHitGlobalPoint[1];
                if ((x == c[0] && y == c[1]) || (x == d[0] && y == d[1])) // 端点检测
                {
                    return(false);
                }
            }
            return(isInsect);
        }
        public bool TestAABBIntersect(GeoAABB2 aabb)
        {
            GeoInsectPointArrayInfo insect = new GeoInsectPointArrayInfo();

            return(GeoSegmentUtils.IsSegmentInsectAABB2(mSeg.mP1, mSeg.mP2, aabb.mMin, aabb.mMax, ref insect));
        }
        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);
        }