示例#1
0
        public void EdgeLoops_JoinBySameValue(LinkedList <LinkedLoop <int> > edgeLoops)
        {
            // join by the most close points
            var parrentListsNode = edgeLoops.First;

            while (parrentListsNode != null)
            {
                var  childList  = parrentListsNode.Value;
                bool jointFound = false;

                var listFirstValue = _meshData.Vertices[childList.first.value];
                var listLastValue  = _meshData.Vertices[childList.last.value];

                var joinCandidate = parrentListsNode.Next;
                while (joinCandidate != null)
                {
                    var restFirstValue = _meshData.Vertices[joinCandidate.Value.first.value];
                    var restLastValue  = _meshData.Vertices[joinCandidate.Value.last.value];

                    if ((listLastValue - restFirstValue).sqrMagnitude < MinPointDistanceSqr)
                    {
                        joinCandidate.Value.first.Remove();                        // to avoid duplication of the same index when concatinaiting
                        childList  = LinkedLoop.ConcatList(childList, joinCandidate.Value);
                        jointFound = true;
                        break;
                    }
                    else if ((listFirstValue - restLastValue).sqrMagnitude < MinPointDistanceSqr)
                    {
                        childList.first.Remove();
                        childList  = LinkedLoop.ConcatList(joinCandidate.Value, childList);
                        jointFound = true;
                        break;
                    }

                    joinCandidate = joinCandidate.Next;
                }

                if (jointFound)
                {
                    edgeLoops.Remove(joinCandidate);
                    parrentListsNode.Value = childList;
                }
                else
                {
                    parrentListsNode = parrentListsNode.Next;
                }
            }
        }
        public void RemoveConcat()
        {
            //Arrange
            LinkedLoop <int> list1 = new LinkedLoop <int>();
            LinkedLoop <int> list2 = new LinkedLoop <int>();

            //Act
            list1.AddLast(1);
            list1.AddLast(2);
            list2.AddLast(3);
            list2.AddLast(4);

            LinkedLoop <int> listS = LinkedLoop.ConcatList(list1, list2);

            //Assert
            var item1 = listS.first;
            var item2 = item1.next;
            var item3 = item2.next;
            var item4 = item3.next;

            Assert.AreEqual(4, listS.size);

            Assert.AreEqual(1, item1.value);
            Assert.AreEqual(2, item2.value);
            Assert.AreEqual(3, item3.value);
            Assert.AreEqual(4, item4.value);

            Assert.AreEqual(item1.next, item2);
            Assert.AreEqual(item1.previous, item4);

            Assert.AreEqual(item2.next, item3);
            Assert.AreEqual(item2.previous, item1);

            Assert.AreEqual(item3.next, item4);
            Assert.AreEqual(item3.previous, item2);

            Assert.AreEqual(item4.next, item1);
            Assert.AreEqual(item4.previous, item3);
        }
示例#3
0
        internal void EdgeLoops_JoinBySameValue(LinkedList <LinkedLoop <int> > edgeLoops)
        {
            // join by the most close points
            var parrentListsNode = edgeLoops.First;

            while (parrentListsNode != null)
            {
                var  childList = parrentListsNode.Value;
                bool delete    = false;

                var listFirstValue = _meshData.Vertices[childList.first.value];
                var listLastValue  = _meshData.Vertices[childList.last.value];

                var rest = parrentListsNode.Next;
                while (rest != null)
                {
                    var restFirstValue = _meshData.Vertices[rest.Value.first.value];
                    var restLastValue  = _meshData.Vertices[rest.Value.last.value];

                    if (listLastValue == restFirstValue)
                    {
                        rest.Value.first.Remove();
                        var newList = LinkedLoop.ConcatList(childList, rest.Value);
                        edgeLoops.AddAfter(parrentListsNode, newList);
                        delete = true;
                        break;
                    }
                    if (listFirstValue == restLastValue)
                    {
                        childList.first.Remove();
                        var newList = LinkedLoop.ConcatList(rest.Value, childList);
                        edgeLoops.AddAfter(parrentListsNode, newList);
                        delete = true;
                        break;
                    }
                    if (listFirstValue == restFirstValue)
                    {
                        rest.Value.Reverse();
                        childList.first.Remove();
                        var newList = LinkedLoop.ConcatList(rest.Value, childList);
                        edgeLoops.AddAfter(parrentListsNode, newList);
                        delete = true;
                        break;
                    }
                    if (listLastValue == restLastValue)
                    {
                        rest.Value.last.Remove();
                        rest.Value.Reverse();
                        var newList = LinkedLoop.ConcatList(childList, rest.Value);
                        edgeLoops.AddAfter(parrentListsNode, newList);
                        delete = true;
                        break;
                    }

                    rest = rest.Next;
                }

                var tmp = parrentListsNode;
                parrentListsNode = parrentListsNode.Next;

                if (delete)
                {
                    edgeLoops.Remove(tmp);
                    edgeLoops.Remove(rest);
                }
            }
        }