public static Comparison <Result> ShowServiceAreaMatchesFirst( IntSet <PartyId> serviceAreaMatches, Comparison <Result> secondOrderComparison) { return(delegate(Result lhs, Result rhs) { int result = 0; // KLUDGE: necessary for type inference :-( bool lhsIsSvcAreaMatch = serviceAreaMatches.Contains(lhs.PartyId); bool rhsIsSvcAreaMatch = serviceAreaMatches.Contains(rhs.PartyId); if (lhsIsSvcAreaMatch == rhsIsSvcAreaMatch) { result = secondOrderComparison(lhs, rhs); } else if (lhsIsSvcAreaMatch) { result = -1; } else if (rhsIsSvcAreaMatch) { result = 1; } return result; }); }
} // VarDecl static void Type() { // Type = SimpleType | ArrayType | RecordType | SetType | PointerType . if (First_SimpleType.Contains(sym.kind)) { SimpleType(); } else if (First_ArrayType.Contains(sym.kind)) { ArrayType(); } else if (First_RecordType.Contains(sym.kind)) { RecordType(); } else if (First_SetType.Contains(sym.kind)) { SetType(); } else if (First_PointerType.Contains(sym.kind)) { PointerType(); } else { ReportError("Invalid Type"); } } // Type
public void complement_with_set_of_different_size_returns_correct_result(IntSet set) { var otherSetType = new BitSetType(10); var y = otherSetType.Of(2, 5, 9); var got = set.Complement(y); foreach (var item in set) { Assert.IsTrue(!got.Contains(item)); } foreach (var item in y) { Assert.IsTrue(got.Contains(item) || set.Contains(item)); } int countToCheck = 1000; foreach (var item in got) { Assert.IsFalse(set.Contains(item)); if (--countToCheck == 0) { break; } } set_is_optimized(got); }
public void adding_existing_values_to_set_does_not_change_set(IntSet x, int value) { x = x.Union(IntSet.Of(value)); int countBeforeValueDuplication = x.Count; Assert.IsTrue(x.Contains(value)); x.Union(IntSet.Of(value)); Assert.IsTrue(x.Contains(value)); Assert.AreEqual(countBeforeValueDuplication, x.Count); }
} // Declaration static void TypeDecl() { // TypeDecl = identifier "=" Type . Accept(IdentSym, "Identifier expected"); Accept(AssignSym, "= expected"); if (First_Type.Contains(sym.kind)) { Type(); } else { ReportError("Type Expected"); } } // TypeDecl
} // PointerType // +++++++++++++++++++++ Main driver function +++++++++++++++++++++++++++++++ public static void Main(string[] args) { // Open input and output files from command line arguments if (args.Length == 0) { Console.WriteLine("Usage: Declarations FileName"); System.Environment.Exit(1); } input = new InFile(args[0]); output = new OutFile(NewFileName(args[0], ".out")); GetChar(); // Lookahead character do { GetSym(); // Lookahead symbol if (First_Mod2Decl.Contains(sym.kind)) { Mod2Decl(); } else { ReportError("Incorrect starting symbol"); // Start to parse from the goal symbol } } while (sym.kind != EOFSym); // if we get back here everything must have been satisfactory Console.WriteLine((errorCnt == 0) ? "Parsed correctly" : ("End of file reached\nError Count: " + errorCnt)); output.Close(); } // Main
public void Remove() { IntSet hashSet = CreateTestHashSet(); hashSet.Remove(1); Assert.IsFalse(hashSet.Contains(1)); }
static void Declaration() { /* Declaration = "TYPE" { TypeDecl SYNC ";" } | "VAR" { Var1Decl SYNC ";" } . */ if (sym.kind == TypeSym) { Accept(TypeSym, "TYPE expected"); while (First_TypeDecl.Contains(sym.kind)) { TypeDecl(); Accept(SemiSym, "; expected."); } } else if (sym.kind == VarSym) { Accept(VarSym, "VAR expected"); while (First_VarDecl.Contains(sym.kind)) { VarDecl(); Accept(SemiSym, "; expected."); } } else { ReportError("Declaration expected"); } } // Declaration
} // FieldLists static void FieldList() { // FieldList = [ IdentList ";" Type ] . if (First_IdentList.Contains(sym.kind)) { IdentList(); Accept(ColonSym, ": expected"); if (First_Type.Contains(sym.kind)) { Type(); } else { ReportError("Invalid Field List"); } } else if (Follow_FieldList.Contains(sym.kind)) { ; } else { ReportError("Invalid Field List"); } } // FieldList
// Non Terminal Functions static void Mod2Decl() { // Mod2Decl = { Declaration } . while (First_Declaration.Contains(sym.kind)) { Declaration(); } }
} // Accept static void CDecls() { while (firstDecList.Contains(sym.kind)) { DecList(); } Accept(EOFSym, "EOF expected"); }
} // Accept static void CDecls() { //Cdecls = { DecList } EOF . while (firstDecList.Contains(sym.kind)) { DecList(); // GetChar(); } } // CDecls
} // Accept static void Mod2Decl() { IntSet temp = new IntSet(typeSym, varSym); while (temp.Contains(sym.kind)) // kind of TypeDecl or VarDec { Declaration(); } }
public static void Main(string [] args) { const int Max = 32000; IntSet uncrossed = new IntSet(Max); // the sieve //bool[] uncrossed = new bool[Max]; int i, n, k, it, iterations, primes = 0; // counters IO.Write("How many iterations? "); iterations = IO.ReadInt(); bool display = iterations == 1; IO.Write("Supply largest number to be tested "); n = IO.ReadInt(); if (n > Max) { IO.Write("n too large, sorry"); System.Environment.Exit(1); } IO.WriteLine("Prime numbers between 2 and " + n); IO.WriteLine("-----------------------------------"); for (it = 1; it <= iterations; it++) { primes = 0; for (i = 2; i <= n; i++) // clear sieve { uncrossed.Incl(i); //uncrossed[k] = true; } for (i = 2; i <= n; i++) // the passes over the sieve { if (uncrossed.Contains(i)) //uncrossed[i] { if (display && primes % 8 == 0) // ensure line not too long { IO.WriteLine(); } primes++; if (display) { IO.Write(i, 6); } k = i; // now cross out multiples of i do { uncrossed.Excl(k); //uncrossed[k] = false; k += i; } while (k <= n); } } if (display) { IO.WriteLine(); } } IO.Write(primes + " primes"); } // main
} // Accept static void Accept(IntSet allowedSet, string errorMessage) { // Checks that lookahead token is in allowedSet if (allowedSet.Contains(sym.kind)) { GetSym(); } else { Abort(errorMessage, sym.val); } } // Accept
} // TypeDecl static void VarDecl() { // VarDecl = IdentList ":" Type . if (First_IdentList.Contains(sym.kind)) { IdentList(); } else { ReportError("IdentList Expected"); } Accept(ColonSym, ": expected"); if (First_Type.Contains(sym.kind)) { Type(); } else { ReportError("Type expected"); } } // VarDecl
static void updateSuggestedBoard(string[,] assignedBoard, int[, ][,] suggestedBoard) { int emptySpots = 0; for (int row = 0; row < 9; row++) { for (int col = 0; col < 9; col++) { if (assignedBoard[row, col] != "..") //if a number is already assinged to that position { suggestedBoard[row, col] = null; emptySpots++; //an empty suggested block } else //find the possible numbers { IntSet currentSet = getCurrentSet(suggestedBoard[row, col]); //what's currently already suggested (now filter this list) IntSet rowSet = getRowSet(assignedBoard, row); IntSet colSet = getColSet(assignedBoard, col); IntSet blockSet = getBlockSet(assignedBoard, row, col); //check the square the number is in //print the block of the (row,col) point // the final set of containing the suggested block IntSet allSet = currentSet.Difference(rowSet.Union(colSet).Union(blockSet)); if (allSet.IsEmpty()) //an empty suggested block { emptySpots++; } //set the block to contain values corresponding to the SET int[,] block = new int[3, 3]; for (int i = 0; i < 3; i++) { for (int j = 0; j < 3; j++) { int numberToCheck = 3 * i + j + 1; if (allSet.Contains(numberToCheck)) //check if number in the suggested set { block[i, j] = numberToCheck; } } } suggestedBoard[row, col] = block; } } } if (emptySpots == 81) //no more suggested spots { suggestedBoardEmpty = true; } }
static void Test(IntSet allowed, IntSet beacons, string errorMessage) { if (allowed.Contains(sym.kind)) { return; } IntSet stopSet = allowed.Union(beacons); while (!stopSet.Contains(sym.kind)) { GetSym(); } } // Test
} // QualIdent static void Subrange() { // Subrange = "[" Constant ".." Constant "]" . Accept(LBracketSym, "[ expected"); if (First_Constant.Contains(sym.kind)) { Constant(); } else { ReportError("Invalid Constant"); } Accept(RangeSym, ".. expected"); if (First_Constant.Contains(sym.kind)) { Constant(); } else { ReportError("Invalid Constant"); } Accept(RBracketSym, "] expected"); } // Subrange
} // ArrayType static void RecordType() { // RecordType = "RECORD" FieldLists "END" . Accept(RecordSym, "RECCORD expected"); if (First_FieldLists.Contains(sym.kind)) { FieldLists(); } else { ReportError("Invalid record Type"); } Accept(EndSym, "END expected"); } // RecordType
} // Type static void SimpleType() { // SimpleType = QualIdent [ Subrange ] | Enumeration | Subrange . if (First_QualIdent.Contains(sym.kind)) { QualIdent(); if (First_Subrange.Contains(sym.kind)) { Subrange(); //else do nothing } } else if (First_Enumeration.Contains(sym.kind)) { Enumeration(); } else if (First_Subrange.Contains(sym.kind)) { Subrange(); } else { ReportError("Invalid Simple Type"); } } // SimpleType
} // RecordType static void FieldLists() { // FieldLists = FieldList { ";" FieldList } . if (First_FieldList.Contains(sym.kind)) { FieldList(); } else { ReportError("Invalid FieldLists"); } while (sym.kind == SemiSym) { GetSym(); if (First_FieldList.Contains(sym.kind)) { FieldList(); } else { ReportError("Invalid FieldLists"); } } } // FieldLists
public void set_has_correct_content_after_adding_value(IntSet set, int value) { MutableIntSet editedSet = set.EditCopy(); Assert.AreEqual(set.Contains(value), editedSet.Contains(value)); editedSet.Add(value); Assert.IsTrue(editedSet.Contains(value)); Assert.IsTrue(editedSet.Contains(value)); Assert.IsTrue(set.Union(IntSet.Of(value)).SetEquals(editedSet)); IntSet result = editedSet.CompleteAndDestroy(); Assert.IsTrue(result.Contains(value)); Assert.IsTrue(set.IsSubsetOf(result)); Assert.IsTrue(set.Union(IntSet.Of(value)).SetEquals(result)); }
} // Accept static void CDecls(IntSet followers) { // Cdecls = { DecList } EOF . if (FirstCdecls.Contains(sym.kind)) { while (FirstDecList.Contains(sym.kind)) { DecList(followers.Union(FollowDecList)); } Accept(EOFSym, "EOF expected"); } else { ReportError("Error occured in Production Rule: CDecls"); } } // CDecls
public void Intersect(IntSet array) { int capacity = GetCapacity(); size = 0; for (int i = 0; i < capacity; i++) { if (lookup[i] >= 0 && array.Contains(i)) { lookup[i] = 0; size++; } else { lookup[i] = -1; } } dirty = true; }
public void complement_returns_correct_result(IntSet set) { var got = set.Complement(); foreach (var item in set) { Assert.IsTrue(!got.Contains(item)); } int countToCheck = 1000; foreach (var item in got) { Assert.IsFalse(set.Contains(item)); if (--countToCheck == 0) { break; } } set_is_optimized(got); }
public void Contains() { IntSet hashSet = CreateTestHashSet(); Assert.IsTrue(hashSet.Contains(1)); }
public void TestEverything() { IntSet intSet; IEnumerator<IntSet.Range> ranges; int index; // {3-5} - {4} = {3,5} intSet = new IntSet(); intSet.AddRange(3, 5); intSet.Remove(4); Assert.True(intSet.Count == 2); ranges = intSet.Ranges.GetEnumerator(); ranges.MoveNext(); Assert.True(ranges.Current.Min == 3 && ranges.Current.Max == 3 && ranges.Current.PreviousItemsCount == 0); ranges.MoveNext(); Assert.True(ranges.Current.Min == 5 && ranges.Current.Max == 5 && ranges.Current.PreviousItemsCount == 1); Verify(intSet); // {3,5} + {4} = {3-5} intSet.Add(4); Assert.True(intSet.Count == 3); ranges = intSet.Ranges.GetEnumerator(); ranges.MoveNext(); Assert.True(ranges.Current.Min == 3 && ranges.Current.Max == 5 && ranges.Current.PreviousItemsCount == 0); Assert.False(ranges.MoveNext()); Verify(intSet); // {3-5} + {6-9} = {3-9} intSet.AddRange(6, 9); Assert.True(intSet.Count == 7); ranges = intSet.Ranges.GetEnumerator(); ranges.MoveNext(); Assert.True(ranges.Current.Min == 3 && ranges.Current.Max == 9 && ranges.Current.PreviousItemsCount == 0); Assert.False(ranges.MoveNext()); Verify(intSet); // {3-9} - {4} - {5} - {3} = {6-9} intSet.Remove(4); intSet.Remove(5); intSet.Remove(3); Assert.True(intSet.Count == 4); ranges = intSet.Ranges.GetEnumerator(); ranges.MoveNext(); Assert.True(ranges.Current.Min == 6 && ranges.Current.Max == 9 && ranges.Current.PreviousItemsCount == 0); Assert.False(ranges.MoveNext()); Verify(intSet); // {6-9} + {13-13} + {11} + {10-12} = {6-13} intSet.AddRange(13, 13); intSet.Add(11); Assert.True(intSet.Contains(6)); Assert.True(intSet.Contains(7)); Assert.True(intSet.Contains(8)); Assert.True(intSet.Contains(9)); Assert.True(intSet.Contains(11)); Assert.True(intSet.Contains(13)); Assert.True(intSet.Contains(6, out index) && index == 0); Assert.True(intSet.Contains(7, out index) && index == 1); Assert.True(intSet.Contains(8, out index) && index == 2); Assert.True(intSet.Contains(9, out index) && index == 3); Assert.True(intSet.Contains(11, out index) && index == 4); Assert.True(intSet.Contains(13, out index) && index == 5); Assert.False(intSet.Contains(5)); Assert.False(intSet.Contains(14)); Assert.False(intSet.Contains(10)); Assert.False(intSet.Contains(12)); intSet.AddRange(10, 12); Assert.True(intSet.Contains(6)); Assert.True(intSet.Contains(7)); Assert.True(intSet.Contains(8)); Assert.True(intSet.Contains(9)); Assert.True(intSet.Contains(10)); Assert.True(intSet.Contains(11)); Assert.True(intSet.Contains(12)); Assert.True(intSet.Contains(13)); Assert.False(intSet.Contains(5)); Assert.False(intSet.Contains(14)); Assert.True(intSet.Count == 8); ranges = intSet.Ranges.GetEnumerator(); ranges.MoveNext(); Assert.True(ranges.Current.Min == 6 && ranges.Current.Max == 13 && ranges.Current.PreviousItemsCount == 0); Assert.False(ranges.MoveNext()); Verify(intSet); // {6-13} - {6-12} = {13} intSet.RemoveRange(6, 12); Assert.True(intSet.Count == 1); Assert.True(intSet.Contains(13)); ranges = intSet.Ranges.GetEnumerator(); ranges.MoveNext(); Assert.True(ranges.Current.Min == 13 && ranges.Current.Max == 13 && ranges.Current.PreviousItemsCount == 0); Assert.False(ranges.MoveNext()); Verify(intSet); // {13} - {13-13} = {} intSet.RemoveRange(13, 13); Assert.True(intSet.Count == 0); Assert.False(intSet.Contains(13)); ranges = intSet.Ranges.GetEnumerator(); Assert.False(ranges.MoveNext()); Verify(intSet); // {} + {5-9} - {6-7} = {5,8-9} intSet.AddRange(5, 9); intSet.RemoveRange(6, 7); Assert.True(intSet.Count == 3); ranges = intSet.Ranges.GetEnumerator(); ranges.MoveNext(); Assert.True(ranges.Current.Min == 5 && ranges.Current.Max == 5 && ranges.Current.PreviousItemsCount == 0); ranges.MoveNext(); Assert.True(ranges.Current.Min == 8 && ranges.Current.Max == 9 && ranges.Current.PreviousItemsCount == 1); Assert.False(ranges.MoveNext()); Verify(intSet); // test Clear() intSet.Clear(); Verify(intSet); // randomly add and remove Random rnd = new Random(0); for (int i = 0; i < 1000; i++) { int one; int begin; int end; begin = rnd.Next(0, 100); end = begin + rnd.Next(0, 7); intSet.AddRange(begin, end); one = rnd.Next(0, 100); intSet.Add(one); begin = rnd.Next(0, 100); end = begin + rnd.Next(0, 7); intSet.RemoveRange(begin, end); one = rnd.Next(0, 100); intSet.Remove(one); Verify(intSet); } // test locking intSet.Lock(); Assert.Throws<NotSupportedException>(delegate { intSet.Add(20); }); Assert.Throws<NotSupportedException>(delegate { intSet.AddRange(20, 20); }); Assert.Throws<NotSupportedException>(delegate { intSet.Remove(6); }); Assert.Throws<NotSupportedException>(delegate { intSet.RemoveRange(1, 20); }); Verify(intSet); }
public void TestEverything() { IntSet intSet; IEnumerator <IntSet.Range> ranges; int index; // {3-5} - {4} = {3,5} intSet = new IntSet(); intSet.AddRange(3, 5); intSet.Remove(4); Assert.True(intSet.Count == 2); ranges = intSet.Ranges.GetEnumerator(); ranges.MoveNext(); Assert.True(ranges.Current.Min == 3 && ranges.Current.Max == 3 && ranges.Current.PreviousItemsCount == 0); ranges.MoveNext(); Assert.True(ranges.Current.Min == 5 && ranges.Current.Max == 5 && ranges.Current.PreviousItemsCount == 1); Verify(intSet); // {3,5} + {4} = {3-5} intSet.Add(4); Assert.True(intSet.Count == 3); ranges = intSet.Ranges.GetEnumerator(); ranges.MoveNext(); Assert.True(ranges.Current.Min == 3 && ranges.Current.Max == 5 && ranges.Current.PreviousItemsCount == 0); Assert.False(ranges.MoveNext()); Verify(intSet); // {3-5} + {6-9} = {3-9} intSet.AddRange(6, 9); Assert.True(intSet.Count == 7); ranges = intSet.Ranges.GetEnumerator(); ranges.MoveNext(); Assert.True(ranges.Current.Min == 3 && ranges.Current.Max == 9 && ranges.Current.PreviousItemsCount == 0); Assert.False(ranges.MoveNext()); Verify(intSet); // {3-9} - {4} - {5} - {3} = {6-9} intSet.Remove(4); intSet.Remove(5); intSet.Remove(3); Assert.True(intSet.Count == 4); ranges = intSet.Ranges.GetEnumerator(); ranges.MoveNext(); Assert.True(ranges.Current.Min == 6 && ranges.Current.Max == 9 && ranges.Current.PreviousItemsCount == 0); Assert.False(ranges.MoveNext()); Verify(intSet); // {6-9} + {13-13} + {11} + {10-12} = {6-13} intSet.AddRange(13, 13); intSet.Add(11); Assert.True(intSet.Contains(6)); Assert.True(intSet.Contains(7)); Assert.True(intSet.Contains(8)); Assert.True(intSet.Contains(9)); Assert.True(intSet.Contains(11)); Assert.True(intSet.Contains(13)); Assert.True(intSet.Contains(6, out index) && index == 0); Assert.True(intSet.Contains(7, out index) && index == 1); Assert.True(intSet.Contains(8, out index) && index == 2); Assert.True(intSet.Contains(9, out index) && index == 3); Assert.True(intSet.Contains(11, out index) && index == 4); Assert.True(intSet.Contains(13, out index) && index == 5); Assert.False(intSet.Contains(5)); Assert.False(intSet.Contains(14)); Assert.False(intSet.Contains(10)); Assert.False(intSet.Contains(12)); intSet.AddRange(10, 12); Assert.True(intSet.Contains(6)); Assert.True(intSet.Contains(7)); Assert.True(intSet.Contains(8)); Assert.True(intSet.Contains(9)); Assert.True(intSet.Contains(10)); Assert.True(intSet.Contains(11)); Assert.True(intSet.Contains(12)); Assert.True(intSet.Contains(13)); Assert.False(intSet.Contains(5)); Assert.False(intSet.Contains(14)); Assert.True(intSet.Count == 8); ranges = intSet.Ranges.GetEnumerator(); ranges.MoveNext(); Assert.True(ranges.Current.Min == 6 && ranges.Current.Max == 13 && ranges.Current.PreviousItemsCount == 0); Assert.False(ranges.MoveNext()); Verify(intSet); // {6-13} - {6-12} = {13} intSet.RemoveRange(6, 12); Assert.True(intSet.Count == 1); Assert.True(intSet.Contains(13)); ranges = intSet.Ranges.GetEnumerator(); ranges.MoveNext(); Assert.True(ranges.Current.Min == 13 && ranges.Current.Max == 13 && ranges.Current.PreviousItemsCount == 0); Assert.False(ranges.MoveNext()); Verify(intSet); // {13} - {13-13} = {} intSet.RemoveRange(13, 13); Assert.True(intSet.Count == 0); Assert.False(intSet.Contains(13)); ranges = intSet.Ranges.GetEnumerator(); Assert.False(ranges.MoveNext()); Verify(intSet); // {} + {5-9} - {6-7} = {5,8-9} intSet.AddRange(5, 9); intSet.RemoveRange(6, 7); Assert.True(intSet.Count == 3); ranges = intSet.Ranges.GetEnumerator(); ranges.MoveNext(); Assert.True(ranges.Current.Min == 5 && ranges.Current.Max == 5 && ranges.Current.PreviousItemsCount == 0); ranges.MoveNext(); Assert.True(ranges.Current.Min == 8 && ranges.Current.Max == 9 && ranges.Current.PreviousItemsCount == 1); Assert.False(ranges.MoveNext()); Verify(intSet); // test Clear() intSet.Clear(); Verify(intSet); // randomly add and remove Random rnd = new Random(0); for (int i = 0; i < 1000; i++) { int one; int begin; int end; begin = rnd.Next(0, 100); end = begin + rnd.Next(0, 7); intSet.AddRange(begin, end); one = rnd.Next(0, 100); intSet.Add(one); begin = rnd.Next(0, 100); end = begin + rnd.Next(0, 7); intSet.RemoveRange(begin, end); one = rnd.Next(0, 100); intSet.Remove(one); Verify(intSet); } // test locking intSet.Lock(); Assert.Throws <NotSupportedException>(delegate { intSet.Add(20); }); Assert.Throws <NotSupportedException>(delegate { intSet.AddRange(20, 20); }); Assert.Throws <NotSupportedException>(delegate { intSet.Remove(6); }); Assert.Throws <NotSupportedException>(delegate { intSet.RemoveRange(1, 20); }); Verify(intSet); }
/// <summary> /// Clips the mesh with the given plane. /// The part on the positive hals will remain. /// Will return null when everything is clipped. /// Cap-faces will be built on everything that is cut open by the plane (non-convex cap faces are not handled properly). /// Only works for meshes without Face-/FaceVertexAttributes -> attributes will be invalid for generated faces. /// </summary> public PolyMesh ClipByPlane(Plane3d plane, double epsilon = 1e-7) { var clippedMesh = SplitOnPlane(plane, epsilon).Item2; // in case everything is clipped away if (clippedMesh == null) { return(null); } // 1. go trough all edges // 2. if edge on plane -> test if there is an open face along the plane (border edges) var vertexOnPlane = clippedMesh.PositionArray.Map(clippedMesh.VertexCount, p => plane.Height(p).Abs() <= epsilon); clippedMesh.BuildTopology(); // use indices so an edge can be removed no matter what "ref" var edges = new IntSet(clippedMesh.EdgeCount); foreach (var e in clippedMesh.Edges) { if (e.IsValid) { edges.Add(e.Index); } } var capFaceEdges = new List <PolyMesh.Edge>(); var capFaceEdgeSet = new IntSet(); while (edges.Count > 0) { var e = clippedMesh.GetEdge(edges.First()); edges.Remove(e.Index); if (e.IsAnyBorder && vertexOnPlane[e.FromVertexIndex] && vertexOnPlane[e.ToVertexIndex]) { // try to find other edges along the plane // keep set of all edges so in case there the loop runs into a degenerated case an exit is possible (will generate degenerated face) capFaceEdges.Clear(); capFaceEdgeSet.Clear(); var currEdge = e; do { if (currEdge.IsValid) { capFaceEdges.Add(currEdge); capFaceEdgeSet.Add(currEdge.Index); } // find next edge at start-vertex along plane // the new cap face should have winding order start<-to becaues it is on the opposite of the current face-edge currEdge = currEdge.FromVertex.Edges .Select(x => x.FromVertexIndex == currEdge.FromVertexIndex ? x.Opposite : x) .FirstOrDefault(x => x.IsAnyBorder && x.Index != currEdge.Index && vertexOnPlane[x.FromVertexIndex], PolyMesh.Edge.Invalid); } while (currEdge.IsValid && currEdge.Index != e.Index && !capFaceEdgeSet.Contains(currEdge.Index)); if (capFaceEdges.Count > 2) { // add cap-face foreach (var fe in capFaceEdges.Skip(1)) { edges.Remove(fe.Index); } clippedMesh.AddFace(capFaceEdges.Select(fe => fe.ToVertexIndex).ToArray()); } } } // clear topology (is invalid if face has been added) clippedMesh.ClearTopology(); return(clippedMesh); }
private void ExtendAutomatonWithLiteral(string literal, int scanAction) { var state = data.Start; var symbols = EnumerateLiteralSymbols(data.Alphabet, literal).GetEnumerator(); bool hasSymbol; // trace and do nothing while ((hasSymbol = symbols.MoveNext())) { State next = Control(state, symbols.Current); if (next == NoState || ambiguous.Contains(next)) { break; } state = next; } int previous = state; // trace and duplicate the path while (hasSymbol) { State next = Control(state, symbols.Current); if (next != NoState) { state = next; var newStateInfo = new TdfaState(data); int newState = data.AddState(newStateInfo); data.DeleteTransition(from: previous, symbol: symbols.Current); data.AddTransition( from: previous, symbol: symbols.Current, to: newState ); var S = data.GetState(state); newStateInfo.IsAccepting = S.IsAccepting; newStateInfo.Actions.AddRange(S.Actions); newStateInfo.Tunnel = state; previous = newState; hasSymbol = symbols.MoveNext(); } else { var S = data.GetState(state); if (S.Tunnel == NoState) { break; } state = S.Tunnel; } } // extend the path for (; hasSymbol; hasSymbol = symbols.MoveNext()) { var newStateInfo = new TdfaState(data); int newState = data.AddState(newStateInfo); data.AddTransition( from: previous, symbol: symbols.Current, to: newState ); newStateInfo.Tunnel = NoState; previous = newState; } // process new final state var finalState = data.GetState(previous); finalState.IsAccepting = true; finalState.Actions.Insert(0, scanAction); }