Beispiel #1
0
        private static List <Vertices> Execute(Vertices subject, Vertices clip, PolyClipType clipType, out PolyClipError error)
        {
            Debug.Assert(subject.IsSimple() && clip.IsSimple(), "Non simple input!", "Input polygons must be simple (cannot intersect themselves).");
            Vertices vertices;
            Vertices vertices2;

            YuPengClipper.CalculateIntersections(subject, clip, out vertices, out vertices2);
            TSVector2 lowerBound  = subject.GetAABB().LowerBound;
            TSVector2 lowerBound2 = clip.GetAABB().LowerBound;
            TSVector2 tSVector;

            TSVector2.Min(ref lowerBound, ref lowerBound2, out tSVector);
            tSVector = TSVector2.one - tSVector;
            bool flag = tSVector != TSVector2.zero;

            if (flag)
            {
                vertices.Translate(ref tSVector);
                vertices2.Translate(ref tSVector);
            }
            vertices.ForceCounterClockWise();
            vertices2.ForceCounterClockWise();
            List <FP> poly1Coeff;
            List <YuPengClipper.Edge> poly1Simplicies;

            YuPengClipper.CalculateSimplicalChain(vertices, out poly1Coeff, out poly1Simplicies);
            List <FP> poly2Coeff;
            List <YuPengClipper.Edge> poly2Simplicies;

            YuPengClipper.CalculateSimplicalChain(vertices2, out poly2Coeff, out poly2Simplicies);
            List <YuPengClipper.Edge> simplicies;

            YuPengClipper.CalculateResultChain(poly1Coeff, poly1Simplicies, poly2Coeff, poly2Simplicies, clipType, out simplicies);
            List <Vertices> list;

            error     = YuPengClipper.BuildPolygonsFromChain(simplicies, out list);
            tSVector *= -1f;
            for (int i = 0; i < list.Count; i++)
            {
                list[i].Translate(ref tSVector);
                SimplifyTools.CollinearSimplify(list[i], FP.Zero);
            }
            return(list);
        }