private void RemoveCloseBlockNodes(Block block) { List <int> toBeRemovedIndexes = new List <int>(); for (int i = 0; i < block.Nodes.Count; i++) { int nextIdx = i == block.Nodes.Count - 1 ? 0 : i + 1; BlockNode currentNode = block.Nodes[i]; BlockNode nextNode = block.Nodes[nextIdx]; if (currentNode.Equals(nextNode)) { toBeRemovedIndexes.Add(i); } } for (int i = toBeRemovedIndexes.Count - 1; i >= 0; i--) { block.Nodes.RemoveAt(toBeRemovedIndexes[i]); } }