Beispiel #1
0
        public BzPoly(BzPolyLoop outer, BzPolyLoop[] inners)
        {
            _loopPoints   = CombineLoops(outer, inners);
            _newTriangles = GetTriangles();

            if (_newTriangles.Count != 0)
            {
                Created = true;
            }
        }
Beispiel #2
0
        private static LoopIndexCollection GetIndexCollection(BzPolyLoop loop)
        {
            var loopData = new LinkedLoop <LoopIndex>();

            var loopNode = loop.edgeLoop.first;

            for (int i = 0; i < loop.edgeLoop.size; i++)
            {
                loopData.AddLast(new LoopIndex(loop, loopNode, loop.polyVertices2D[i]));
                loopNode = loopNode.next;
            }
            var indexCollection = new LoopIndexCollection(loop, loopData);

            return(indexCollection);
        }
Beispiel #3
0
        public bool IsInside(BzPolyLoop outer)
        {
            var innerCenter = Center;

            for (int i = 0; i < outer.triangles.Count; i += 3)
            {
                int     i1 = outer.triangles[i];
                int     i2 = outer.triangles[i + 1];
                int     i3 = outer.triangles[i + 2];
                Vector2 v1 = outer.polyVertices2D[i1];
                Vector2 v2 = outer.polyVertices2D[i2];
                Vector2 v3 = outer.polyVertices2D[i3];

                if (PointInTriangle(ref innerCenter, ref v1, ref v2, ref v3))
                {
                    return(true);
                }
            }

            return(false);
        }
Beispiel #4
0
        private LoopIndex[] CombineLoops(BzPolyLoop outer, BzPolyLoop[] inners)
        {
            var outerData  = GetIndexCollection(outer);
            var innersData = new LoopIndexCollection[inners.Length];

            for (int i = 0; i < innersData.Length; i++)
            {
                var loop = inners[i];
                innersData[i] = GetIndexCollection(loop);
            }

            var allLoops = new BzPolyLoop[inners.Length + 1];

            allLoops[0] = outer;
            Array.Copy(inners, 0, allLoops, 1, inners.Length);

            for (int i = 0; i < innersData.Length; i++)
            {
                LoopNode <LoopIndex> minOliNode;
                LoopNode <LoopIndex> minIliNode;
                var inner     = inners[i];
                var innerData = innersData[i];

                if (outer.Volume <= inner.Volume)
                {
                    continue;
                }

                if (!inner.IsInside(outer))
                {
                    continue;
                }

                if (!GetShortestConnection(outerData, innerData, allLoops, out minOliNode, out minIliNode))
                {
                    continue;
                }

                if (minOliNode != null)
                {
                    outerToInnerConnections.Add(new IndexVector(
                                                    minOliNode.value.indexPointer.value,
                                                    minIliNode.value.indexPointer.value)
                                                );
                    var list = minOliNode.list;
                    list.InsertAfter(minOliNode, minOliNode.value);
                    list.InsertAfter(minOliNode, minIliNode.value);
                    list.InsertAfter(minOliNode, minIliNode, minIliNode.previous);
                }
            }

            var result = new LoopIndex[outerData.items.size];
            var node   = outerData.items.first;

            for (int i = 0; i < outerData.items.size; i++)
            {
                result[i] = node.value;
                node      = node.next;
            }

            return(result);
        }
Beispiel #5
0
 public LoopIndex(BzPolyLoop loop, LoopNode <int> indexPointer, Vector2 vector2d)
 {
     this.loop         = loop;
     this.indexPointer = indexPointer;
     this.vector2d     = vector2d;
 }