IEnumerator <Edge <T> > TryFirstCut(ref bool circleCells, IEnumerator <Edge <T> > ridgeEnum) { IEnumerator <Edge <T> > runningEnum; Edge <T> activeRidge = state.ActiveEdge; //First cut ever //----------------------------------------------------------- switch (state.Case) { case IntersectionCase.NotIntersecting: ridgeEnum.Reset(); break; case IntersectionCase.InMiddle: //if intersection was successfull, select next cell activeRidge = meshIntersecter.FirstCut(activeRidge, state.AlphaCut); ridgeEnum = meshIntersecter.GetNeighborFromEdgeNeighbor(activeRidge); break; case IntersectionCase.StartOfLine: activeRidge = meshIntersecter.FirstCut(activeRidge, state.AlphaCut); runningEnum = meshIntersecter.GetConnectedEdgeEnum(activeRidge); (ridgeEnum, state.Case) = edgeCutter.CutOut(runningEnum, activeRidge, state); break; case IntersectionCase.EndOfLine: activeRidge = meshIntersecter.FirstCut(activeRidge, state.AlphaCut); if (boundaryLines.MoveNext()) { runningEnum = meshIntersecter.GetConnectedEdgeEnum(activeRidge); (ridgeEnum, state.Case) = edgeCutter.CutOut(runningEnum, activeRidge, state); } else { circleCells = false; } break; case IntersectionCase.EndOfEdge: meshIntersecter.VertexCut(activeRidge, state.AlphaCut); runningEnum = meshIntersecter.GetConnectedEdgeEnum(activeRidge); (ridgeEnum, state.Case) = edgeCutter.CutOut(runningEnum, activeRidge, state); break; case IntersectionCase.EndOfEdgeAndLine: meshIntersecter.VertexCut(activeRidge, state.AlphaCut); if (boundaryLines.MoveNext()) { runningEnum = meshIntersecter.GetConnectedEdgeEnum(activeRidge); (ridgeEnum, state.Case) = edgeCutter.CutOut(runningEnum, activeRidge, state); } else { circleCells = false; } break; default: throw new Exception(); } return(ridgeEnum); }
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); }