Exemplo n.º 1
0
        public CellPairCollection <T> FollowBoundaryAndCollectCandidates(IEnumerable <Edge <T> > periodicEdges)
        {
            LinkedListDictionary <int, List <Edge <T> > > edges = DivideIntoBoundaries(periodicEdges);

            Debug.Assert(edges.Count % 2 == 0);
            CellPairCollection <T> candidates = new CellPairCollection <T>();


            while (edges.Count > 0)
            {
                List <Edge <T> > boundary = edges.First().Value;
                int        boundaryNumber = edges.First().Key;
                Position[] positions      = new Position[boundary.Count];
                for (int i = 0; i < boundary.Count; ++i)
                {
                    Edge <T> edge = boundary[i];
                    if (NodeIsOnRightSideOfEdge(edge.Cell.Node, edge))
                    {
                        if (edge.Twin.Cell.Node != null && NodeIsOnRightSideOfEdge(edge.Twin.Cell.Node, edge))
                        {
                            positions[i] = Position.right;
                            candidates.AddOuterSplitCell(edge.Cell, edge.BoundaryEdgeNumber);
                        }
                        else
                        {
                            positions[i] = Position.rightUnsplit;
                            candidates.AddOuterUnsplitCell(edge.Cell, edge.BoundaryEdgeNumber);
                        }
                    }
                    else
                    {
                        if (edge.Twin.Cell.Node != null && !NodeIsOnRightSideOfEdge(edge.Twin.Cell.Node, edge))
                        {
                            positions[i] = Position.left;
                            candidates.AddInnerSplitCell(edge.Cell, edge.BoundaryEdgeNumber);
                        }
                        else
                        {
                            positions[i] = Position.leftUnsplit;
                            candidates.AddInnerUnsplitCell(edge.Cell, edge.BoundaryEdgeNumber);
                        }
                    }
                }
                edges.Remove(boundaryNumber);

                boundaryNumber = map.PeriodicBoundaryCorrelation[boundaryNumber];
                boundary       = edges[boundaryNumber];
                for (int i = 0; i < boundary.Count; ++i)
                {
                    Edge <T> edge = boundary[i];
                    switch (positions[boundary.Count - 1 - i])
                    {
                    case Position.left:
                        candidates.AddOuterSplitCell(edge.Cell, edge.BoundaryEdgeNumber);
                        break;

                    case Position.right:
                        candidates.AddInnerSplitCell(edge.Cell, edge.BoundaryEdgeNumber);
                        break;

                    case Position.leftUnsplit:
                        candidates.AddOuterUnsplitCell(edge.Cell, edge.BoundaryEdgeNumber);
                        break;

                    case Position.rightUnsplit:
                        candidates.AddInnerUnsplitCell(edge.Cell, edge.BoundaryEdgeNumber);
                        break;

                    default:
                        throw new Exception();
                    }
                }
                edges.Remove(boundaryNumber);
            }
            return(candidates);
        }