Пример #1
0
        void CutOut()
        {
            IEnumerator <Edge <T> > edgeEnumerator = FirstCellEdgeEnumerator();
            List <BoundaryLine>     lines          = new List <BoundaryLine>(10);

            bool firstCut = true;

            isFirstIntersection = true;

            while (boundaryLines.MoveNext())
            {
                bool circleCells = true;
                while (circleCells)
                {
                    circleCells = false;

                    state.Reset();
                    state.ActiveLine = boundaryLines.Current;

                    //Check for intersection of Cell and Line
                    while (edgeEnumerator.MoveNext() && !circleCells)
                    {
                        circleCells = FindIntersection(edgeEnumerator.Current, state.ActiveLine);
                    }
                    isFirstIntersection = false;

                    //Handle intersection
                    if (firstCut)
                    {
                        if (state.Case != IntersectionCase.NotIntersecting)
                        {
                            firstCut = false;
                            FinishFirstCut(lines);
                        }
                        edgeEnumerator = TryFirstCut(ref circleCells, edgeEnumerator);
                        //Start with empty line set
                    }
                    else
                    {
                        edgeEnumerator = TryCut(ref circleCells, edgeEnumerator, lines);
                    }
                    switch (state.Case)
                    {
                    case IntersectionCase.NotIntersecting:
                        break;

                    case IntersectionCase.InMiddle:
                    case IntersectionCase.StartOfLine:
                    case IntersectionCase.EndOfEdge:
                        lines.Clear();
                        break;

                    case IntersectionCase.EndOfLine:
                    case IntersectionCase.EndOfEdgeAndLine:
                        lines.Clear();
                        circleCells = false;
                        break;

                    default:
                        throw new Exception();
                    }
                }
                lines.Add(state.ActiveLine);
            }
            HandleLastCell(lines);
            boundaryLines.Reset();
            greatDivider.RemoveOutsideCells();
        }
Пример #2
0
        public (IEnumerator <Edge <T> >, IntersectionCase) CutOut(
            IEnumerator <Edge <T> > edgeEnum,
            Edge <T> outerEdge,
            CutterState <Edge <T> > state)
        {
            bool             keepOnRunning    = true;
            Edge <T>         activeEdge       = default(Edge <T>);
            IntersectionCase intersectionCase = IntersectionCase.NotIntersecting;

            while (keepOnRunning)
            {
                keepOnRunning = false;
                double alphaCut = 0;
                state.ActiveLine = boundary.Current;
                while (edgeEnum.MoveNext() && !keepOnRunning)
                {
                    activeEdge    = edgeEnum.Current;
                    keepOnRunning = LineIntersect.Find(activeEdge, state.ActiveLine, ref intersectionCase, out alphaCut);
                    if (alphaCut < LineIntersect.accuracy)
                    {
                        intersectionCase = IntersectionCase.NotIntersecting;
                        keepOnRunning    = false;
                    }
                }
                switch (intersectionCase)
                {
                case IntersectionCase.NotIntersecting:
                case IntersectionCase.InMiddle:
                    //keepOnRunning = false;
                    //IEnumerator<Edge<T>> cellEnum = meshIntersecter.GetAfterCutEdgeEnumerator(state.ActiveEdge.Cell.Edges, state.ActiveEdge);
                    //return (cellEnum, intersectionCase);
                    keepOnRunning = false;
                    break;

                case IntersectionCase.EndOfLine:
                    activeEdge = meshIntersecter.AddLineSegment(activeEdge, alphaCut, boundary.LineIndex());
                    edgeEnum   = meshIntersecter.GetConnectedEdgeEnum(activeEdge);
                    outerEdge  = activeEdge;
                    if (!boundary.MoveNext())
                    {
                        keepOnRunning = false;
                    }
                    break;

                case IntersectionCase.EndOfEdge:
                    meshIntersecter.AddEdge(activeEdge, boundary.LineIndex());
                    edgeEnum = meshIntersecter.GetConnectedEdgeEnum(activeEdge);
                    //edgeEnum.MoveNext();
                    outerEdge = activeEdge;
                    break;

                case IntersectionCase.EndOfEdgeAndLine:
                    meshIntersecter.AddEdge(activeEdge, boundary.LineIndex());
                    edgeEnum  = meshIntersecter.GetConnectedEdgeEnum(activeEdge);
                    outerEdge = activeEdge;
                    if (!boundary.MoveNext())
                    {
                        keepOnRunning = false;
                    }
                    break;

                case IntersectionCase.StartOfLine:
                default:
                    throw new InvalidOperationException();
                }
            }
            MeshIntersecter <T> .AfterCutEdgeEnumerator cellEnumerator = meshIntersecter.GetNeighborFromLineDirection(outerEdge, state.ActiveLine);
            cellEnumerator.Cell.IntersectionVertex = outerEdge.End.ID;
            return(cellEnumerator, intersectionCase);
        }