示例#1
0
        static private Slice2D SingleSlice(Polygon2D polygon, Pair2D slice)
        {
            Slice2D result = Slice2D.Create(null, slice);

            if (Vector2D.Distance(slice.A, slice.B) < 0.001f)
            {
                Debug.LogWarning("Slicer2D: Slice is too short");

                return(result);
            }

            Vector2D vertexToIntersection = VertexToIntersection.Get(polygon, slice);

            if (vertexToIntersection != null)
            {
                return(VertexToIntersection.Slice(polygon, slice, vertexToIntersection));
            }

            if ((polygon.PointInPoly(slice.A) || polygon.PointInPoly(slice.B)))                 //  && pointsInHoles == 1
            {
                Debug.LogWarning("Slicer2D: Incorrect Split: Code 1 (One point is inside Vertice?)" + " " + slice.ToString());

                // Slicing through hole cut-out
                return(result);
            }


            Polygon2D holeA = polygon.PointInHole(slice.A);
            Polygon2D holeB = polygon.PointInHole(slice.B);

            int pointsInHoles = Convert.ToInt32(holeA != null) + Convert.ToInt32(holeB != null);

            if (pointsInHoles == 2 && holeA == holeB)
            {
                pointsInHoles = 1;
            }

            switch (pointsInHoles)
            {
            case 0:
                return(SliceWithoutHoles.Slice(polygon, slice));

            case 1:
                return(SliceWithOneHole.Slice(polygon, slice, holeA, holeB));

            case 2:
                return(SliceWithTwoHoles.Slice(polygon, slice, holeA, holeB));

            default:
                break;
            }

            return(result);
        }
示例#2
0
        static private Slice2D SingleSlice(Polygon2D polygon, ComplexSlicerSplit split)
        {
            Slice2D result = Slice2D.Create(null, split.points);

            // Change
            if (Slicer2D.complexSliceType == Slicer2D.SliceType.Regular)
            {
                if (Math2D.SliceIntersectItself(split.points))
                {
                    if (Slicer2D.Debug.enabled)
                    {
                        Debug.LogWarning("Slicer2D: Slice Intersect Itself In Regular Mode");
                    }
                    return(result);
                }
            }

            // Start and End of slice should be outside the polygon
            if (polygon.PointInPoly(split.points.First()) == true || polygon.PointInPoly(split.points.Last()) == true)
            {
                return(result);
            }

            List <Vector2D> slice = new List <Vector2D> (split.points);

            if (split.type == ComplexSlicerSplit.Type.SingleVertexCollision)
            {
                Debug.Log("Single Vertex Collision");

                return(result);
            }

            ComplexCollision collisionSlice = new ComplexCollision(polygon, slice);

            if (collisionSlice.error)
            {
                if (Slicer2D.Debug.enabled)
                {
                    Debug.LogWarning("Slicer2D: Complex Collision Error");
                }
                return(result);
            }

            List <Polygon2D> intersectHoles = polygon.GetListSliceIntersectHoles(slice);

            switch (intersectHoles.Count)
            {
            case 0:
                if (collisionSlice.collisionCount == 2)
                {
                    return(SliceWithoutHoles.Slice(polygon, slice, collisionSlice));
                }
                break;

            case 1:
                return(SliceWithOneHole.Slice(polygon, slice, collisionSlice));

            case 2:
                return(SliceWithTwoHoles.Slice(polygon, slice, collisionSlice));

            default:
                break;
            }

            return(result);
        }