private void SecondPass(State state) { int set = 0; int index = 0; var lookupShape = default(Shape <TNode, TPosition, TKey>); var shape = default(Shape <TNode, TPosition, TKey>); var node = default(TNode); var tesselationSurroundEnumerable = default(IEnumerable <TPosition>); var tesselationSurroundEnumerator = default(IEnumerator <TPosition>); var neighbor = default(TPosition); for (int shapeIndex = state.Shapes.Count - 1; shapeIndex >= 0; shapeIndex--) { shape = state.Shapes[shapeIndex]; for (int nodeIndex = shape.Nodes.Count - 1; nodeIndex >= 0; nodeIndex--) { set = 0; index = 0; node = shape.Nodes[nodeIndex]; tesselationSurroundEnumerable = Tesselation.Surround(node.Point); tesselationSurroundEnumerator = tesselationSurroundEnumerable.GetEnumerator(); while (tesselationSurroundEnumerator.MoveNext()) { neighbor = tesselationSurroundEnumerator.Current; if (Tesselation.Valid(neighbor)) { lookupShape = state.GetShape(neighbor); } else { lookupShape = null; } set *= 2; if (lookupShape != shape) { set++; } node[index++] = lookupShape != null ? lookupShape.Area : null; } tesselationSurroundEnumerator.Dispose(); if (CollisionGenerator.OuterNode(set)) { shape.AddOuterNode(node); } } } }
private void FirstPass(State state) { var skippedPoints = new HashSet <TPosition>(PositionComparer) { default(TPosition) }; var activePoints = new HashSet <TPosition>(PositionComparer); var newActivePoints = new HashSet <TPosition>(PositionComparer); var inactivePoints = new HashSet <TPosition>(PositionComparer); var index = 0; var testIndex = 0; var reference = default(TPosition); var key = default(TKey); var shape = default(Shape <TNode, TPosition, TKey>); while (skippedPoints.Count > 0) { reference = GetReference(skippedPoints); key = Tesselation.Key(reference); shape = state.CreateShape(key); activePoints.Clear(); activePoints.Add(reference); while (activePoints.Count > 0) { newActivePoints.Clear(); foreach (var v in activePoints) { skippedPoints.Remove(v); inactivePoints.Add(v); state.AddNodeToShape(shape, NodeFactory, v); index = 0; foreach (var vs in Tesselation.Surround(v)) { testIndex = index++; if (Tesselation.Valid(vs) && Tesselation.Tesselate(testIndex) && !(newActivePoints.Contains(vs) || inactivePoints.Contains(vs))) { if (KeyComparer.Equals(key, Tesselation.Key(vs))) { newActivePoints.Add(vs); } else { skippedPoints.Add(vs); } } } } activePoints.Clear(); foreach (var item in newActivePoints) { activePoints.Add(item); } } } }