예제 #1
0
        private static bool Snip(Vertices contour, int u, int v, int w, int n, int[] V)
        {
            bool flag = Settings.Epsilon > MathUtils.Area(ref FlipcodeDecomposer._tmpA, ref FlipcodeDecomposer._tmpB, ref FlipcodeDecomposer._tmpC);
            bool result;

            if (flag)
            {
                result = false;
            }
            else
            {
                for (int i = 0; i < n; i++)
                {
                    bool flag2 = i == u || i == v || i == w;
                    if (!flag2)
                    {
                        TSVector2 tSVector = contour[V[i]];
                        bool      flag3    = FlipcodeDecomposer.InsideTriangle(ref FlipcodeDecomposer._tmpA, ref FlipcodeDecomposer._tmpB, ref FlipcodeDecomposer._tmpC, ref tSVector);
                        if (flag3)
                        {
                            result = false;
                            return(result);
                        }
                    }
                }
                result = true;
            }
            return(result);
        }
예제 #2
0
        // TS - public static List<Vertices> ConvexPartition(Vertices vertices, TriangulationAlgorithm algorithm, bool discardAndFixInvalid = true, FP tolerance = 0.001f)
        public static List <Vertices> ConvexPartition(Vertices vertices, TriangulationAlgorithm algorithm, bool discardAndFixInvalid, FP tolerance)
        {
            if (vertices.Count <= 3)
            {
                return new List <Vertices> {
                           vertices
                }
            }
            ;

            List <Vertices> results;

            switch (algorithm)
            {
            case TriangulationAlgorithm.Earclip:
                if (Settings.SkipSanityChecks)
                {
                    Debug.Assert(!vertices.IsCounterClockWise(), "The Earclip algorithm expects the polygon to be clockwise.");
                }
                else
                {
                    if (vertices.IsCounterClockWise())
                    {
                        Vertices temp = new Vertices(vertices);
                        temp.Reverse();
                        results = EarclipDecomposer.ConvexPartition(temp, tolerance);
                    }
                    else
                    {
                        results = EarclipDecomposer.ConvexPartition(vertices, tolerance);
                    }
                }
                break;

            case TriangulationAlgorithm.Bayazit:
                if (Settings.SkipSanityChecks)
                {
                    Debug.Assert(vertices.IsCounterClockWise(), "The polygon is not counter clockwise. This is needed for Bayazit to work correctly.");
                }
                else
                {
                    if (!vertices.IsCounterClockWise())
                    {
                        Vertices temp = new Vertices(vertices);
                        temp.Reverse();
                        results = BayazitDecomposer.ConvexPartition(temp);
                    }
                    else
                    {
                        results = BayazitDecomposer.ConvexPartition(vertices);
                    }
                }
                break;

            case TriangulationAlgorithm.Flipcode:
                if (Settings.SkipSanityChecks)
                {
                    Debug.Assert(vertices.IsCounterClockWise(), "The polygon is not counter clockwise. This is needed for Bayazit to work correctly.");
                }
                else
                {
                    if (!vertices.IsCounterClockWise())
                    {
                        Vertices temp = new Vertices(vertices);
                        temp.Reverse();
                        results = FlipcodeDecomposer.ConvexPartition(temp);
                    }
                    else
                    {
                        results = FlipcodeDecomposer.ConvexPartition(vertices);
                    }
                }
                break;

            case TriangulationAlgorithm.Seidel:
                results = SeidelDecomposer.ConvexPartition(vertices, tolerance);
                break;

            case TriangulationAlgorithm.SeidelTrapezoids:
                results = SeidelDecomposer.ConvexPartitionTrapezoid(vertices, tolerance);
                break;

            case TriangulationAlgorithm.Delauny:
                results = CDTDecomposer.ConvexPartition(vertices);
                break;

            default:
                throw new ArgumentOutOfRangeException("algorithm");
            }

            if (discardAndFixInvalid)
            {
                for (int i = results.Count - 1; i >= 0; i--)
                {
                    Vertices polygon = results[i];

                    if (!ValidatePolygon(polygon))
                    {
                        results.RemoveAt(i);
                    }
                }
            }

            return(results);
        }
