Пример #1
0
 public IEnumerable<ValidRectanglePosition> ValidPositions()
 {
     foreach (List<PossibleRectanglePosition> many in positions.Values) {
         foreach (var pair in many.SelectMany ((value, index) => many.Skip (index + 1),
         (first, second) => new { first, second })) {
             List<PossibleRectanglePosition> pos
                 = new PossibleRectanglePosition[] { pair.first, pair.second } .ToList ();
             if (pos.Count == 2) {
                 for (int i = 0; i <= 1; ++i) {
                     int first = i % 2;
                     int second = (i + 1) % 2;
                     Edge edgeAB = pos [first].Edge;
                     Edge edgeCD = pos [second].Edge;
                     Node nodeA = pos [first].NodeA;
                     Node nodeB = pos [first].NodeB;
                     Node nodeC = pos [second].NodeA;
                     Node nodeD = pos [second].NodeB;
                     if (nodeB == nodeC || (nodeA-nodeB) == (nodeC-nodeD)) {
                         var valid = new ValidRectanglePosition {
                             EdgeAB = edgeAB,
                             EdgeCD = edgeCD,
                             NodeA = nodeA,
                             NodeB = nodeB,
                             NodeC = nodeC,
                             NodeD = nodeD,
                             Position = pos [first].Position,
                             IsVirtual = pos [first].IsVirtual || pos [second].IsVirtual
                         };
                         yield return valid;
                     }
                 }
             }
         }
     }
 }
Пример #2
0
 public void AddEdge(Edge edge, Node nodeA, Node nodeB, bool isVirtual)
 {
     Vector3 edgeCenter = nodeA.CenterBetween (nodeB);
     foreach (Direction direction in Direction.Values) {
         if (direction.Axis != edge.Direction.Axis) {
             Vector3 rectangleCenter = edgeCenter + direction * Node.Scale / 2;
             PossibleRectanglePosition rectanglePosition = new PossibleRectanglePosition {
                 Edge = edge,
                 NodeA = nodeA,
                 NodeB = nodeB,
                 Position = rectangleCenter,
                 IsVirtual = isVirtual
             };
             positions.Add (rectangleCenter, rectanglePosition);
         }
     }
 }