/// <summary> /// Removes the element from the list. /// </summary> internal void Remove(SimplexConnector <VERTEX> connector) { if (connector.Previous != null) { connector.Previous.Next = connector.Next; } else if (connector.Previous == null) { this.first = connector.Next; } if (connector.Next != null) { connector.Next.Previous = connector.Previous; } else if (connector.Next == null) { this.last = connector.Previous; } connector.Next = null; connector.Previous = null; }
internal void DepositConnector(SimplexConnector <VERTEX> connector) { connector.Face = null; connector.Previous = null; connector.Next = null; ConnectorStack.Push(connector); }
/// <summary> /// Adds a face to the list. /// </summary> internal void Add(SimplexConnector <VERTEX> element) { if (this.last != null) { this.last.Next = element; } element.Previous = this.last; this.last = element; if (this.first == null) { this.first = element; } }
/// <summary> /// Connect faces using a connector. /// </summary> private void ConnectFace(SimplexConnector <VERTEX> connector) { var index = connector.HashCode % Buffer.CONNECTOR_TABLE_SIZE; var list = Buffer.ConnectorTable[index]; for (var current = list.First; current != null; current = current.Next) { if (SimplexConnector <VERTEX> .AreConnectable(connector, current, Dimension)) { list.Remove(current); SimplexConnector <VERTEX> .Connect(current, connector); Buffer.ObjectManager.DepositConnector(current); Buffer.ObjectManager.DepositConnector(connector); return; } } list.Add(connector); }
/// <summary> /// Can two faces be connected. /// </summary> internal static bool AreConnectable(SimplexConnector <VERTEX> a, SimplexConnector <VERTEX> b, int dim) { if (a.HashCode != b.HashCode) { return(false); } var n = dim - 1; var av = a.Vertices; var bv = b.Vertices; for (int i = 0; i < n; i++) { if (av[i] != bv[i]) { return(false); } } return(true); }
/// <summary> /// Connect two faces. /// </summary> internal static void Connect(SimplexConnector <VERTEX> a, SimplexConnector <VERTEX> b) { a.Face.AdjacentFaces[a.EdgeIndex] = b.Face; b.Face.AdjacentFaces[b.EdgeIndex] = a.Face; }
/// <summary> /// Commits a cone and adds a vertex to the convex hull. /// </summary> private void CommitCone() { // Add the current vertex. Vertices.Add(Buffer.CurrentVertex); // Fill the adjacency. for (int i = 0; i < Buffer.ConeFaceBuffer.Count; i++) { DeferredSimplex <VERTEX> face = Buffer.ConeFaceBuffer[i]; SimplexWrap <VERTEX> newFace = face.Face; SimplexWrap <VERTEX> adjacentFace = face.Pivot; SimplexWrap <VERTEX> oldFace = face.OldFace; int orderedPivotIndex = face.FaceIndex; newFace.AdjacentFaces[orderedPivotIndex] = adjacentFace; adjacentFace.AdjacentFaces[face.PivotIndex] = newFace; // let there be a connection. for (int j = 0; j < Dimension; j++) { if (j == orderedPivotIndex) { continue; } SimplexConnector <VERTEX> connector = Buffer.ObjectManager.GetConnector(); connector.Update(newFace, j, Dimension); ConnectFace(connector); } // This could slightly help... if (adjacentFace.VerticesBeyond.Count < oldFace.VerticesBeyond.Count) { FindBeyondVertices(newFace, adjacentFace.VerticesBeyond, oldFace.VerticesBeyond); } else { FindBeyondVertices(newFace, oldFace.VerticesBeyond, adjacentFace.VerticesBeyond); } // This face will definitely lie on the hull if (newFace.VerticesBeyond.Count == 0) { Buffer.ConvexSimplexs.Add(newFace); Buffer.UnprocessedFaces.Remove(newFace); Buffer.ObjectManager.DepositVertexBuffer(newFace.VerticesBeyond); newFace.VerticesBeyond = Buffer.EmptyBuffer; } else // Add the face to the list { Buffer.UnprocessedFaces.Add(newFace); } // recycle the object. Buffer.ObjectManager.DepositDeferredSimplex(face); } // Recycle the affected faces. for (int fIndex = 0; fIndex < Buffer.AffectedFaceBuffer.Count; fIndex++) { var face = Buffer.AffectedFaceBuffer[fIndex]; Buffer.UnprocessedFaces.Remove(face); Buffer.ObjectManager.DepositFace(face); } }
/// <summary> /// Adds the element to the beginning. /// </summary> void AddFirst(SimplexConnector <VERTEX> connector) { this.first.Previous = connector; connector.Next = this.first; this.first = connector; }
internal void Clear() { first = null; last = null; }