예제 #3
0
        public static List <Vertices> ConvexPartition(Vertices vertices)
        {
            Debug.Assert(vertices.Count > 3);
            Debug.Assert(vertices.IsCounterClockWise());
            int[] array = new int[vertices.Count];
            for (int i = 0; i < vertices.Count; i++)
            {
                array[i] = i;
            }
            int             j    = vertices.Count;
            int             num  = 2 * j;
            List <Vertices> list = new List <Vertices>();
            int             num2 = j - 1;
            List <Vertices> result;

            while (j > 2)
            {
                bool flag = 0 >= num--;
                if (flag)
                {
                    result = new List <Vertices>();
                    return(result);
                }
                int  num3  = num2;
                bool flag2 = j <= num3;
                if (flag2)
                {
                    num3 = 0;
                }
                num2 = num3 + 1;
                bool flag3 = j <= num2;
                if (flag3)
                {
                    num2 = 0;
                }
                int  num4  = num2 + 1;
                bool flag4 = j <= num4;
                if (flag4)
                {
                    num4 = 0;
                }
                FlipcodeDecomposer._tmpA = vertices[array[num3]];
                FlipcodeDecomposer._tmpB = vertices[array[num2]];
                FlipcodeDecomposer._tmpC = vertices[array[num4]];
                bool flag5 = FlipcodeDecomposer.Snip(vertices, num3, num2, num4, j, array);
                if (flag5)
                {
                    list.Add(new Vertices(3)
                    {
                        FlipcodeDecomposer._tmpA,
                        FlipcodeDecomposer._tmpB,
                        FlipcodeDecomposer._tmpC
                    });
                    int num5 = num2;
                    for (int k = num2 + 1; k < j; k++)
                    {
                        array[num5] = array[k];
                        num5++;
                    }
                    j--;
                    num = 2 * j;
                }
            }
            result = list;
            return(result);
        }
예제 #4
0
        public static List <Vertices> ConvexPartition(Vertices vertices, TriangulationAlgorithm algorithm, bool discardAndFixInvalid, FP tolerance)
        {
            bool            flag = vertices.Count <= 3;
            List <Vertices> result;

            if (flag)
            {
                result = new List <Vertices>
                {
                    vertices
                };
            }
            else
            {
                List <Vertices> list;
                switch (algorithm)
                {
                case TriangulationAlgorithm.Earclip:
                {
                    bool flag2 = vertices.IsCounterClockWise();
                    if (flag2)
                    {
                        Vertices vertices2 = new Vertices(vertices);
                        vertices2.Reverse();
                        list = EarclipDecomposer.ConvexPartition(vertices2, tolerance);
                    }
                    else
                    {
                        list = EarclipDecomposer.ConvexPartition(vertices, tolerance);
                    }
                    break;
                }

                case TriangulationAlgorithm.Bayazit:
                {
                    bool flag3 = !vertices.IsCounterClockWise();
                    if (flag3)
                    {
                        Vertices vertices3 = new Vertices(vertices);
                        vertices3.Reverse();
                        list = BayazitDecomposer.ConvexPartition(vertices3);
                    }
                    else
                    {
                        list = BayazitDecomposer.ConvexPartition(vertices);
                    }
                    break;
                }

                case TriangulationAlgorithm.Flipcode:
                {
                    bool flag4 = !vertices.IsCounterClockWise();
                    if (flag4)
                    {
                        Vertices vertices4 = new Vertices(vertices);
                        vertices4.Reverse();
                        list = FlipcodeDecomposer.ConvexPartition(vertices4);
                    }
                    else
                    {
                        list = FlipcodeDecomposer.ConvexPartition(vertices);
                    }
                    break;
                }

                case TriangulationAlgorithm.Seidel:
                    list = SeidelDecomposer.ConvexPartition(vertices, tolerance);
                    break;

                case TriangulationAlgorithm.SeidelTrapezoids:
                    list = SeidelDecomposer.ConvexPartitionTrapezoid(vertices, tolerance);
                    break;

                case TriangulationAlgorithm.Delauny:
                    list = CDTDecomposer.ConvexPartition(vertices);
                    break;

                default:
                    throw new ArgumentOutOfRangeException("algorithm");
                }
                if (discardAndFixInvalid)
                {
                    for (int i = list.Count - 1; i >= 0; i--)
                    {
                        Vertices polygon = list[i];
                        bool     flag5   = !Triangulate.ValidatePolygon(polygon);
                        if (flag5)
                        {
                            list.RemoveAt(i);
                        }
                    }
                }
                result = list;
            }
            return(result);
        }