Exemple #1
0
        private void Decompose()
        {
            List <List <Vector2> > tempCenters = new List <List <Vector2> >();

            if (mIsConvex)
            {
                tempCenters = ConvexPolygonScanning.DrawPolygonTranslate(mPolygonData.mPointArray, mScale);
            }
            else
            {
                tempCenters = PolygonScanning.DrawPolygonScale(mPolygonData.mPointArray, mScale);
            }
            foreach (List <Vector2> vv in tempCenters)
            {
                foreach (Vector2 v in vv)
                {
                    Vector2 p = v;
                    if (mIsConvex && GeoPolygonUtils.IsPointInConvexPolygon2(mPolygonData, ref p))
                    {
                        mCenterList.Add(p);
                    }
                    else if (!mIsConvex && GeoPolygonUtils.IsPointInPolygon2(mPolygonData, ref p))
                    {
                        mCenterList.Add(p);
                    }
                }
            }
        }
Exemple #2
0
        private void RemovePointsInPolygon(List <Vector2> innerPoly)
        {
            List <Vector2> temp = new List <Vector2>();

            temp.AddRange(innerPoly);
            GeoPolygonUtils.ReverseIfCW(ref temp);
            GeoPointsArray2 poly        = new GeoPointsArray2(temp);
            List <int>      removeIndex = new List <int>();

            for (int i = 0; i < mCenterList.Count; ++i)
            {
                Vector2 t = mCenterList[i];
                if (GeoPolygonUtils.IsPointInPolygon2(poly, ref t))
                {
                    removeIndex.Add(i);
                }
            }
            for (int i = removeIndex.Count - 1; i >= 0; --i)
            {
                mCenterList.RemoveAt(removeIndex[i]);
            }
        }
Exemple #3
0
        private bool CheckRectangleValid(Vector2 min, Vector2 max, float w, float h)
        {
            Vector2 p4 = new Vector2(min[0], max[1]);
            Vector2 p2 = new Vector2(max[0], min[1]);

            // 点都在polygon 内部  // 使用 bvh 判断
            if (mIsConvex)
            {
                bool isInconvex = GeoPolygonUtils.IsPointInConvexPolygon2(mPolygonData, ref max);
                if (!isInconvex)
                {
                    return(false);
                }
                isInconvex = GeoPolygonUtils.IsPointInConvexPolygon2(mPolygonData, ref min);
                if (!isInconvex)
                {
                    return(false);
                }
                isInconvex = GeoPolygonUtils.IsPointInConvexPolygon2(mPolygonData, ref p2);
                if (!isInconvex)
                {
                    return(false);
                }
                isInconvex = GeoPolygonUtils.IsPointInConvexPolygon2(mPolygonData, ref p4);
                if (!isInconvex)
                {
                    return(false);
                }
            }
            else
            {
                if (mSegmentsBvh != null)
                {
                    bool insect = mSegmentsBvh.TestIntersection(new GeoAABB2(min, max));
                    if (insect)
                    {
                        return(false);
                    }
                }
                else
                {
                    bool isInconvex = GeoPolygonUtils.IsPointInPolygon2(mPolygonData, ref max);
                    if (!isInconvex)
                    {
                        return(false);
                    }
                    isInconvex = GeoPolygonUtils.IsPointInPolygon2(mPolygonData, ref min);
                    if (!isInconvex)
                    {
                        return(false);
                    }
                    isInconvex = GeoPolygonUtils.IsPointInPolygon2(mPolygonData, ref p2);
                    if (!isInconvex)
                    {
                        return(false);
                    }
                    isInconvex = GeoPolygonUtils.IsPointInPolygon2(mPolygonData, ref p4);
                    if (!isInconvex)
                    {
                        return(false);
                    }
                }
            }
            // 矩形与矩形是否有交叉
            bool isInsectAABB = IsIntersectOtherAABB(min, max);

            if (isInsectAABB)
            {
                return(false);
            }
            return(true);
        }