IEnumerator <Edge <T> > TryCut( ref bool circleCells, IEnumerator <Edge <T> > ridgeEnum, List <BoundaryLine> lines) { IEnumerator <Edge <T> > runningEnum; Edge <T> activeRidge = state.ActiveEdge; //All other cuts and subdivisions etc. //----------------------------------------------------------- switch (state.Case) { case IntersectionCase.NotIntersecting: ridgeEnum.Reset(); break; case IntersectionCase.InMiddle: //if intersection was successfull, select next cell activeRidge = meshIntersecter.Subdivide(activeRidge, lines, state.AlphaCut, boundaryLines.LineIndex()); ridgeEnum = meshIntersecter.GetNeighborFromEdgeNeighbor(activeRidge); break; case IntersectionCase.EndOfLine: activeRidge = meshIntersecter.Subdivide(activeRidge, lines, state.AlphaCut, boundaryLines.LineIndex()); if (boundaryLines.MoveNext()) { lines.Clear(); runningEnum = meshIntersecter.GetConnectedEdgeEnum(activeRidge); (ridgeEnum, state.Case) = edgeCutter.CutOut(runningEnum, activeRidge, state); } else { circleCells = false; } break; case IntersectionCase.EndOfEdge: activeRidge = meshIntersecter.SubdivideWithoutNewVertex(activeRidge, lines, boundaryLines.LineIndex()); runningEnum = meshIntersecter.GetConnectedEdgeEnum(activeRidge); lines.Clear(); (ridgeEnum, state.Case) = edgeCutter.CutOut(runningEnum, activeRidge, state); break; case IntersectionCase.EndOfEdgeAndLine: activeRidge = meshIntersecter.SubdivideWithoutNewVertex(activeRidge, lines, boundaryLines.LineIndex()); if (boundaryLines.MoveNext()) { lines.Clear(); runningEnum = meshIntersecter.GetConnectedEdgeEnum(activeRidge); (ridgeEnum, state.Case) = edgeCutter.CutOut(runningEnum, activeRidge, state); } else { circleCells = false; } break; default: throw new NotImplementedException(); } 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); }