/// <summary> /// Adds a face to the list. /// </summary> /// <param name="element">The element.</param> public void Add(FaceConnector element) { if (last != null) { last.Next = element; } element.Previous = last; last = element; if (First == null) { First = element; } }
/// <summary> /// Get an unused face connector. If none is available, create it. /// </summary> /// <returns>FaceConnector.</returns> public FaceConnector GetConnector() { if (ConnectorStack == null) { return(new FaceConnector(Dimension)); } var ret = ConnectorStack; ConnectorStack = ConnectorStack.Next; ret.Next = null; return(ret); }
/// <summary> /// Store a face connector in the "embedded" linked list. /// </summary> /// <param name="connector">The connector.</param> public void DepositConnector(FaceConnector connector) { if (ConnectorStack == null) { connector.Next = null; ConnectorStack = connector; } else { connector.Next = ConnectorStack; ConnectorStack = connector; } }
/// <summary> /// Connect faces using a connector. /// </summary> /// <param name="connector">The connector.</param> private void ConnectFace(FaceConnector connector) { var index = connector.HashCode % Constants.ConnectorTableSize; var list = ConnectorTable[index]; for (var current = list.First; current != null; current = current.Next) { if (FaceConnector.AreConnectable(connector, current, NumOfDimensions)) { list.Remove(current); FaceConnector.Connect(current, connector); current.Face = null; connector.Face = null; ObjectManager.DepositConnector(current); ObjectManager.DepositConnector(connector); return; } } list.Add(connector); }
/// <summary> /// Removes the element from the list. /// </summary> /// <param name="connector">The connector.</param> public void Remove(FaceConnector connector) { if (connector.Previous != null) { connector.Previous.Next = connector.Next; } else if (/*first == face*/ connector.Previous == null) { First = connector.Next; } if (connector.Next != null) { connector.Next.Previous = connector.Previous; } else if (/*last == face*/ connector.Next == null) { last = connector.Previous; } connector.Next = null; connector.Previous = null; }
/// <summary> /// Adds the element to the beginning. /// </summary> /// <param name="connector">The connector.</param> private void AddFirst(FaceConnector connector) { First.Previous = connector; connector.Next = First; First = connector; }