Ejemplo n.º 1
0
        public bool PlanLegalityCheck()
        {
            for (int p = 0; p < numberOfPoints; p++)
            {
                this[p].illegal = false;
            }
            bool output = false;

            for (int indexAA = 0; indexAA < numberOfPoints; indexAA++)
            {
                Vector2Int p0      = _points[indexAA].position;
                int        indexAB = (indexAA + 1) % numberOfPoints;
                Vector2Int p1      = _points[indexAB].position;
                for (int indexBA = 0; indexBA < numberOfPoints; indexBA++)
                {
                    if (indexAA == indexBA)
                    {
                        continue;                                        //skip testing wall on itself
                    }
                    int indexBB = (indexBA + 1) % numberOfPoints;
                    if (indexAA == indexBB)
                    {
                        continue;                                        //skip testing wall on itself
                    }
                    Vector2Int p2 = _points[indexBA].position;
                    Vector2Int p3 = _points[indexBB].position;


                    if (BuildrUtils.PointOnLine(p0, p2, p3))
                    {
                        _points[indexAA].illegal = true;
                        _points[indexBA].illegal = true;
                        output = true;
                        continue;
                    }

                    if (indexAA == indexBB || indexAB == indexBA || indexAB == indexBB)
                    {
                        continue;                                                                                    //don't test lines that connect
                    }
                    //                    if (p0 == p2 || p0 == p3 || p1 == p2 || p1 == p3) continue;//don't test lines that connect

                    if (BuildrUtils.FastLineIntersection(p0, p1, p2, p3))
                    {
                        _points[indexAA].illegal = true;
                        _points[indexBA].illegal = true;
                        output = true;
                    }
                }
            }
            return(output);
        }
Ejemplo n.º 2
0
        private bool PlanLegality()
        {
            for (int p = 0; p < numberOfPoints; p++)
            {
                this[p].illegal = false;
            }
            for (int p = 0; p < numberOfPoints - 1; p++)
            {
                if (this[p] == this[p + 1])
                {
                    _points.RemoveAt(p + 1);//remove duplicate points
                }
            }
            bool output = false;

            for (int pA = 0; pA < numberOfPoints; pA++)
            {
                Vector2Int p0 = _points[pA].position;
                Vector2Int p1 = _points[(pA + 1) % numberOfPoints].position;
                for (int pB = 0; pB < numberOfPoints; pB++)
                {
                    if (pA == pB)
                    {
                        continue;          //skip testing wall on itself
                    }
                    Vector2Int p2 = _points[pB].position;
                    Vector2Int p3 = _points[(pB + 1) % numberOfPoints].position;

                    if (p0 == p2 || p0 == p3 || p1 == p2 || p1 == p3)
                    {
                        continue;                                              //don't test lines that connect
                    }
                    if (BuildrUtils.FastLineIntersection(p0, p1, p2, p3))
                    {
                        _points[pA].illegal = true;
                        _points[pB].illegal = true;
                        output = true;
                    }
                }
            }
            return(output);
        }